Skip to content

Commit 7db4eb4

Browse files
committed
Works when LTE module is reset and connects to LTE on it's own
1 parent 02340c2 commit 7db4eb4

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

Examples/ex05_SIM767X.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
config_dict = dashio.decode_cfg64(cfg64)
2828
device = dashio.Device("aDeviceType", "aDeviceID", "Fred", cfg_dict=config_dict)
29-
lte_con = lte_767x_connection.Lte767xConnection("iot.gdsp.nz", "username", "password", 'dash.dashio.io', 8883, "/dev/tty.usbserial-143110", 115200, None)
29+
# lte_con = lte_767x_connection.Lte767xConnection("iot.gdsp.nz", "username", "password", 'dash.dashio.io', 8883, "/dev/tty.usbserial-143110", 115200, None)
30+
lte_con = lte_767x_connection.Lte767xConnection("iot.gdsp.nz", "craig", "ThingyThing", 'dash.dashio.io', 8883, "/dev/cu.usbmodem0000000000013", 115200, None)
3031
lte_con.add_device(device)
3132

3233
tcp_con = dashio.TCPConnection()

dashio/lte_767x_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import logging
2727
import threading
2828
import json
29-
import shortuuid
30-
import zmq
29+
import shortuuid # type: ignore
30+
import zmq # type: ignore
3131
from .sim767x import Sim767x, ErrorState
3232
from .constants import CONNECTION_PUB_URL
3333
from .device import Device

dashio/sim767x.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,13 @@ def _process_at_commands(self):
394394
self._disconnect_timer_s = 0
395395
self._start_pdp_context()
396396
else: # Request response
397+
self._run_at_callbacks = False
397398
status = int(result_arr[1])
398399
if status == 1 or status == 5 or status == 6:
399400
if self._lte_state != LteState.LTE_CONNECTED:
400401
self._lte_state = LteState.LTE_CONNECTED
401402
self._disconnect_timer_s = 0
402-
self._start_pdp_context()
403+
self._check_pdp_context()
403404
else: # Only do this for request response (i.e. when monitoring)
404405
self._lte_state = LteState.LTE_DISCONNECTED
405406
self._mqtt_state = MqttState.MQTT_DISCONNECTED
@@ -419,7 +420,26 @@ def _process_at_commands(self):
419420
result_arr = result_str.split(',')
420421
if len(result_arr) >= 3:
421422
logger.debug("Carrier: %s", result_arr[2])
423+
elif data.startswith("+CGACT:"):
424+
result_arr = result_str.split(',')
425+
if len(result_arr) >= 2:
426+
if result_arr[0] == "1": # pdp context 0
427+
if result_arr[0] == "1":
428+
self._check_MQTT_client()
429+
else:
430+
self._start_pdp_context()
422431
# MQTT
432+
elif data.startswith("+CMQTTACCQ:"):
433+
result_arr = result_str.split(',')
434+
if len(result_arr) >= 3:
435+
if result_arr[0] == "0": # clientIndex 0
436+
if result_arr[1] and (self._imei in result_arr[1]):
437+
if (self._mqtt_state == MqttState.MQTT_DISCONNECTED):
438+
logger.debug("MQTT already connected") # ???
439+
self._mqtt_state = MqttState.MQTT_CONNECTED # ??? This doesn't work
440+
# ??? self.reset_module() this causes a crash because the serial disconnects
441+
else:
442+
self._mqtt_start()
423443
elif data.startswith("+CMQTTSTART:"):
424444
error = int(result_str)
425445
if error == 0:
@@ -619,11 +639,20 @@ def _print_ok(self):
619639
def _check_connection(self):
620640
self._protected_at_cmd("CREG?", self._print_ok, None)
621641

642+
def _check_pdp_context(self):
643+
self._protected_at_cmd("CGACT?", self._print_ok, None)
644+
645+
def _check_MQTT_client(self):
646+
self._protected_at_cmd("CMQTTACCQ?", self._print_ok, None)
647+
622648
def _get_imei(self):
623649
self._protected_at_cmd("SIMEI?", self._set_unsolicited_network_reg_messages, None)
624650

625651
def _set_unsolicited_network_reg_messages(self):
626-
self._protected_at_cmd("CREG=1", self._set_carrier, None)
652+
self._protected_at_cmd("CREG=1", self._get_network_reg_status, None)
653+
654+
def _get_network_reg_status(self):
655+
self._protected_at_cmd("CREG?", self._set_carrier, None)
627656

628657
def _set_carrier(self):
629658
if self._network:
@@ -661,7 +690,7 @@ def _mqtt_start(self):
661690
self._protected_at_cmd("CMQTTSTART", self._print_ok, None, 60)
662691

663692
def _mqtt_acquire_client(self):
664-
temp_str = f'CMQTTACCQ=0,"{self._imei}",1' # clientIndex = 0, cliendID, serverType 1 = SSL/TLS, 0 = TCP
693+
temp_str = f'CMQTTACCQ=0,{self._imei},1' # clientIndex = 0, cliendID, serverType 1 = SSL/TLS, 0 = TCP
665694
self._protected_at_cmd(temp_str, self._mqtt_config_ssl, None)
666695

667696
def _mqtt_config_ssl(self):

0 commit comments

Comments
 (0)