Renamed to main.py

This commit is contained in:
Jimmy 2021-05-29 14:59:36 +12:00
parent 71247d0154
commit 091d24a263
1 changed files with 0 additions and 37 deletions

View File

@ -1,37 +0,0 @@
from machine import Pin
from time import sleep
import machine
import dht
from umqtt.robust import MQTTClient
import json
import gc
with open("config.json", 'r') as f:
config = json.load(f)
print(config)
led = Pin(2, Pin.OUT)
d = dht.DHT11(Pin(12))
adc = machine.ADC(0)
c = MQTTClient("umqtt_client", config["mqtt"]["server"],ssl=True, user=config["mqtt"]["user"], password=config["mqtt"]["password"])
gc.enable()
while True:
led(0)
d.measure()
data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': config["id"]}
print(data)
led(1)
c.connect()
c.publish(b"sensors", json.dumps(data))
c.disconnect()
gc.collect()
# wdt.feed()
#sleep(1)