Skip to content

Commit 07c1aad

Browse files
author
brentru
committed
reduce errors during gprs bringup
1 parent b6c2912 commit 07c1aad

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ def _init_fona(self):
159159
print("Attempting to open comm with ATs")
160160
timeout = 7000
161161
while timeout > 0:
162-
if self._send_check_reply(CMD_AT, reply=REPLY_OK):
163-
break
162+
while self._uart.in_waiting:
163+
if self._send_check_reply(CMD_AT, reply=REPLY_OK):
164+
break
165+
166+
#while self._uart.in_waiting:
164167
if self._send_check_reply(CMD_AT, reply=REPLY_AT):
165168
break
166169
time.sleep(0.5)
@@ -246,15 +249,15 @@ def gprs(self, gprs_on=True):
246249
:param bool gprs_on: Turns on GPRS, enabled by default.
247250
248251
"""
249-
attempts = 3
252+
attempts = 5
250253
while not self._set_gprs(gprs_on):
251254
if attempts == 0:
252255
raise RuntimeError("Unable to establish PDP context.")
253256
if self._debug:
254257
print("* Not registered with network, retrying, ", attempts)
255258
self._set_gprs(False)
256-
time.sleep(5)
257259
attempts -= 1
260+
time.sleep(5)
258261
return True
259262

260263
# pylint: disable=too-many-return-statements
@@ -280,13 +283,15 @@ def _set_gprs(self, gprs_on=True):
280283
# enable multi connection mode (3,1)
281284
if not self._send_check_reply(b"AT+CIPMUX=1", reply=REPLY_OK):
282285
return False
286+
self._read_line()
283287

284288
# enable receive data manually (7,2)
285289
if not self._send_check_reply(b"AT+CIPRXGET=1", reply=REPLY_OK):
286290
return False
287291

288292
# disconnect all sockets
289-
self._send_check_reply(b"AT+CIPSHUT", reply=b"SHUT OK", timeout=20000)
293+
if not self._send_check_reply(b"AT+CIPSHUT", reply=b"SHUT OK", timeout=20000):
294+
return False
290295

291296
if not self._send_check_reply(b"AT+CGATT=1", reply=REPLY_OK, timeout=10000):
292297
return False
@@ -448,13 +453,13 @@ def gps(self, enable_gps=False):
448453
self._set_gps(enable_gps)
449454

450455
# Wait for a GPS fix
451-
if not self.gps == 3:
456+
while self.gps != 3:
452457
if self._debug:
453458
print("\t* GPS fix not found, retrying, ", failure_count)
454459
failure_count += 1
455-
time.sleep(5)
456460
if failure_count >= attempts:
457-
return -1
461+
return False
462+
time.sleep(1)
458463

459464
return True
460465

@@ -881,7 +886,9 @@ def _send_check_reply(
881886
return False
882887

883888
# validate response
884-
if not reply:
889+
if not self._buf == reply:
890+
print("buf: ", self._buf, end="")
891+
print(" reply: ", reply)
885892
return False
886893

887894
return True

0 commit comments

Comments
 (0)