Ejemplo n.º 1
0
notification_buf = bytearray(64)

print("FONA Ready!")
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)
        print("FROM: ", sender)
        print("MSG: ", message)

        # Read BME280 sensor values
        temp = bme280.temperature
        humid = bme280.humidity
        pres = bme280.pressure

        # Sanitize message
        message = message.lower()
        message = message.strip()

        if message in ['temp', 'temperature', 't']:
            response = "Temperature: %0.1f C" % temp
        elif message in ['humid', 'humidity', 'h']:
# 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):
    print(fona.read_sms(slot))