Skip to content

#24 Fix enabling GPS for non-gps modules #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions adafruit_fona/adafruit_fona.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
# FONA Versions
FONA_800_L = const(0x01)
FONA_800_H = const(0x6)
FONA_800_C = const(0x7)
FONA_808_V1 = const(0x2)
FONA_808_V2 = const(0x3)
FONA_3G_A = const(0x4)
Expand All @@ -71,7 +72,7 @@ class FONA:
"""CircuitPython FONA module interface.

:param ~busio.UART uart: FONA UART connection.
:param ~digitalio.DigitalInOut rdt: FONA RST pin.
:param ~digitalio.DigitalInOut rst: FONA RST pin.
:param ~digitalio.DigitalInOut ri: Optional FONA Ring Interrupt (RI) pin.
:param bool debug: Enable debugging output.
"""
Expand Down Expand Up @@ -147,14 +148,20 @@ def _init_fona(self) -> bool:
self._fona_type = FONA_3G_A
elif self._buf.find(b"SIMCOM_SIM5320E") != -1:
self._fona_type = FONA_3G_E

if self._fona_type == FONA_800_L:
# determine if SIM800H
elif self._buf.find(b"SIM800") != -1:
self._uart_write(b"AT+GMM\r\n")
self._read_line(multiline=True)

if self._buf.find(b"SIM800H") != -1:
self._fona_type = FONA_800_H
elif self._buf.find(b"SIM800L") != -1:
self._fona_type = FONA_800_L
elif self._buf.find(b"SIM800C") != -1:
self._fona_type = FONA_800_C

if self._debug and self._fona_type == 0:
print(f"Unsupported module: {self._buf}")

return True

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

if not b"+CGNSINF: " in self._buf:
if b"+CGNSINF: " not in self._buf:
return False

status = int(self._buf[10:11].decode("utf-8"))
Expand Down
22 changes: 18 additions & 4 deletions adafruit_fona/adafruit_fona_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ def __init__(
self._iface = fona
self._apn = apn
self._network_connected = False
self._network_type = NET_CDMA
self._network_type = NET_GSM
self._has_gps = False

if not self._iface.version == 0x4 or self._iface.version == 0x5:
self._network_type = NET_GSM
# These are numbers defined in adafruit_fona FONA versions
# For some reason, we can't import them from the adafruit_fona file

if self._iface.version in (0x4, 0x5):
self._network_type = NET_CDMA

if self._iface.version in (0x2, 0x3, 0x4, 0x5):
self._iface.gps = True
self._has_gps = True

def __enter__(self) -> "CELLULAR":
return self
Expand All @@ -72,7 +79,14 @@ def iccid(self) -> str:
def is_attached(self) -> bool:
"""Returns if the modem is attached to the network."""
if self._network_type == NET_GSM:
if self._iface.gps == 3 and self._iface.network_status == 1:
if (
self._has_gps
and self._iface.gps == 3
and self._iface.network_status == 1
):
return True

if not self._has_gps and self._iface.network_status == 1:
return True
else: # Attach CDMA network
if self._iface.ue_system_info == 1 and self._iface.network_status == 1:
Expand Down