Skip to content

Commit 0bfb378

Browse files
author
brentru
committed
update for cdma/gsm network class
1 parent 6ce637a commit 0bfb378

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

FONA_SMS_Sensor/code.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# pylint: disable=unused-import
12
import time
23
import board
34
import busio
45
import digitalio
56
from adafruit_fona.adafruit_fona import FONA
7+
from adafruit_fona.fona_3g import FONA3G
68
import adafruit_bme280
79

810
print("FONA SMS Sensor")
@@ -11,9 +13,12 @@
1113
uart = busio.UART(board.TX, board.RX)
1214
rst = digitalio.DigitalInOut(board.D4)
1315

14-
# Initialize FONA module (this may take a few seconds)
16+
# Use this for FONA800 and FONA808
1517
fona = FONA(uart, rst)
1618

19+
# Use this for FONA3G
20+
# fona = FONA3G(uart, rst, ri)
21+
1722
# Initialize BME280 Sensor
1823
i2c = busio.I2C(board.SCL, board.SDA)
1924
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
@@ -28,23 +33,11 @@
2833
# Enable FONA SMS notification
2934
fona.enable_sms_notification = True
3035

31-
# store incoming notification info
32-
notification_buf = bytearray(64)
33-
34-
print("FONA Ready!")
36+
print("Listening for messages...")
3537
while True:
36-
if fona.in_waiting: # data is available from FONA
37-
notification_buf = fona.read_line()[1]
38-
# Split out the sms notification slot num.
39-
notification_buf = notification_buf.decode()
40-
if "+CMTI:" not in notification_buf:
41-
continue
42-
sms_slot = notification_buf.split(",")[1]
43-
44-
print("NEW SMS!\n\t Slot: ", sms_slot)
45-
46-
# Get SMS message and address
47-
sender, message = fona.read_sms(sms_slot)
38+
sender, message = fona.receive_sms()
39+
if message:
40+
print("New Message!")
4841
print("FROM: ", sender)
4942
print("MSG: ", message)
5043

@@ -57,16 +50,18 @@
5750
message = message.lower()
5851
message = message.strip()
5952

60-
if message in ['temp', 'temperature', 't']:
53+
if message in ["temp", "temperature", "t"]:
6154
response = "Temperature: %0.1f C" % temp
62-
elif message in ['humid', 'humidity', 'h']:
55+
elif message in ["humid", "humidity", "h"]:
6356
response = "Humidity: %0.1f %%" % humid
64-
elif message in ['pres', 'pressure', 'p']:
57+
elif message in ["pres", "pressure", "p"]:
6558
response = "Pressure: %0.1f hPa" % pres
66-
elif message in ['status', 's']:
59+
elif message in ["status", "s"]:
6760
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}% \
68-
Pressure: {2:.1f}hPa".format(temp, humid, pres)
69-
elif message in ['help']:
61+
Pressure: {2:.1f}hPa".format(
62+
temp, humid, pres
63+
)
64+
elif message in ["help"]:
7065
response = "I'm a SMS Sensor - txt me with a command:\
7166
TEMP - Read temperature\
7267
HUMID - Read humidity\
@@ -82,8 +77,3 @@
8277
if not fona.send_sms(int(sender), response):
8378
print("SMS Send Failed")
8479
print("SMS Sent!")
85-
86-
# Delete the original message
87-
if not fona.delete_sms(sms_slot):
88-
print("Could not delete SMS in slot", sms_slot)
89-
print("OK!")

0 commit comments

Comments
 (0)