led.off()
print('Connected')
status
= wlan.ifconfig()
print('ip = '
###MQTT
Topic Setup ###
def
connectMQTT():
client
= MQTTClient(secrets['client_id'],secrets['broker'],
secrets['port'], secrets['user_mosquitto'], secrets['passwd_mosquitto'])
client.connect()
return
client
def
publish(topic, value):
print(topic)
print(value)
pub_msg
=
"%5.2f"
print(topic,"
client.publish(topic, pub_msg)
print("publish
try:
client
= connectMQTT()
except
OSError
as
machine.reset()
def
getSensorsAndPublish():
# start DS18B20 conversion
ds.convert_temp()
# record time in nanosecond
startConv_ms
= time.ticks_ms()
# end need to be 750ms after
endConv_ms
=
startConv_ms
# DS18b20 needs 750ms after conversion
while
time.ticks_ms() < endConv_ms:
pass
publish(secrets['pubtopicTemp'], ds.read_temp(roms[0]))
#ok main process
try:
while
True:
led.value(True)
getSensorsAndPublish()
led.value(False)
time.sleep(15)
except
OSError
as
pass
machine.reset()
+ status[0])
%
value
",pub_msg)
Done")
e:
+
750
e: