Skip to content

Commit 57b808e

Browse files
author
brentru
committed
update to poll within user code instead of gsm module
1 parent 52c01a5 commit 57b808e

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

adafruit_fona/adafruit_fona_gsm.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,8 @@ def __init__(self, fona, apn, debug=True):
4646
self._apn = apn
4747
self._gsm_connected = False
4848

49-
# Attempt to enable GPS module and obtain GPS fix
50-
attempts = 10
49+
# Enable GPS module
5150
self._iface.gps = True
52-
while not self._iface.gps == 3:
53-
if attempts < 0:
54-
raise RuntimeError("Unable to establish GPS fix.")
55-
attempts -= 1
56-
time.sleep(0.5)
57-
58-
# Check if FONA is registered to GSM network
59-
attempts = 30
60-
while self._iface.network_status != 1:
61-
if attempts == 0:
62-
raise TimeoutError("Not registered with GSM network.")
63-
if self._debug:
64-
print("* Not registered with network, retrying, ", attempts)
65-
attempts -= 1
66-
time.sleep(1)
6751

6852
def __enter__(self):
6953
return self
@@ -81,6 +65,16 @@ def iccid(self):
8165
"""Returns the SIM card's ICCID, as a string."""
8266
return self._iface.iccid
8367

68+
@property
69+
def is_attached(self):
70+
"""Returns if the modem is attached to the network
71+
and the GPS has a fix."""
72+
if self._iface.gps == 3:
73+
if self._iface.network_status == 1:
74+
return True
75+
return False
76+
77+
8478
@property
8579
def is_connected(self):
8680
"""Returns if attached to GSM

examples/fona_cheerlights.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import busio
44
import digitalio
55
from adafruit_fona.adafruit_fona import FONA
6+
from adafruit_fona.adafruit_fona_gsm import GSM
67
import adafruit_fona.adafruit_fona_socket as cellular_socket
78
import adafruit_requests as requests
89

910
import neopixel
1011
import adafruit_fancyled.adafruit_fancyled as fancy
1112

13+
1214
# Get GPRS details and more from a secrets.py file
1315
try:
1416
from secrets import secrets
@@ -23,18 +25,18 @@
2325
rst = digitalio.DigitalInOut(board.D4)
2426

2527
# Initialize FONA module (this may take a few seconds)
26-
print("Initializing FONA")
2728
fona = FONA(uart, rst)
2829

29-
# Enable GPS
30-
fona.gps = True
30+
# Enable FONA debugging
31+
fona._debug = True
3132

32-
# Bring up cellular connection
33-
fona.configure_gprs((secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
33+
# initialize gsm
34+
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
3435

35-
# Bring up GPRS
36-
fona.gprs = True
37-
print("FONA initialized")
36+
while not gsm.is_connected:
37+
print("Connecting to network...")
38+
gsm.connect()
39+
time.sleep(5)
3840

3941
# Initialize a requests object with a socket and cellular interface
4042
requests.set_socket(cellular_socket, fona)

examples/fona_simpletest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
# initialize gsm
3535
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
3636

37+
while not gsm.is_attached:
38+
print("Attaching to network...")
39+
time.sleep(0.5)
40+
3741
while not gsm.is_connected:
3842
print("Connecting to network...")
3943
gsm.connect()

0 commit comments

Comments
 (0)