With ESP8266 send data to fhem

Begonnen von kroonen, 05 März 2015, 18:53:11

Vorheriges Thema - Nächstes Thema

kroonen

Hi,

I read this about the esp8266 to go to deep sleep and send data to a node.js server

http://blog.hekkers.net/2015/03/01/esp8266-testing-deep-sleep-interrupts/

Is it possible to send data like that to fhem?? So for exampl port 8001 maps to a temp sensor in them??

It should be nice to have an dht22 for that so it sends data every 2 miniutes tofhem to the esp8266 and the rest of the time is goed to deep sleep



schka17

you have some posibilities, i.e. connect via telnet to 7072 and "set %device %Value", or you can use the http command to your fhem port. Or you can use the ECMD device which is mor flexible but a little bit more difficult.


regards,

Karl
M: Thinclient x64 Debian | CUL FS20, HMS100WD, HMS100TF, HMS100T, HMS100CO, S300, S555TH | OWServer DS1420, DS18B20, DS2408 | RFXCOM UVN128, THWR800, THGR228N,RTGR328, PCR800 |Jeelink PCA301 EC3000|CUNO+IR|HMLAN|HMUSB|CUL433 Somfy|mySensors|espEasy
S1:Raspberry mit BPM810, Jeelink EC3000

kroonen

Hi,

I can't find anything how to http commands should work??




kroonen

this is something


192.168.180.5:8083/fhem?cmd=setreading%20mayatemp%20state%20T%2020

any idea what i must replace to get above working in this piece, with socket send?

socket:send(""fhem?cmd=setreading%20mayatemp%20state%20T%"..temp.."\r")

but I don't think thats correct?


below original code

serv_ip = '192.168.180.5'
serv_port = 8083
gpio4 = 2
interval = 20000000
ds18b20.setup(gpio4)

function getTemp()
  temp = ds18b20.read()
  conn = net.createConnection(net.TCP, 0)
  conn:on("connection", function(socket)
    socket:send(""..node.chipid().." "..tries.." "..temp.."\r")
  end)
  conn:on("sent",function(conn)
    conn:close()
  end)
  conn:on("disconnection", function(conn)
    node.dsleep(interval-tmr.now(), 0)
  end)

  conn:connect(serv_port, serv_ip)



fh168

hello kroonen,

i wanted to try the example, but i got an error in lua (arg wrong range) in

socket:send(""..node.chipid().." "..tries.." "..temp.."\r")

i am using lualoader 0.83 and latest firmware of the esp.

robin

Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

kroonen

#5
Hi Robin

I now have it working with this , here the init.lua en fhem.lua, next I hope to get it working with the dht22

--init.lua
wifi.sta.config("ssidname","password")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
  if wifi.sta.getip()== nil then
  print("IP unavaiable, Waiting...")
else
  tmr.stop(1)
print("ESP8266 mode is: " .. wifi.getmode())
print("The module MAC address is: " .. wifi.ap.getmac())
print("Config done, IP is "..wifi.sta.getip())
dofile ("fhem.lua")
end
end)

--fhem.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(8083,"192.168.180.5")
conn:send('GET /fhem?cmd=setreading%20Testtemp%20state%20T:%20' ..t.. '\r\n HTTP/1.1\r\nHost: www.local.lan\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n"')
end)

And also this in fhem

attr Testtemp IODev CUL
attr Testtemp event-min-interval state:600
attr Testtemp event-on-change-reading state
attr Testtemp event-on-update-reading .*
attr Testtemp room ESP8266

define FileLog_Testtemp FileLog /var/log/fhem/Testtemp-%Y.log Testtemp
attr FileLog_Testtemp logtype temp4hum4:Temp/Hum,text
attr FileLog_Testtemp room ESP8266

define weblink_Testtemp SVG FileLog_Testtemp:temp4hum4:CURRENT
attr weblink_Testtemp label "Schuur Min $data{min1}, Max $data{max1}, Last $data{currval1}"
attr weblink_Testtemp room Plots

fh168

#6
hi koonen,

i have a question about the library ds18b20.
do i have to modify the library (paths and so) or is this just an upload of the ds16b20.lua?

because in the Source of the library. there are ...


-- DS18B20 one wire module for NODEMCU
-- NODEMCU TEAM
-- LICENCE: http://opensource.org/licenses/MIT
-- Vowstar <vowstar@nodemcu.com>
--------------------------------------------------------------------------------

-- Set module name as parameter of require
local modname = ...


Robin
Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

kroonen

Robin,

I took the file from here

https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/ds18b20

than the ds18b20.lua

Upload the file like the other and than should work


fh168

Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

fh168

#9
i have some problems:

NodeMCU 0.9.5 build 20150127  powered by Lua 5.1.4
>
Hard Restart Samstag, 7. März 2015  19:47:34

IP unavaiable, Waiting...
IP unavaiable, Waiting...
ESP8266 mode is: 1
The module MAC address is: 1A-FE-34-9C-E2-CB
Config done, IP is 192.168.178.34
PANIC: unprotected error in call to Lua API (fhem.lua:7: attempt to concatenate a nil value)
PANIC: unprotected error in call to Lua API (attempt to concatenate a lightfunction value)
PANIC: unprotected error in call to Lua API (attempt to call a string value)
ü!  ¤§1ä)]ô1ä)]†1¤ñ¡Hø


temperature works.

fhem noch niet... is a define missing?
Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

kroonen

Trying to post again maybe cut and paste went wrong?

Zitat--fhem.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(8083,"192.168.180.5")
conn:send('GET /fhem?cmd=setreading%20Testtemp%20state%20T:%20' ..t.. '\r\n HTTP/1.1\r\nHost: www.local.lan\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n"')
end)

fh168

#11
i think theres somewhere a define for Testtemp

and in lua is:  www.local.lan   is this correct or have to be a ip adress?

please use the code function (#) here in the forum -editor to paste the code.
Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-

kroonen

Yes sorry the define was missed. www.local.lan is just dummy

define Testtemp CUL_WS 2
attr Testtemp IODev CUL
attr Testtemp event-min-interval state:600
attr Testtemp event-on-change-reading state
attr Testtemp event-on-update-reading .*
attr Testtemp room ESP8266


kroonen

#13
I tested your config with dht22 and init.lau but strange values

Any idea what cause this

Humidity:    -0.1%
Temperature: 79.3 deg C
> Humidity:    -0.1%
Temperature: 80.1 deg C
Humidity:    -0.1%
Temperature: 78.1 deg C
Humidity:    -0.1%
Temperature: 77.7 deg C


fh168

Tschakaaaa, it works now!

CUL_WS
esp8266temp
T: 25.0625

Thank you.. Maybe i can transmit now other things than temperature.

robin
Hue, Lacrosse, PCA301, MySensors, V 1.67 CUL 868 V3.4, Lacrosse-WLAN-Gateway, Tasmota RF-