Interesting ESP8266 WiFi Module Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Rebels
Posts: 6
Joined: Thursday 04 December 2014 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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&param=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.
Rebels
Posts: 6
Joined: Thursday 04 December 2014 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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&param=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 ;-)
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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 :D
Zycker
Posts: 24
Joined: Monday 29 December 2014 8:04
Target OS: Linux
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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&param=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.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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).
I am not active on this forum anymore.
Zycker
Posts: 24
Joined: Monday 29 December 2014 8:04
Target OS: Linux
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post by Zycker »

Here is what I get :
Image

Thanks for the link, I'll take a look.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
I am not active on this forum anymore.
Zycker
Posts: 24
Joined: Monday 29 December 2014 8:04
Target OS: Linux
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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 :
Image
Rebels
Posts: 6
Joined: Thursday 04 December 2014 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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 :D
Done! :D
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.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post by ThinkPad »

Nice, i directly made some additions to the wiki page. I added some nice projects i read about a while ago.
I am not active on this forum anymore.
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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 :D
Done! :D
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?
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
I am not active on this forum anymore.
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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
I am not active on this forum anymore.
User avatar
Keptenkurk
Posts: 103
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post by Keptenkurk »

Thanks Rebels and Thinkpad for the very nice and clear Wiki ! Playtime!
/paul
Zycker
Posts: 24
Joined: Monday 29 December 2014 8:04
Target OS: Linux
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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 :D
Done! :D
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.
mirek
Posts: 1
Joined: Tuesday 10 March 2015 19:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2284
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
Rebels
Posts: 6
Joined: Thursday 04 December 2014 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
webster
Posts: 15
Joined: Saturday 13 December 2014 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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&param=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)
RPI B+
RPI 2
Fibaro motion sensors , Philips Hue, Z-Wave dimmers, Eneco Toon
Honeywell Evohome 1-Wire Wifi sensors
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Interesting ESP8266 WiFi Module

Post 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.
I am not active on this forum anymore.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest