Search
SQLite Viewer: Link
from machine import Pin import network, dht, time, json, urequests SSID = "" # enter network credentials PW = "" URL = "" # set Flask app URL sensor = dht.DHT22(Pin(15)) # edit pin number if needed wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(SSID,PW) while wlan.isconnected() == False: print("Connecting...") time.sleep(1) print(wlan.ifconfig()) while True: try: sensor.measure() temp = sensor.temperature() humi = sensor.humidity() data = json.dumps({"temperature": temp, "humidity": humi}) response = urequests.post(URL,data=data, headers={"Content-Type": "application/json"}) print("Posted data with response code:",response.status_code) print(response.text) except Exception as e: print("Error:", e) time.sleep(2)