I`m begginer of RaspberyPi, Lua scripts and Domoticz.
I need help and advise how to transfer from DHT22 two values - temp and humidity from esp8266-03.
I found similar script and try to customize for myself but I do not have any idea how to put in json two values t and h and send it to Domoticz.
I tried .. string.format("%2d;%2d;0", t, h) .. but it`s wrong .
Perhaps all script has mistakes.
Please if somebody can help me I will appreciate it.
Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("Vic","")
wifi.sta.connect()
wifi.sta.setip({ip="192.168.1.195",netmask="255.255.255.0",gateway="192.168.1.253"})
print("ESP8266 mode is: " .. wifi.getmode())
print("The module MAC address is: " .. wifi.ap.getmac())
print("Config done, IP is "..wifi.sta.setip())
-- set up some DHT22 things from https://github.com/javieryanez/nodemcu-modules/tree/master/dht22
PIN = 3 -- data pin, GPIO0
dht22 = require("dht22_min")
chipserial = node.chipid()
dht22.read(PIN)
t = dht22.getTemperature()
h = dht22.getHumidity()
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(8080,"192.168.1.201")
conn:send("GET /json.htm?type=command¶m=udevice&idx=46&nvalue=0&svalue=" .. string.format("%2d;%2d;0", t, h) .."HTTP/1.1\r\nHost:www.local.lan\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
Tom