ESP8266 Deepsleep verwenden

Guten Tag,

ich arbeite an einer Wetterstation mit einem ESP8266.

Alles drum herum mit Raspberry als Server und ESP als Client funktioniert auch.

Nur ein Problem besitze ich noch: Mein ESP sendet ausgelesene Daten vom DHT22 an den Raspberrry, danach soll er, wegen dem minimalen Stromverbrauch, in den DeepSleep Modus gehen:Node MCU deepsleep

Nun wenn ich mein Programm abspielen lasse (ohne dsleep), dann werden die Daten gesendet.
Mit Dsleep wird zwar alles ausgeführt, aber am Schluss kommt dann im ESPlorer
"HTTP client: Disconnected with error: -11"
"HTTP client: Connection timeout"

Das sieht irgendwie aus, als ob das Programm abgebrochen wird. Da ich leider noch nichts mit LUA geschrieben habe, weiß ich auch nicht, wie ich "dsleep" ausführen muss. Oder einfach ganz zum Schluss machen kann.
Mein Code hierzu:

local SSID = "FRITZesBox!"
local SSID_PASSWORD = "61833906480538706789"
local SIGNAL_MODE = wifi.PHYMODE_N
DHT_PIN = 4
INTERVAL = 10 -- seconds
RASPBERRY_PI_URL = "http://192.168.178.41:8000/esp8266_trigger"
SERVER_PASSWORD = "tutorials-raspberrypi.de"
 
 
function wait_for_wifi_conn ( )
   tmr.alarm (1, 1000, 1, function ( )
      if wifi.sta.getip ( ) == nil then
         print ("Waiting for Wifi connection")
      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 ( ))
      end
   end)
end
 
function transmit_msg(data)
    -- send http request to Raspberry Pi
    ok, json = pcall(sjson.encode, data)
    if ok then        
        http.post(RASPBERRY_PI_URL, 
            'Content-Type: application/json\r\n',
            json,
            function(code, data)
                if (code < 0) then
                    print("HTTP request failed")
                --else
                --    print(code, data)
                end
        end)
    else
        return false
    end
end
 
function readDHTValues()
    status, temp, humi, temp_dec, humi_dec = dht.read(DHT_PIN)
    if status == dht.OK then
        print("ok")
        return {temperature= temp, humidity= humi}    
    else
        print("not ok")
        return false
    end
end
 
function main()
    for i=1,1 do
        gpio.mode(4,gpio.INPUT)
        gpio.mode(1,gpio.OUTPUT)
        gpio.write(1,gpio.HIGH)
        print(gpio.read(1),"\n")
        tmr.delay(2 * 1000000)
        gpio.write(1,gpio.LOW)
        print(gpio.read(1),"\n")
        tmr.delay(2 * 1000000)
        data = readDHTValues()
        if data ~= false then
            
            data["sender_id"] = wifi.ap.getmac()
            data["password"] = SERVER_PASSWORD
        
            transmit_msg(data)
            break
        end
    end

    deepsleep()
end

function deepsleep()
    tmr.delay(3 * 1000000)
    node.dsleep(10*1000000)
end
 
-- Configure the ESP as a station (client)
wifi.setmode(wifi.STATION)
wifi.setphymode(SIGNAL_MODE)
--wifi.sta.config(SSID, SSID_PASSWORD)
wifi.sta.config {ssid=SSID, pwd=SSID_PASSWORD}
wifi.sta.autoconnect(1)
 
-- Hang out until we get a wifi connection before the httpd server is started.
wait_for_wifi_conn ( )
 
 
tmr.alarm(2, INTERVAL * 1000, tmr.ALARM_AUTO, function ()
    main()
end)

Das Tutorial stammt von hier: Tutorial

Im Anhang ist noch ein Screenshot.
Falls ihr noch mehr Details braucht einfach fragen :smiley:

Gruß

Mit LUA bist Du hier wahrscheinlich falsch. Hier geht es um den Arduino, die Arduino-IDE und damit um C++.

Wahrscheinlich bist Du in einem ESP8266-LUA-Forum besser aufgehoben oder Du schreibst es in C++ um.

Gruß Tommy