Bobby
Published

ESP-07 (or ESP-12) with NodeMCU going into deep sleep

Sample project how to set up ESP-07 (or ESP-12) with NodeMCU going into deep sleep

BeginnerProtip32,369
ESP-07 (or ESP-12) with NodeMCU going into deep sleep

Things used in this project

Hardware components

USB to TTL FT232
×1
Espressif ESP-07
×1

Software apps and online services

NodeMCU Firmware programmer
NodeMCU firmware
NodeMCU firmware
Esplorer

Story

Read more

Schematics

ESP-07 Pinout

ESP8266 GPIO list and NodeMCU index

Code

init.lua

Lua
--init.lua

wifi.setmode(wifi.STATION)
wifi.sta.config("ssidname","ssidpassword")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
    print("Waiting for IP...")
else
    tmr.stop(1)
    print("Your IP is "..wifi.sta.getip())
    dofile("sleep.lua")
end
end)

sleep.lua

Lua
-- retrieve the current time from Google
print("Check the time...")
conn=net.createConnection(net.TCP, 0) 

conn:on("connection",function(conn, payload)
            conn:send("HEAD / HTTP/1.1\r\n".. 
                      "Host: google.com\r\n"..
                      "Accept: */*\r\n"..
                      "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
                      "\r\n\r\n") 
            end)
            
conn:on("receive", function(conn, payload)
    print('Retrieved in '..((tmr.now()-t)/1000)..' milliseconds.')
    print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
           +6,string.find(payload,"Date: ")+35))
           print("Going to sleep...gone in 60s")
    -- enable deepsleep for 60 s (60 x 1000 x 1000)
    node.dsleep(60000000)
    conn:close()
    end) 
t = tmr.now()    
conn:connect(80,'google.com') 

Credits

Bobby

Bobby

2 projects • 9 followers

Comments