Page 1 of 1

How to put in json two values t and h and send it to Domoticz

Posted: Wednesday 24 February 2016 18:24
by tomallm
Hi.
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&param=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

Re: How to put in json two values t and h and send it to Domoticz

Posted: Wednesday 24 February 2016 19:45
by simonrg
Tom,

Great this is my job for sometime soon, I have got a Wemos Mini D1 and 4 DHT22 sensors, so just need to connect the bits together, do I need some capacitors and resistors or just a breadboard?

If you have a look at the wiki - http://www.domoticz.com/wiki/Domoticz_A ... 2Fhumidity - then you should be using this format -

Code: Select all

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
- which it looks like you are, but I am not sure the communication is quite right, however I haven't really worked out what it is doing.

Cribbing from: https://openenergymonitor.org/emon/node/10235

Code: Select all

conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) 
end)

conn:on("connection", function(conn, payload) 
   conn:send("GET /json.htm?type=command&param=udevice&idx=46&nvalue=0&svalue=" .. string.format("%2d;%2d;0", t, h)
   .." HTTP/1.1\r\n" 
   .."Host: 127.0.0.1:8080\r\n"
   .."Connection: close\r\n"
   .."Accept: */*\r\n" 
   .."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" 
   .."\r\n")
   print("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=46&nvalue=0&svalue=" .. string.format("%2d;%2d;0", t, h")
end) 

conn:on("disconnection", function(conn, payload) 
end)
Simon

P.S. Could you edit your original post to use the

Code: Select all

[code]
[/code] block, as it make it easier to read the code.

Re: How to put in json two values t and h and send it to Domoticz

Posted: Wednesday 24 February 2016 20:08
by BobS
Hi,
You might consider using ESPeasy (www.esp8266.nu) it supports Domoticz and DHT11.
All programming has already been done for you.

Re: How to put in json two values t and h and send it to Domoticz

Posted: Wednesday 24 February 2016 20:26
by simonrg
BobS wrote:Hi,
You might consider using ESPeasy (http://www.esp8266.nu) it supports Domoticz and DHT11.
All programming has already been done for you.
So if I understand it right, then I just need to load the ESPeasy firmware onto my ESP8266, which will then present a web server, which is used to configure the ESP8266 to act as a sensor and then it will send data to Domoticz. :D

Re: How to put in json two values t and h and send it to Domoticz

Posted: Wednesday 24 February 2016 22:02
by tomallm
Hi.
Thanks for help.
I have tried also Symon`s advice and BobS`s also.
Both work.
I will stay with with ESPeasy. I`m suprised what this firmware can do with ESP and other connected devices.
It took me a few minutes to programmed my ESP8266-03 with AM2302 and see results in Domoticz. Even deep sleep works well.
Tom

Re: How to put in json two values t and h and send it to Domoticz

Posted: Thursday 25 February 2016 1:54
by simonrg
tomallm wrote:I will stay with with ESPeasy. I`m suprised what this firmware can do with ESP and other connected devices.
It took me a few minutes to programmed my ESP8266-03 with AM2302 and see results in Domoticz.
5 minutes with http://www.esp8266.nu/index.php/HumiditySensor
ESPeasy firmware is really easy - just burn the firmware - connect up my DHT22 temp / humdity sensor, create dummy temp /hum sensor in Domoticz, configure ESPeasy web interface on my Wemos D1 Mini and magically data starts being sent to Domoticz - a £5 temperature / humidity sensor.

Things aren't supposed to be this easy, you are supposed to have to figure out obscure TCP connection strings. No doubt at some stage such things may still be useful when I want to do something very specific but otherwise thanks all, EPSeasy seems amazaing. :lol:

Re: How to put in json two values t and h and send it to Domoticz

Posted: Thursday 09 March 2017 20:55
by homerruma