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

Moderator: leecollings

Post Reply
tomallm
Posts: 2
Joined: Wednesday 24 February 2016 18:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
Last edited by tomallm on Wednesday 24 February 2016 20:34, edited 1 time in total.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

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

Post 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.
Last edited by simonrg on Wednesday 24 February 2016 20:23, edited 1 time in total.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
BobS
Posts: 15
Joined: Friday 05 June 2015 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Rotterdam, NL
Contact:

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

Post by BobS »

Hi,
You might consider using ESPeasy (www.esp8266.nu) it supports Domoticz and DHT11.
All programming has already been done for you.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

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

Post 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
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
tomallm
Posts: 2
Joined: Wednesday 24 February 2016 18:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

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

Post 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:
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
User avatar
homerruma
Posts: 6
Joined: Tuesday 07 March 2017 17:01
Target OS: Windows
Domoticz version: 4.9700
Location: Ruma-Serbia
Contact:

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

Post by homerruma »

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest