ESP8266 schickt Temperatur an SHC
Your browser (%browser%) is out of date. It has known security flaws and may not display all features of this and other websites. \
Learn how to update your browser'.
-
-
gibt es den irgendwelche "fehlermeldungen" was steht in der serial console ?
-
Hallo
Hab nochmal neu aufgesetzt mit der init.lua vom DS18 und mit den oben genannten dht22.lua und shcdht22.lua.
in der serial consolle steht:
Source Code
- Y…O;ž’e‡þOAE’e†ü$Ž
- PORT OPEN 9600
- FILE="dht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > ESP_Receiver=function(rcvBuf) if string.match(rcvBuf,"^ESP_cmd_close")==nil then file.write(string.gsub(rcvBuf, '\r', '')) uart.write(0, "> ") else uart.on("data")
- >> file.flush() file.close() FILE=nil rcvBuf=nil ESP_Receiver=nil uart.setup(0,9600,8,0,1,1) str="\r\n--Done--\r\n> " print(str) str=nil collectgarbage() end end uart.on("data",'\r',ESP_Receiver,0)-- ***************************************************************************
- -- DHT22 module for ESP8266 with nodeMCU
- --
- -- Written by Javier Yanez
- --stdin:2: unexpected symbol near '*'
- > but based on a script of Pigs Fly from ESP8266.com forum
- --
- -- MIT license, http://opensource.org/licenses/MIT
- -- ***************************************************************************
- local moduleName = ...
- local M = {}
- _G[moduleName] = M
- local humidity
- local temperature
- function M.read(pin)
- local checksum
- local checksumTest
- humidity = 0
- temperature = 0
- checksum = 0
- -- Use Markus Gritsch trick to speed up read/write on GPIO
- local gpio_read = gpio.read
- local bitStream = {}
- for j = 1, 40, 1 do
- bitStream[j] = 0
- end
- local bitlength = 0
- -- Step 1: send out start s
- stdin:1: '<eof>' expected near 'end'
- > ignal to DHT22
- gpio.mode(pin, gpio.OUTPUT)
- gpio.write(pin, gpio.HIGH)
- tmr.delay(150stdin:1: '=' expected near 'to'
- > )
- gpio.write(pin, gpio.LOW)
- --tmr.delay(20000)
- tmr.delay(40)
- --delayMicroseconds(40)
- --gpio.write(pin, gpio.HIGH)
- gpio.mode(pin, gpio.INPUT)
- -- Step 2: DHT22 send response signal
- -- bus will always let up eventually, don't bother with timeout
- while (gpio_read(pin) == 0 ) do end
- local c=0
- while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
- -- bus will always let up eventually, don't bo
- stdin:1: attempt to call global 'gpio_read' (a nil value)
- > ther with timeout
- while (gpio_read(pin) == 0 ) do end
- c=0
- while (gpio_read(pin) == 1 astdin:1: '=' expected near 'with'
- > nd c < 500) do c = c + 1 end
- -- Step 3: DHT22 send data
- for j = 1, 40, 1 do
- while (gpio_read(pin) == 1 and bitlength < 10 ) do
- bitlength = bitlen
- stdin:1: '=' expected near 'c'
- > gth + 1
- end
- bitStream[j] = bitlength
- bitlength = 0
- -- bus will always let up eventually, don't bother with timeout
- while (gpio_read(pin) == 0) do end
- end
- --DHT data acquired, process.
- for i = 1, 16, 1 do
- if (bitStream[i] > 4) then
- humidity = humidity + 2 ^ (16 - i)
- end
- end
- for i = 1, 16, 1 do
- if (bitStream[i + 16] > 4) then
- temperature = temperature + 2 ^ (16 - i)
- end
- end
- for i = 1, 8, 1 do
- if (bitStream[i + 32] > 4) then
- checksum = checksum + 2 ^ (8 - i)
- end
- end
- checksumTest = (bit.band(humidity, 0xFF) + bit.rshift(humidity, 8) + bit.band(temperature, 0xFF) + bit.rshift(temperature, 8))
- checksumTest = bit.band(checksumTest, 0xFF)
- if temperature > 0x8000 then
- -- convert to negative format
- temperature = -(temperature - 0x8000)
- end
- -- conditions compatible con float point and integer
- if (checksumTest - checksum >= 1) or (checksum - checksumTest >= 1) then
- humidity = nil
- end
- --Per DHT Arduino Lib
- gpio.mode(pin, gpio.OUTPUT)
- gpio.write(pin, gpio.HIGH)
- end
- function M.getTemperature()
- return temperature
- end
- function M.getHumidity()
- return humidity
- end
- return M
- ESP_cmd_close
- stdin:1: ')' expected near ','
- >
- >
- > FILE="shcdht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > >> > > > > > > > > >
- --Done--
- >
- >
- > FILE="init.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > >> > > > >
- --Done--
- >
- >
- > dofile("init.lua")
- 192.168.178.45 255.255.255.0 192.168.178.1
- > ESP8266 mode is: 1
- The module MAC address is: 1A-FE-34-A2-45-92
- Config done, IP is 192.168.178.45
- PANIC: unprotected error in call to Lua API (cannot open ds18b20.ü0‚~–4û!‹Y…O;ž’e‡þOAE’e†ü$Ž
[hr]
Habe einen Fehler in der init.lua gefunden,
in der Zeile 15 stand "dofile ("ds18b20.lua").
habe ich umbenannt in ("dht22.lua").
Vorher wurde nichts gesendet vom ESP, jetzt ja (blaue Led blinkt rythmisch).
Aber in SHC kommt nichts an.
In der Serial consoll sieht es jetzt so aus:
Source Code
- PORT OPEN 9600
- FILE="dht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > >> > > > > > > > > > > > >
- --Done--
- >
- >
- > FILE="shcdht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > >> > > > > > > > > >
- --Done--
- >
- >
- > FILE="init.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > >> > > > >
- --Done--
- >
- >
- > 0‚~–4û!‹Y…O;ž’e‡þOAE’e†ü$Ž
- PORT OPEN 9600
- ESP8266 mode is: 1
- The module MAC address is: 1A-FE-34-A2-45-92
- Config done, IP is 192.168.178.45
- PANIC: unprotected error in call to Lua API (dht22.lua:12: table index is nil)
- PANIC: unprotected error in call to Lua API (table index is nil)
- ü!¤<1ä)]ô1H)}†Êè
jetzige init.lua:
Source Code
- --init.lua
- wifi.setmode(wifi.STATION)
- wifi.sta.config("FritzRepeater2","93728348")
- wifi.sta.setip({ip="192.168.178.45",netmask="255.255.255.0",gateway="192.168.178.1"})
- print(wifi.sta.getip())
- wifi.sta.connect()
- tmr.alarm(1, 10000, 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 ("dht22.lua")
- end
- end)
Kann besser Hardware als Software !The post was edited 1 time, last by premo ().
-
Hey
ist ja irgendwie klar, das es nichts an SHC sendet
in deiner init.lua
verbindest du dich nur mit wlan und ruft dann dht22.lua auf
wenn das die dht22.lua ist die du oben in deinen post gepostet hast fürst du nur die lib aus diese macht nix da du dort keine funktionen aufrufst dise stellt nur die funktionen zu verfügung um die daten vom DHT auszulessen
du must jetzt die Temp und Feuchte auslesen und dann an SHC senden z.b. so:
[code=php]
PIN = 4 -- pin an den der DHT22 angeschlossen ist
dht22 = require("dht22")
dht22.read(PIN)
t = dht22.getTemperature()
h = dht22.getHumidity()
print("Daten von DHT22:" ..t.. "\n" ..h.. "\n")
-- t = temp h = feuchte jetzt kannst du die daten an SHC senden z.b. mit:
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- senden an shc
conn:connect(80,"192.168.0.15") -- ip anpassen auf die SHC ip
conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=10&sid=88&type=2&v1=" ..t.. "&v2=" ..h.. " HTTP/1.1\r\n")
conn:send("Host: 192.168.0.15\r\n") -- ip anpassen
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
conn:close()
end)
conn:on("disconnection", function(conn)
end)
end
[/php]
diesen code anstelle "dofile("dht22.lua")" einfügen und er sollte was senden evtl
empfiehtl sich noch die Var t und h zu formatieren!The post was edited 1 time, last by gMaN ().
-
Klappt nicht, als Laie garnicht einfach.
Diese 3 Lua habe ich genommen.
dht22.lua:
Source Code
- -- ***************************************************************************
- -- DHT22 module for ESP8266 with nodeMCU
- --
- -- Written by Javier Yanez
- -- but based on a script of Pigs Fly from ESP8266.com forum
- --
- -- MIT license, http://opensource.org/licenses/MIT
- -- ***************************************************************************
- local moduleName = ...
- local M = {}
- _G[moduleName] = M
- local humidity
- local temperature
- function M.read(pin)
- local checksum
- local checksumTest
- humidity = 0
- temperature = 0
- checksum = 0
- -- Use Markus Gritsch trick to speed up read/write on GPIO
- local gpio_read = gpio.read
- local bitStream = {}
- for j = 1, 40, 1 do
- bitStream[j] = 0
- end
- local bitlength = 0
- -- Step 1: send out start signal to DHT22
- gpio.mode(pin, gpio.OUTPUT)
- gpio.write(pin, gpio.HIGH)
- tmr.delay(150)
- gpio.write(pin, gpio.LOW)
- --tmr.delay(20000)
- tmr.delay(40)
- --delayMicroseconds(40)
- --gpio.write(pin, gpio.HIGH)
- gpio.mode(pin, gpio.INPUT)
- -- Step 2: DHT22 send response signal
- -- bus will always let up eventually, don't bother with timeout
- while (gpio_read(pin) == 0 ) do end
- local c=0
- while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
- -- bus will always let up eventually, don't bother with timeout
- while (gpio_read(pin) == 0 ) do end
- c=0
- while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
- -- Step 3: DHT22 send data
- for j = 1, 40, 1 do
- while (gpio_read(pin) == 1 and bitlength < 10 ) do
- bitlength = bitlength + 1
- end
- bitStream[j] = bitlength
- bitlength = 0
- -- bus will always let up eventually, don't bother with timeout
- while (gpio_read(pin) == 0) do end
- end
- --DHT data acquired, process.
- for i = 1, 16, 1 do
- if (bitStream[i] > 4) then
- humidity = humidity + 2 ^ (16 - i)
- end
- end
- for i = 1, 16, 1 do
- if (bitStream[i + 16] > 4) then
- temperature = temperature + 2 ^ (16 - i)
- end
- end
- for i = 1, 8, 1 do
- if (bitStream[i + 32] > 4) then
- checksum = checksum + 2 ^ (8 - i)
- end
- end
- checksumTest = (bit.band(humidity, 0xFF) + bit.rshift(humidity, 8) + bit.band(temperature, 0xFF) + bit.rshift(temperature, 8))
- checksumTest = bit.band(checksumTest, 0xFF)
- if temperature > 0x8000 then
- -- convert to negative format
- temperature = -(temperature - 0x8000)
- end
- -- conditions compatible con float point and integer
- if (checksumTest - checksum >= 1) or (checksum - checksumTest >= 1) then
- humidity = nil
- end
- --Per DHT Arduino Lib
- gpio.mode(pin, gpio.OUTPUT)
- gpio.write(pin, gpio.HIGH)
- end
- function M.getTemperature()
- return temperature
- end
- function M.getHumidity()
- return humidity
- end
shcdht222.lua:
Brainfuck Source Code
- --------------------------------------
- -- DS18B20 Temperatur Webserver mit statischer IP und Auto-Refresh
- --------------------------------------
- -- Quellen
- -- github.com/nodemcu/nodemcu-firmware#connect-to-your-ap
- -- github.com/nodemcu/nodemcu-firmware#or-a-simple-http-server
- -- github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/ds18b20
- --------------------------------------
- print("DHT22 v.0.1")
- function read_temp()
- PIN = 4 -- data pin, GPIO0
- dht22 = require("dht22")
- dht22.read(PIN)
- t = dht22.getTemperature()
- h = dht22.getHumidity()
- if h == nil then
- print("Error reading from DHT22")
- else
- t1 = string.sub(t,1,2)
- t2 = string.sub(t,3,4)
- h1 = string.sub(h,1,2)
- h2 = string.sub(h,3,4)
- if t2 == nil then
- t2 = 0
- elseif h2 == nil then
- h2 = 0
- end
- print ("t:" ..t1.. "." .. t2.. "\nh:" ..h1.. "." ..h2.. "\n")
- return t1,t2,h1,h2
- end
- -- release module
- dht22 = nil
- package.loaded["dht22"]=nil
- end
- end)
init.lua:
Source Code
- --init.lua
- wifi.setmode(wifi.STATION)
- wifi.sta.config("FritzRepeater2","93728348")
- wifi.sta.setip({ip="192.168.178.45",netmask="255.255.255.0",gateway="192.168.178.1"})
- print(wifi.sta.getip())
- wifi.sta.connect()
- tmr.alarm(1, 10000, 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())
- PIN = 4 -- pin an den der DHT22 angeschlossen ist
- dht22 = require("dht22")
- dht22.read(PIN)
- t = dht22.getTemperature()
- h = dht22.getHumidity()
- print("Daten von DHT22:" ..t.. "\n" ..h.. "\n")
- -- t = temp h = feuchte jetzt kannst du die daten an SHC senden z.b. mit:
- conn=net.createConnection(net.TCP, 0)
- conn:on("receive", function(conn, payload) print(payload) end)
- -- senden an shc
- conn:connect(80,"192.168.178.38") -- ip anpassen auf die SHC ip
- conn:send("GET /shc/index.php?app=shc&a&ajax=pushsensorvalues&spid=10&sid=88&type=2&v1=" ..t.. "&v2=" ..h.. " HTTP/1.1\r\n")
- conn:send("Host: 192.168.178.38\r\n") -- ip anpassen
- conn:send("Accept: */*\r\n")
- conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
- conn:send("\r\n")
- conn:on("sent",function(conn)
- conn:close()
- end)
- conn:on("disconnection", function(conn)
- end)
Kann besser Hardware als Software ! -
wie schaut den hier die debug ausgabe der init.lua aus ?
-
Hallo
Mit den aufgesetzten .lua wird nichts gesendet.
Die blaue Led bleibt dunkel.
Die Debug Ausgabe sieht so aus
Source Code
- ORT OPEN 9600
- FILE="dht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > > > > >> > > > > > > > > > > > >
- --Done--
- >
- >
- > FILE="shcdht222.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > >> > > > > >
- --Done--
- >
- >
- > dofile("shcdht222.lua")
- shcdht222.lua:39: '<eof>' expected near 'end'
- > FILE="init.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > >> > > > > > > >
- --Done--
- >
- >
- > dofile("init.lua")
- init.lua:38: 'end' expected (to close 'if' at line 8) near '<eof>'
- >
Kann besser Hardware als Software !The post was edited 1 time, last by premo ().
-
init.lua:38: 'end' expected (to close 'if' at line
near '<eof>'
hier steht ja schon wo das probelm ist
denke vor dem end) in der letzten zeil sollte noch ein "end" rein
hast du evtl skype ? könnte dir so vtl schneller helfen gerne auch über skype/teamviwer -
Skype und sonstiges habe ich leider nicht.
Habe jetzt noch mal in der init.lua
vor dem end) ein "end" gesetzt.
Gesendet wird leider immer noch nichts
(blaue Led ist stumm)
die serial console sind schonmal besser aus:
Source Code
- PORT OPEN 9600
- file.format()
- > 0‚~–4û!‹Y…O;ž’e‡þOAE’e†ü$Ž
- PORT OPEN 9600
- FILE="dht22.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > >> > > > > > > > > > > > >
- --Done--
- >
- >
- > FILE="shcdht222.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > >> > > > > >
- --Done--
- >
- >
- > FILE="init.lua" file.remove(FILE) file.open(FILE,"w+") uart.setup(0,9600,8,0,1,0)
- > >> > > > > > > >
- --Done--
- >
Kann besser Hardware als Software ! -
wenn der esp jetzt startet
wie schaut diese Debug ausgabe aus ?
ohne irgendwelche ausgaben ist es schwer den fehler zu finden -
-
sollte eigentlich sowas in der art stehen
"NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4"
wenn das net da steht dann funktioniert irgendwas noch nicht richtig -
Habe nochmal mit
"nodemcu_float_0.9.6-dev_20150704"
und den .lua`s getestet, es bleibt so.
Es erscheint kein
"NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4" .
An der dht22.lua kann es ja nicht liegen,
sind wohl Fehler in den beiden anderen .lua`s.
Die DS18 habe ich erfolgreich am laufen.
Vieleicht gibt es ja irgendwann fertige .lua.Kann besser Hardware als Software ! -
premo wrote:
Habe nochmal mit
"nodemcu_float_0.9.6-dev_20150704"
und den .lua`s getestet, es bleibt so.
Es erscheint kein
"NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4" .
Einer von meinen 5 ESPs zeigt ähnliche Symptome. Das Flashen funktioniert ohne Fehler, aber danach kommen entweder wirre Sonderzeichen oder gar nichts. Die anderen 4 funktionieren einwandfrei.
Nach etwas Recherche im Internet ist es wohl der verbaute Flash, der rumspinnen kann. Ich hab überlegt, ob ich den mal ersetze, aber bei dem Preis ist es wohl sinnvoller, bei der nächsten Bestellung noch ein paar ESPs mit zu ordern.
Zum Thema DHT:
Ist auch gerade mein Plan. Nach ewigem Probieren und Problemen mit "not enough memory" beim Laden der dht.lua bin ich hier drübergestolpert: Link
Laut Vowstar ist in den Development-Releases der Support für DHT schon fest in die Firmware eingebaut.
Hab ich grad mal geflasht und getestet, funktioniert einwandfrei -
zum fehler not enought memory einfach im ESPlorer auf die datei die aufm chip ist rechts klickt und ein "Compile ..." ausführen damit ist das problem dann behoben
-
-
Laus ja
Firmenwar gute frage wenn ich den ESP neu startet kommt eine Meldung mit der Version der Firmenwar -
gMaN wrote:
zum fehler not enought memory einfach im ESPlorer auf die datei die aufm chip ist rechts klickt und ein "Compile ..." ausführen damit ist das problem dann behoben
Hat bei mir nicht funktioniert. Compilieren wandelt ja nur die LUA Scripte zu Bytecode und das Problem ist ja nicht die Größe der Dateien, sondern der RAM.
premo wrote:
Kann ich einen ESP mit dem Esplorer auch auslesen,
z.b. welche .lua's drauf sind und Firmware.
Die Firmwareversion siehst du nur beim Booten und nur, wenn die Firmware auch ordentlich läuft.
Die Dateien siehst du am rechten Rand, unter Format, FS Info und Reload. Wenn nicht, mit Reload die Ansicht aktualisieren. -
Hast du dann auch die luas gelöscht ?
-
gMaN wrote:
Hast du dann auch die luas gelöscht ?
Ja, aber das Problem war ja nicht die Dateigröße, bei mir waren nur noch knapp 7kB Heap frei, nachdem die Scripte geladen waren.
Aber wie schon geschrieben, das Problem hat sich mit der Development-Firmware erledigt. Ich kann jetzt DHT und DS18b20 auslesen, ohne extra Scripte, und hab fast 25kB RAM frei
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0
-
Users Online 1
1 Guest