<img height="1" src="https://www.facebook.com/tr?id=1055054847899682&amp;ev=PageView&amp;noscript=1" style="display:none" width="1" />
Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!

Things used in this project

Hardware components:
USB to TTL FT232
×1
Everything ESP ESP-07
×1
Software apps and online services:
NodeMCU Firmware programmer
Nodemcu style5 150px.png 150x150
NodeMCU firmware
Esplorer

Schematics

ESP-07 Pinout
Esp pinout 07
ESP8266 GPIO list and NodeMCU index
Screenshot from 2015 09 07 220915

Code

init.luaLua
--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.luaLua
-- 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

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Slarti Fartfast

Slarti Fartfast

6 months ago

Good idea for a project, as I want to implement a sleep function, and great documentation, .

One thing that I can't quite see; you say the ESP will reset after sleep, but I don't see any call to node.restart() so what does that? surely dsleep doesnt reset, or we would lose variables, etc. sorry if that seems dumb!

Bobby

Bobby

5 months ago

That's how actually Deep Sleep works. This state triggers the Reset pin when timer expires.
Yes, you will need loose variables if not stored, the algorithm just starts again.

If you want to save variables, just save it on a file (write/read).

Anudeep

Anudeep

5 months ago

Hi.. I tried same code with Esp8266-01 after displaying date and time it's going to deepsleep and but it's not restarting.....?

Bobby

Bobby

5 months ago

That's because ESP01 does not have (exposed) this GPIO16 - Deep Sleep to connect it to reset pin, in order to be triggered.
So, use ESP07 or 12 or similar.

Deleted account

Deleted account

3 months ago

I have a big problem with the ESP-12
I plug according to the diagram at 3.3v:
+3.3 Volts to Vcc
ground to ground
TxD on the board to RxD on the adapter (PL2303)
RxD on the board to TXD on the adapter (PL2303)
Vcc is CH_PD
GPI0 is GND
GPI15 is GND
And with Flash does not have a problem (Loading a just - nodemcu_float_0.9.6-dev_20150704.bin)
The problem appears in ESPlorer - I can not open a port and connect to upload any code 😦
It performs steps in sequence to power off the ESP-12
Connect Vcc is CH_PD (even though it was still connected in this way)
Disconnect GPI0 from GND and connect it to Vcc
(Or the GPI15 I did not do anything? And continue to be connected to the ground?)
PL2303 plug in a USB powering at this moment the ESP-12. In ESPlorer i want to open but nothing happens, and only rows of dots to display ...
What I am doing wrong and how to make the opening of the port with my ESP-12?? 😦

Similar projects you might like

ProjectsCommunitiesContestsLiveFree StoreBlogAdd projectSign up / Login