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
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
Hi,
I can't find anything how to http commands should work??
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)
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
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
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
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
ok, thank you
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?
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)
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.
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
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
Tschakaaaa, it works now!
CUL_WS
esp8266temp
T: 25.0625
Thank you.. Maybe i can transmit now other things than temperature.
robin
Go Robin go.
Und dann alles in dein meintechblog.de.
Großartig diese Seite.
Gruß Stefan
i will test this. i have a dth here, but not today.
@stefan, no i will write a short statement my own blog.
But the interesting part of the 8266 is the sleep mode, because at the moment i takes too much current.
Robin
Yes we must now look at deep sleep, but I think it's not easy on an esp-01. I think needed is the esp8266-12 for that.
Goal: dht22 with deep sleep fully battery powered push data to fhem every 1 minutes.
Hello kroonen,
i used your code in my blog with a few modifications. I hope its okay.
http://blog.moneybag.de/fhem-temperaturmessung-mit-dem-esp-8266-und-ds18b20-ohne-arduino-datenuebertragung-per-wlan/
@Stefan. Du kannst den Beitrag abschreiben und bei dir im blog setzen.
LG
/robin
No problem, mostly I also copied from others.
Let me know if it is up for a week or so, to see how stable it is.
regards Richard
Hi,
The Site meintechblog.de is not mine,
This Site belongs to another User from FhemForum.
Thx
Stefan
Hi,
I'm also busy with the dht22, but the temp and humidity are not stable, any ideas are welcome. I used a dht22 with resistor 4.7k and without, and also tried this schema
http://www.esp8266.com/viewtopic.php?f=19&t=1363
output in log file
2015-03-09_13:16:31 Testtemp T: 21.9 H: 42.2
2015-03-09_13:17:01 Testtemp T: 24.3 H: 44.2
2015-03-09_13:17:31 Testtemp T: 21.3 H: 43.7
2015-03-09_13:18:01 Testtemp T: 21 H: 45
2015-03-09_13:18:31 Testtemp T: 20.8 H: 45
2015-03-09_13:19:01 Testtemp T: 20.6 H: 45.5
2015-03-09_13:19:31 Testtemp T: 20.4 H: 45.8
2015-03-09_13:20:01 Testtemp T: 20.4 H: 46.2
2015-03-09_13:20:31 Testtemp T: 20.3 H: 46.6
2015-03-09_13:21:01 Testtemp T: 20.2 H: 46.8
2015-03-09_13:21:31 Testtemp T: 20.7 H: 47.4
2015-03-09_13:22:01 Testtemp T: 20 H: 47.1
2015-03-09_13:22:31 Testtemp T: 20 H: 47.4
2015-03-09_13:23:01 Testtemp T: 19.9 H: 47.5
2015-03-09_13:23:31 Testtemp T: 20.7 H: 48.1
2015-03-09_13:24:01 Testtemp T: 20 H: 48.1
2015-03-09_13:24:31 Testtemp T: 19.8 H: 47.8
2015-03-09_13:25:01 Testtemp T: 21 H: 49.2
2015-03-09_13:25:31 Testtemp T: 19.8 H: 47.9
2015-03-09_13:26:01 Testtemp T: 20.7 H: 48.5
using this config
laster dht22.lua from node mcu , the init.la like above for ds18b20
https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/dht22
and fhem.lua
tmr.alarm(0,30000, 1, function()
PIN = 4 -- data pin, GPIO2
dht22 = require("dht22")
dht22.read(PIN)
t = dht22.getTemperature()
h = dht22.getHumidity()
humi=dht22.getHumidity()/10
temp=dht22.getTemperature()/10
if h == nil then
print("Error reading from DHT22")
else
-- temperature in degrees Celsius and Farenheit
-- floating point and integer version:
print("Temperature: "..((t-(t % 10)) / 10).."."..(t % 10).." deg C")
-- only integer version:
print("Temperature: "..(9 * t / 50 + 32).."."..(9 * t / 5 % 10).." deg F")
-- only float point version:
print("Temperature: "..(9 * t / 50 + 32).." deg F")
-- humidity
-- floating point and integer version
print("Humidity: "..((h - (h % 10)) / 10).."."..(h % 10).."%")
end
-- release module
dht22 = nil
package.loaded["dht22"]=nil
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' ..temp.. '%20H:%20'..humi..'\r\n HTTP/1.1\r\nHost: www.local.lan\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n"')
end)
Got it stable. The dht22 must be connected to the 5v , than it works
2015-03-09_14:29:04 Testtemp T: 19.6 H: 48.5
2015-03-09_14:29:34 Testtemp T: 19.6 H: 48.4
2015-03-09_14:33:04 Testtemp T: 19.6 H: 48.3
2015-03-09_14:33:34 Testtemp T: 19.6 H: 48.4
2015-03-09_14:34:04 Testtemp T: 19.6 H: 48.3
2015-03-09_14:34:34 Testtemp T: 19.7 H: 48.5
2015-03-09_14:35:04 Testtemp T: 19.6 H: 48.4
2015-03-09_14:35:34 Testtemp T: 19.6 H: 48.3
2015-03-09_14:37:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:37:34 Testtemp T: 19.6 H: 48.3
2015-03-09_14:38:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:39:04 Testtemp T: 19.6 H: 48.3
2015-03-09_14:39:34 Testtemp T: 19.7 H: 48.4
2015-03-09_14:40:04 Testtemp T: 19.6 H: 48.3
2015-03-09_14:41:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:41:34 Testtemp T: 19.6 H: 48.3
2015-03-09_14:42:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:46:34 Testtemp T: 19.7 H: 48.3
2015-03-09_14:47:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:47:34 Testtemp T: 19.7 H: 48.3
2015-03-09_14:48:04 Testtemp T: 19.7 H: 48.4
2015-03-09_14:48:34 Testtemp T: 19.7 H: 48.2
2015-03-09_14:49:04 Testtemp T: 19.7 H: 48.3
2015-03-09_14:49:34 Testtemp T: 19.7 H: 48
2015-03-09_14:50:04 Testtemp T: 19.7 H: 48.2
thank you kroonen, i will give it a try :-)
Robin
Nice work guys :) With your help i've got my ESP8266-201 running. I used arduino to program the ESP8266 instead of lua, and interfacing to the fhem i used your solution. Hat off to Kroonen many thanks.
@Chunky,
Can you also post the arduino code. It's based on de arduino ide?
regards Richard
Yes of course:#include <OneWire.h>
#include <ESP8266WiFi.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
OneWire ds(0); // on pin 2 (a 4.7K resistor is necessary)
const char* ssid = "XX-XXXXXX";
const char* password = "XXXXXXXXXXXXXXX";
const char* host = "10.0.0.15";
void setup(void) {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(60000); // 1 Minute delay
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 8083;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/fhem?cmd=setreading%20esp8266temp%20state%20";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + celsius + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Authorization: Basic Rsdfsfdsno6MDYwMg==\r\n" +
"Connection: keep-alive\r\n" +
"Accept: */*\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
It's chanky btw ;-)
Hello,
is there a way to use Telnet-port 7270 with user and Password ?
Greetings Christian
Have a look here: https://forum.fhem.de/index.php?topic=55728
Grüße Jörg
Gesendet von iPad mit Tapatalk
Hallo Jörg, (ich probier mal auf deutsch ;-) )
wie geht denn die Kurzfassung ohne 11 Seiten lesen zu müsen ? Ich schicke über den Telnet-Port per LUA direkt auf FHEM, aber der Telnet-Port ist aktuell offen ohne PW. Nun suche ich nach einer Möglichkeit, eben auch User und PW mit zu übertragen.
Hier mal der Codeschnipsel, mit dem ich das schicke:
conn2=net.createConnection(net.TCP, 0)
-- direkt über Telnet auf FHEM schießen
conn2:connect(7072,"192.168.X.XX")
print("Tasterdruck an FHEM gesendet")
if gpio.read(6)==1 then
conn2:send("set WLAN_Testdose on\nexit\n");
print("ON gesendet");
end
Grüße
Christian
Hallo Christian,
es ist alles relativ einfach. Du installierst die aktuelle ESPEasy Version und das im Thread bereitgestellte Fhem Modul. In ESPEasy Fhem als Ziel auswählen, hier kannst Du auch User/Passwort angeben und die entsprechenden Sensoren/Aktionen als Device den GPIO zuordnen. In Fhem ein entsprechendes Device anlegen, und schon schickt ESPEasy Daten an Fhem.
Grüße Jörg
Nö,
das hilft leider nicht, weil ich die Software selber programmiere, ohne ESPeasy, direkt in LUA, damit die das tut, was ich haben will, das läßt sich mit ESPeasy leider nicht darstellen...
Grüße
Christian
Hier ein Beispiel aus dem Forum
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end )
conn:connect(7072,"192.168.2.2")
conn:send("meinpasswort\n")
conn:send("setreading Multisensor_Ost lux " ..luxi.. "\n")
conn:send("setreading Multisensor_Ost temperature " ..temp.. "\n")
conn:send("setreading Multisensor_Ost humidity " ..humi.. "\nexit\n")
https://forum.fhem.de/index.php/topic,28905.180.html
Grüße Jörg
Gesendet von iPad mit Tapatalk
Cooool, das werde ich mal probieren :-)
Daaaanke
Grüße
Christian Schmitz
Jawoll,
damit funktioniert es :-)
Vielen Vielen Dank !!!
LG
Christian