# Use this for FONA800 and FONA808 fona = FONA(uart, rst) # Use this for FONA3G # fona = FONA3G(uart, rst) # Initialize network while fona.network_status != 1: print("Connecting to network...") time.sleep(1) print("Connected to network!") print("RSSI: %ddB" % fona.rssi) # Text a number print("Sending SMS...") if not fona.send_sms(140404, "HELP"): raise RuntimeError("FONA did not successfully send SMS") print("SMS Sent!") # Ask the FONA how many SMS message it has stored num_sms = fona.num_sms() print("%d SMS's on SIM Card" % num_sms) # FONA3G SMS memory slots start at 0 if fona.version == FONA_3G_A or fona.version == FONA_3G_E: sms_idx = 0 else: # FONA800 and FONA808 SMS slots start at 1 sms_idx = 1 # Read num_sms messages from the FONA for slot in range(sms_idx, num_sms):
response = "Temperature: %0.1f C" % temp elif message in ['humid', 'humidity', 'h']: response = "Humidity: %0.1f %%" % humid elif message in ['pres', 'pressure', 'p']: response = "Pressure: %0.1f hPa" % pres 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']: response = "I'm a SMS Sensor - txt me with a command:\ TEMP - Read temperature\ HUMID - Read humidity\ PRES - Read pressure\ STATUS - Read all sensors.\ HELP - List commands" else: response = "Incorrect message format received. \ Text HELP to this number for a list of commands." # Send a response back to the sender print("Sending response...") 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!")
ri = digitalio.DigitalInOut(board.D5) # Use this for FONA800 and FONA808 fona = FONA(uart, rst, ri) # Use this for FONA3G # fona = FONA3G(uart, rst, ri) # Initialize Network while fona.network_status != 1: print("Connecting to network...") time.sleep(1) print("Connected to network!") print("RSSI: %ddB" % fona.rssi) # Enable FONA SMS notification fona.enable_sms_notification = True print("FONA Ready!\nWaiting for SMS...") while True: sender, message = fona.receive_sms() if message: print("Incoming SMS from {}: {}".format(sender, message)) # Reply back! print("Sending response...") if not fona.send_sms(int(sender), "Hey, I got your text!"): print("SMS Send Failed") print("SMS Sent!")