diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 2866f025..6832912c 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -632,11 +632,13 @@ def _handlePacketFromRadio(self, meshPacket, hack=False): # asObj = DotMap(asDict) topic = "meshtastic.receive" # Generic unknown packet type - decoded = asDict["decoded"] - # The default MessageToDict converts byte arrays into base64 strings. - # We don't want that - it messes up data payload. So slam in the correct - # byte array. - decoded["payload"] = meshPacket.decoded.payload + decoded = None + if 'decoded' in asDict: + decoded = asDict["decoded"] + # The default MessageToDict converts byte arrays into base64 strings. + # We don't want that - it messes up data payload. So slam in the correct + # byte array. + decoded["payload"] = meshPacket.decoded.payload # UNKNOWN_APP is the default protobuf portnum value, and therefore if not # set it will not be populated at all to make API usage easier, set diff --git a/meshtastic/tests/test_smokevirt.py b/meshtastic/tests/test_smokevirt.py index 1a10c2ed..2c6967f5 100644 --- a/meshtastic/tests/test_smokevirt.py +++ b/meshtastic/tests/test_smokevirt.py @@ -21,7 +21,7 @@ # seconds to pause after running a meshtastic command PAUSE_AFTER_COMMAND = 0.1 -PAUSE_AFTER_REBOOT = 0.1 +PAUSE_AFTER_REBOOT = 0.2 #TODO: need to fix the virtual device to have a reboot. When you issue the command @@ -358,6 +358,11 @@ def test_smokevirt_ch_set_downlink_and_uplink(): @pytest.mark.smokevirt def test_smokevirt_ch_add_and_ch_del(): """Test --ch-add""" + return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-index 1 --ch-del') + assert re.search(r'Deleting channel 1', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_REBOOT) return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-add testing') assert re.search(r'Writing modified channels to device', out, re.MULTILINE) assert return_value == 0 @@ -375,7 +380,7 @@ def test_smokevirt_ch_add_and_ch_del(): assert return_value == 0 # pause for the radio time.sleep(PAUSE_AFTER_REBOOT) - # make sure the secondar channel is not there + # make sure the secondary channel is not there return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --info') assert re.match(r'Connected to radio', out) assert not re.search(r'SECONDARY', out, re.MULTILINE) @@ -386,6 +391,11 @@ def test_smokevirt_ch_add_and_ch_del(): @pytest.mark.smokevirt def test_smokevirt_ch_enable_and_disable(): """Test --ch-enable and --ch-disable""" + return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-index 1 --ch-del') + assert re.search(r'Deleting channel 1', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_REBOOT) return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-add testing') assert re.search(r'Writing modified channels to device', out, re.MULTILINE) assert return_value == 0 @@ -434,6 +444,11 @@ def test_smokevirt_ch_enable_and_disable(): @pytest.mark.smokevirt def test_smokevirt_ch_del_a_disabled_non_primary_channel(): """Test --ch-del will work on a disabled non-primary channel.""" + return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-index 1 --ch-del') + assert re.search(r'Deleting channel 1', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(PAUSE_AFTER_REBOOT) return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --ch-add testing') assert re.search(r'Writing modified channels to device', out, re.MULTILINE) assert return_value == 0