30 lines
573 B
Python
30 lines
573 B
Python
from machine import Pin
|
|
from time import sleep
|
|
import machine
|
|
import dht
|
|
from umqtt.simple import MQTTClient
|
|
import json
|
|
import gc
|
|
|
|
led = Pin(2, Pin.OUT)
|
|
d = dht.DHT11(Pin(16))
|
|
adc = machine.ADC(0)
|
|
server="10.1.1.162"
|
|
c = MQTTClient("umqtt_client", server)
|
|
gc.enable()
|
|
print(machine.freq())
|
|
|
|
while True:
|
|
led(0)
|
|
d.measure()
|
|
data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': 1}
|
|
print(data)
|
|
led(1)
|
|
c.connect()
|
|
c.publish(b"sensors", json.dumps(data))
|
|
c.disconnect()
|
|
gc.collect()
|
|
# wdt.feed()
|
|
sleep(2)
|
|
|