Skip to content

Commit 54bf7f0

Browse files
committed
Fix enabling GPS for non-gps modules
Signed-off-by: Ric Sapasap <[email protected]>
1 parent b7e5f91 commit 54bf7f0

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
# FONA Versions
5757
FONA_800_L = const(0x01)
5858
FONA_800_H = const(0x6)
59+
FONA_800_C = const(0x7)
5960
FONA_808_V1 = const(0x2)
6061
FONA_808_V2 = const(0x3)
6162
FONA_3G_A = const(0x4)
@@ -147,14 +148,20 @@ def _init_fona(self) -> bool:
147148
self._fona_type = FONA_3G_A
148149
elif self._buf.find(b"SIMCOM_SIM5320E") != -1:
149150
self._fona_type = FONA_3G_E
150-
151-
if self._fona_type == FONA_800_L:
152-
# determine if SIM800H
151+
elif self._buf.find(b"SIM800") != -1:
153152
self._uart_write(b"AT+GMM\r\n")
154153
self._read_line(multiline=True)
155154

156155
if self._buf.find(b"SIM800H") != -1:
157156
self._fona_type = FONA_800_H
157+
elif self._buf.find(b"SIM800L") != -1:
158+
self._fona_type = FONA_800_L
159+
elif self._buf.find(b"SIM800C") != -1:
160+
self._fona_type = FONA_800_C
161+
162+
if self._debug and self._fona_type == 0:
163+
print(f"Unsupported module: {self._buf}")
164+
158165
return True
159166

160167
def factory_reset(self) -> bool:
@@ -366,7 +373,7 @@ def gps(self) -> int:
366373
# Instead just look for a fix and if found assume it's a 3D fix.
367374
self._get_reply(b"AT+CGNSINF")
368375

369-
if not b"+CGNSINF: " in self._buf:
376+
if b"+CGNSINF: " not in self._buf:
370377
return False
371378

372379
status = int(self._buf[10:11].decode("utf-8"))

adafruit_fona/adafruit_fona_network.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ def __init__(
4141
self._iface = fona
4242
self._apn = apn
4343
self._network_connected = False
44-
self._network_type = NET_CDMA
44+
self._network_type = NET_GSM
45+
self._has_gps = False
4546

46-
if not self._iface.version == 0x4 or self._iface.version == 0x5:
47-
self._network_type = NET_GSM
47+
# These are numbers defined in adafruit_fona FONA versions
48+
# For some reason, we can't import them from the adafruit_fona file
49+
50+
if self._iface.version in (0x4, 0x5):
51+
self._network_type = NET_CDMA
52+
53+
if self._iface.version in (0x2, 0x3, 0x4, 0x5):
4854
self._iface.gps = True
55+
self._has_gps = True
4956

5057
def __enter__(self) -> "CELLULAR":
5158
return self
@@ -72,7 +79,14 @@ def iccid(self) -> str:
7279
def is_attached(self) -> bool:
7380
"""Returns if the modem is attached to the network."""
7481
if self._network_type == NET_GSM:
75-
if self._iface.gps == 3 and self._iface.network_status == 1:
82+
if (
83+
self._has_gps
84+
and self._iface.gps == 3
85+
and self._iface.network_status == 1
86+
):
87+
return True
88+
89+
if not self._has_gps and self._iface.network_status == 1:
7690
return True
7791
else: # Attach CDMA network
7892
if self._iface.ue_system_info == 1 and self._iface.network_status == 1:

0 commit comments

Comments
 (0)