update for cdma/gsm network class

This commit is contained in:
brentru 2020-06-01 16:46:10 -04:00
parent 6ce637a453
commit 0bfb378a0e

View file

@ -1,8 +1,10 @@
# pylint: disable=unused-import
import time
import board
import busio
import digitalio
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.fona_3g import FONA3G
import adafruit_bme280
print("FONA SMS Sensor")
@ -11,9 +13,12 @@ print("FONA SMS Sensor")
uart = busio.UART(board.TX, board.RX)
rst = digitalio.DigitalInOut(board.D4)
# Initialize FONA module (this may take a few seconds)
# Use this for FONA800 and FONA808
fona = FONA(uart, rst)
# Use this for FONA3G
# fona = FONA3G(uart, rst, ri)
# Initialize BME280 Sensor
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
@ -28,23 +33,11 @@ print("RSSI: %ddB" % fona.rssi)
# Enable FONA SMS notification
fona.enable_sms_notification = True
# store incoming notification info
notification_buf = bytearray(64)
print("FONA Ready!")
print("Listening for messages...")
while True:
if fona.in_waiting: # data is available from FONA
notification_buf = fona.read_line()[1]
# Split out the sms notification slot num.
notification_buf = notification_buf.decode()
if "+CMTI:" not in notification_buf:
continue
sms_slot = notification_buf.split(",")[1]
print("NEW SMS!\n\t Slot: ", sms_slot)
# Get SMS message and address
sender, message = fona.read_sms(sms_slot)
sender, message = fona.receive_sms()
if message:
print("New Message!")
print("FROM: ", sender)
print("MSG: ", message)
@ -57,16 +50,18 @@ while True:
message = message.lower()
message = message.strip()
if message in ['temp', 'temperature', 't']:
if message in ["temp", "temperature", "t"]:
response = "Temperature: %0.1f C" % temp
elif message in ['humid', 'humidity', 'h']:
elif message in ["humid", "humidity", "h"]:
response = "Humidity: %0.1f %%" % humid
elif message in ['pres', 'pressure', 'p']:
elif message in ["pres", "pressure", "p"]:
response = "Pressure: %0.1f hPa" % pres
elif message in ['status', 's']:
elif message in ["status", "s"]:
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}% \
Pressure: {2:.1f}hPa".format(temp, humid, pres)
elif message in ['help']:
Pressure: {2:.1f}hPa".format(
temp, humid, pres
)
elif message in ["help"]:
response = "I'm a SMS Sensor - txt me with a command:\
TEMP - Read temperature\
HUMID - Read humidity\
@ -82,8 +77,3 @@ while True:
if not fona.send_sms(int(sender), response):
print("SMS Send Failed")
print("SMS Sent!")
# Delete the original message
if not fona.delete_sms(sms_slot):
print("Could not delete SMS in slot", sms_slot)
print("OK!")