Renamed to main.py
This commit is contained in:
parent
71247d0154
commit
091d24a263
37
uP/mqtt.py
37
uP/mqtt.py
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue