Skip to content

Commit 6d63837

Browse files
authored
Merge pull request #6 from brentru/update-sms
Update for FONA3G, SMS
2 parents c3ab121 + c5a824a commit 6d63837

9 files changed

+630
-269
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 179 additions & 178 deletions
Large diffs are not rendered by default.

adafruit_fona/adafruit_fona_gsm.py renamed to adafruit_fona/adafruit_fona_network.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,38 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_fona_gsm`
23+
`adafruit_fona_network`
2424
=================================================================================
2525
26-
Interface for 2G GSM cellular modems such as the Adafruit FONA808.
26+
Interface for connecting to and interacting with GSM and CDMA cellular networks.
2727
2828
* Author(s): Brent Rubell
2929
3030
"""
3131

32+
# Network types
33+
NET_GSM = 0x01
34+
NET_CDMA = 0x02
3235

33-
class GSM:
34-
"""Interface for interacting with FONA 2G GSM modems.
35-
"""
36+
37+
class CELLULAR:
38+
"""Interface for connecting to and interacting with GSM and CDMA cellular networks."""
3639

3740
def __init__(self, fona, apn):
38-
"""Initializes interface with 2G GSM modem.
41+
"""Initializes interface with cellular network.
3942
:param adafruit_fona fona: The Adafruit FONA module we are using.
4043
:param tuple apn: Tuple containing APN name, (optional) APN username,
4144
and APN password.
4245
4346
"""
4447
self._iface = fona
4548
self._apn = apn
46-
self._gsm_connected = False
49+
self._network_connected = False
50+
self._network_type = NET_CDMA
4751

48-
# Enable GPS module
49-
self._iface.gps = True
52+
if not self._iface.version == 0x4 or self._iface.version == 0x5:
53+
self._network_type = NET_GSM
54+
self._iface.gps = True
5055

5156
def __enter__(self):
5257
return self
@@ -56,7 +61,7 @@ def __exit__(self, exception_type, exception_value, traceback):
5661

5762
@property
5863
def imei(self):
59-
"""Returns the GSM modem's IEMI number, as a string."""
64+
"""Returns the modem's IEMI number, as a string."""
6065
return self._iface.iemi
6166

6267
@property
@@ -66,31 +71,31 @@ def iccid(self):
6671

6772
@property
6873
def is_attached(self):
69-
"""Returns if the modem is attached to the network
70-
and the GPS has a fix."""
71-
if self._iface.gps == 3 and self._iface.network_status == 1:
72-
return True
74+
"""Returns if the modem is attached to the network."""
75+
if self._network_type == NET_GSM:
76+
if self._iface.gps == 3 and self._iface.network_status == 1:
77+
return True
78+
else: # Attach CDMA network
79+
if self._iface.ue_system_info == 1 and self._iface.network_status == 1:
80+
return True
7381
return False
7482

7583
@property
7684
def is_connected(self):
77-
"""Returns if attached to GSM
78-
and an IP Addresss was obtained.
79-
80-
"""
81-
if not self._gsm_connected:
85+
"""Returns if attached to network and an IP Addresss was obtained."""
86+
if not self._network_connected:
8287
return False
8388
return True
8489

8590
def connect(self):
86-
"""Connect to GSM network."""
91+
"""Connect to cellular network."""
8792
if self._iface.set_gprs(self._apn, True):
88-
self._gsm_connected = True
93+
self._network_connected = True
8994
else:
9095
# reset context for next connection attempt
9196
self._iface.set_gprs(self._apn, False)
9297

9398
def disconnect(self):
94-
"""Disconnect from GSM network."""
99+
"""Disconnect from cellular network."""
95100
self._iface.set_gprs(self._apn, False)
96-
self._gsm_connected = False
101+
self._network_connected = False

adafruit_fona/adafruit_fona_socket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def __init__(
103103
raise RuntimeError("Only AF_INET family supported by cellular sockets.")
104104
self._sock_type = type
105105
self._buffer = b""
106-
self._timeout = 0
106+
if hasattr(_the_interface, "tx_timeout"):
107+
self._timeout = _the_interface.tx_timeout
108+
else:
109+
self._timeout = 3000 # FONA800
107110

108111
self._socknum = _the_interface.get_socket()
109112
SOCKETS.append(self._socknum)
@@ -157,7 +160,7 @@ def send(self, data):
157160
:param bytes data: Desired data to send to the socket.
158161
159162
"""
160-
_the_interface.socket_write(self._socknum, data)
163+
_the_interface.socket_write(self._socknum, data, self._timeout)
161164
gc.collect()
162165

163166
def recv(self, bufsize=0):

0 commit comments

Comments
 (0)