Page 3 of 6
Re: Interesting ESP8266 WiFi Module
Posted: Tuesday 24 February 2015 20:33
by Rebels
I've been at this for a while now, but still without any success. I'm trying to get a temperature reading from a DS18B20 1wire sensor that is connected directly to an ESP8266 module wich has nodeMCU installed.
The principle works. Ik can get it to connect to my wifi network, and with a simple webserver I can read the temperature of the sensor in a webbrowser.
But I want the ESP to send it automatically to my Domoticz server. Using the examples given in this topic, and elsewere on the net I did succeeed up until a certain point. Everything seems to work, but there is no data in Domoticz. Maybe someone can help me take the last hurdle.
Some more info regarding to my setup:
The IP address of the Domoticz server is 192.168.8.12
The IP address of the ESP8266 is 192.168.8.99
I've created a dummy device so i got a temperature sensor in Domoticz. The ID of the device is 32
On the ESP, i use the following script to connect to my WiFi and give it a static IP address:
Code: Select all
--init.lua
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
wifi.sta.config("MySSID","MyWPA2key")
wifi.sta.connect()
wifi.sta.setip({ip="192.168.8.99",netmask="255.255.255.0",gateway="192.168.8.11"})
print("ESP8266 mode is: " .. wifi.getmode())
print("The module MAC address is: " .. wifi.ap.getmac())
print("Config done, IP is "..wifi.sta.getip())
dofile ("domoticz.lua")
Then I use the DS18B20.lua script so I can read the DS18B20 sensor. This code can be found in the github area of the NodeMcu code.
This works like a charm. I get correct temperatures at the serial console.
Last, I trie to send the temperature to Domoticz, and I think that there is the problem somewhere, but I do not see it.
The code I use is:
Code: Select all
require('ds18b20')
-- ESP-01 GPIO Mapping
gpio0 =3
gpio2 =4
-- ds18b20.setup(gpio0)
ds18b20.setup(gpio2)
t1=ds18b20.read()
print("Temp:" .. ds18b20.read() .. " C\n")
conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(8080,"192.168.8.12")
conn:send("GET /json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=" .. t1 .. " HTTP/1.1\r\nHost: 192.168.8.12:8080\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
I've tried switching IP adresses, but that didn't help. I'm at a loss. Does someone see what I am missing?
Thanx for looking.
Ed.
Re: Interesting ESP8266 WiFi Module
Posted: Wednesday 25 February 2015 19:40
by Rebels
I've fixed it!
As it turns out I made a few mistakes in the script thats sends the data to domoticz.
The working script is below.
Code: Select all
require('ds18b20')
-- ESP-01 GPIO Mapping
gpio0 =3
gpio2 =4
ds18b20.setup(gpio2)
t=ds18b20.read()
print("Temp:" .. ds18b20.read() .. " C\n")
if(t==nil) then
t=0
end
tmr.alarm(0,30000, 1, function()
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(8080,"192.168.8.12")
conn:send("GET /json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=" .. t .. " HTTP/1.1\r\nHost: www.local.lan\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
So now it it time to put those mini sensors everywhere
Re: Interesting ESP8266 WiFi Module
Posted: Wednesday 25 February 2015 23:30
by roblom
Rebels wrote:So now it it time to put those mini sensors everywhere
But first write a wiki on how to build and program these sensors so we can all put it everywhere
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 7:41
by Zycker
I finally managed to get my pulse counter working in Domoticz thanks to sweetpants and mvdbro, here is my lua code. That's not complicated but it could be usefull to someone.
Code: Select all
count = 1
delay = 0
gpio.mode(2,gpio.INT)
function counter(level)
x = tmr.now()
if x > delay then
delay = tmr.now()+250000
count = count + 1
conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(8080,"192.168.1.22")
conn:send("GET /json.htm?type=command¶m=udevice&idx=XX&svalue=" .. count .." HTTP/1.1\r\nHost: <192.168.1.22>:8080\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end
end
gpio.trig(2, "down",counter)
Now I will try to optimize that to send count every minutes or every X kWh.
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 9:18
by ThinkPad
Nice, what do you see in Domoticz for kind of device? Can you make a screenshot.
Also, have a look at this Lua code for ESP:
http://gathering.tweakers.net/forum/lis ... 6#43783066
It also does pulsecounting, but also gasmeter reading (reedcontact).
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 9:28
by Zycker
Here is what I get :
Thanks for the link, I'll take a look.
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 9:30
by ThinkPad
Ok, nice. But you don't have the actual usage with your code. With the code from the link (explanation is in Dutch unfortunately) i was able to get the actual usage ("473W") in Domoticz and also the graphs like you show.
But something that annoyed me, is that the counting part is done completely on the ESP. You only say to Domoticz: "today xx kWh". So if the ESP reboots, your measurements are gone, and the day counter will start back at 0.... I was hoping someone would create a workaround for that, but haven't seen it yet.
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 10:24
by Zycker
The code from the link is quiet interesting, I'm modifying it for my setup, tests are coming soon.
For the esp8266 reboot problem, I thought about it and in fact domoticz manage to keep updating the counter without start back at 0.
I've restarted my esp-12 a couple of time this morning and I get this :
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 18:03
by Rebels
roblom wrote:Rebels wrote:So now it it time to put those mini sensors everywhere
But first write a wiki on how to build and program these sensors so we can all put it everywhere
Done!
There now is a Wiki page "ESP8266 WiFi module" under "Protocols, sensors and integration".
I've documented everything I've done and tried to be as clear as possible.
Regards,
Rebels.
Re: Interesting ESP8266 WiFi Module
Posted: Saturday 28 February 2015 20:11
by ThinkPad
Nice, i directly made some additions to the wiki page. I added some nice projects i read about a while ago.
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 12:25
by roblom
Rebels wrote:roblom wrote:Rebels wrote:So now it it time to put those mini sensors everywhere
But first write a wiki on how to build and program these sensors so we can all put it everywhere
Done!
There now is a Wiki page "ESP8266 WiFi module" under "Protocols, sensors and integration".
I've documented everything I've done and tried to be as clear as possible.
Regards,
Rebels.
You're my hero for today!
Now I have to find some time to experiment with it.
Short question, what is the power consumption of this setup? I don't think it is possible to make it battery powered isn't it?
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 12:45
by ThinkPad
The ESP8266 can use up to 250mA when sending data over WiFi, so nah... not really battery-friendly.
You can make it less power hungry by putting it in (deep) sleep between updates, but WiFi is just a power hungry medium.
If you look at the comments on
this page, you will see that he had the ESP running for 5 days on a powerbank with 2x 2800mAh lithium cells.
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 12:52
by roblom
Besides the fysical differences, does it matter which ESP8266 I use for the wiki? I have bought a 03 variant a long time ago, I assume i can use that one.
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 12:54
by ThinkPad
Yeah, shouldn't be a problem. The 03 has more GPIO available.
This also means you maybe have to change the pin assignment in the code, but i am not sure. Just try
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 14:28
by Keptenkurk
Thanks Rebels and Thinkpad for the very nice and clear Wiki ! Playtime!
/paul
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 01 March 2015 14:50
by Zycker
Rebels wrote:roblom wrote:Rebels wrote:So now it it time to put those mini sensors everywhere
But first write a wiki on how to build and program these sensors so we can all put it everywhere
Done!
There now is a Wiki page "ESP8266 WiFi module" under "Protocols, sensors and integration".
I've documented everything I've done and tried to be as clear as possible.
Regards,
Rebels.
Nice, that's a good start.
Re: Interesting ESP8266 WiFi Module
Posted: Tuesday 10 March 2015 21:15
by mirek
ESP8266 + BMP180 domoticz.lua script.
How to transfer data to domoticz of esp8266 + bmp180 without arduino?
Domoticz.lua script needed. Analogous to the ESP8266 + DS18B20.
Regards Mirek.
Re: Interesting ESP8266 WiFi Module
Posted: Thursday 12 March 2015 8:37
by Rebels
A simpel Google Search resulted in this link
http://www.esp8266.com/viewtopic.php?f=19&t=1896
So it looks like it is supported whitin NodeMCU. Just connect it, load the library and replace the Json lines with the right ones for the barometric device and you should be fine.
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 15 March 2015 20:18
by webster
Ok i got the module working with 1 DS18B20 sensor
but i can't get it to work with 2 sensors
does sombody got it working with 2 sensors and is willing to share the lua script
here is my current lua script for 1 sensor
Code: Select all
--domoticz.lua
require('ds18b20')
-- ESP-01 GPIO Mapping
gpio0 =3
gpio2 =4
ds18b20.setup(gpio2)
t=ds18b20.read()
print("Temp:" .. ds18b20.read() .. " C\n")
if(t==nil) then
t=0
end
tmr.alarm(0,30000, 1, function()
t=ds18b20.read()
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(8080,"192.168.0.45")
conn:send("GET /json.htm?type=command¶m=udevice&idx=73&nvalue=0&svalue=" .. t .. " HTTP/1.1\r\nHost: www.local.lan\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
Re: Interesting ESP8266 WiFi Module
Posted: Sunday 15 March 2015 20:45
by ThinkPad
Yes i have:
http://www.domoticz.com/forum/viewtopic.php?f=38&t=5301 (second post).
But the code is not very stable. It is rebooting every few measurements. But that doesn't really bother me, as it automatically starts measuring & uploading after a crash (reboots automatically). Have it working for about a week now, works great with the Python logging i use that a fellow forum member made.
I also have to put in a delay after powering on. I have it placed on a timer outlet so it turns off at night (i hate idle power consumption). But when it turns on at 06:00, i receive a measurement of 85 degrees (default startup value of DS18B20). I think by putting in a small delay i can avoid this. Haven't had time to look at this though
Tomorrow going to create a second module, to put in the bedroom.