Luigi Francesco Cerfeda
Published © CC BY

IoT Thermometer Using Python

How to develop a simple but powerful IoT thermometer using a Zerynth-powered single-board MCU and the Zerynth App.

IntermediateFull instructions provided2 hours17,566
IoT Thermometer Using Python

Things used in this project

Story

Read more

Schematics

Flip&Click + Wifi Plus Click + Temp&Hum Click

Code

IoT Thermometer

Python
################################################################################
# Zerynth App Oscilloscope
################################################################################
 
from wireless import wifi
from microchip.mcw1001a import mcw1001a as wifi_driver
import streams
import adc
 
streams.serial()
 
# Import the Zerynth APP library
from zerynthapp import zerynthapp
 
# Import the HTS221 library
from stm.hts221 import hts221
 
temp_hum = hts221.HTS221(I2C0, D21) # slot A
 
sleep(1000)
print("STARTING...")
 
try:
    # Device UID and TOKEN can be created in the ADM panel
    zapp = zerynthapp.ZerynthApp("DEVICE UID", "DEVICE TOKEN",ip = "178.22.65.123", log=True)
 
    # connect to the wifi network (Set your SSID and password below)
    wifi_driver.init(SERIAL2,D24) # slot B
    for i in range(0,5):
        try:
            wifi.link("SSID",wifi.WIFI_WPA2,"PASSWORD")
            break
        except Exception as e:
            print("Can't link",e)
    else:
        print("Impossible to link!")
        while True:
            sleep(1000)
 
    # Start the Zerynth app instance!
    # Remember to create a template with the files under the "template" folder you just cloned
    # upload it to the ADM and associate it with the connected device
    zapp.run()
    
    # Read the sensor and send values to the ADM
    while True:
        sleep(1000)
        tmp, hum = temp_hum.get_temp_humidity() # Read tmp and hum
        print("Temp is:", tmp, "Humidity is:", hum)
        try:
            zapp.event({"data":tmp})
        except Exception as e:
            print(e)
        if tmp>30:
            # send mobile notification
            # (there is a limit of one notification per minute per device on the ADM sandbox)
            try:
                zapp.notify("ALARM!","High Temperature!")
            except Exception as e:
                print(e)
        
except Exception as e:
    print(e)

Credits

Luigi Francesco Cerfeda

Luigi Francesco Cerfeda

6 projects • 95 followers
Yet another Tony Stark wannabe

Comments