mqtt.lua 728 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
BROKER = "192.168.80.2"
BRPORT = 1883
BRUSER = "user"
BRPWD  = "pwd"
CLIENTID = "ESP8266-" ..  node.chipid()

dofile("baro.lc")

print "Connecting to MQTT broker. Please wait..."
m = mqtt.Client( CLIENTID, 120, BRUSER, BRPWD)
m:connect( BROKER , BRPORT, 0, function(conn)
     print("Connected to MQTT:" .. BROKER .. ":" .. BRPORT .." as " .. CLIENTID )
     m:publish("sensors/".. CLIENTID .. "/temperature",read_temp(i2c_addr),0,0, function(conn)
          print ("temp published") 
          tmr.delay(10000)
          m:publish("sensors/".. CLIENTID .. "/pressure",read_pressure(i2c_addr),0,0, function(conn)
               print ("pressure published") 
               node.dsleep(60*1000000)
          end)
     end)
end)