Do you like this post? A regular project like the PlaneSpotter Color
takes many hours of my free time to develop and maintain. Would you offer me a beer for my hard work if I was your neighbour? Modern technology called teleportation makes it easy to send me a beer. Just click here
. Thank you!
A while ago a wanted to build one of those nightlights for my daughter that tell her when to sleep and when to call for the parents: an orange light behind a sun depicts the day, a blue light behind a moon the night. My first attempt was based on a Spark Core which is a bit pricy (~$40) to just connect to the internet to synchronise the time.
Playing with the ESP8266 I needed an actual project to use it and the nightlight came in handy. It uses both GPIO pins available on the ESP8266-ESP01 and calls google.com to synchronise the time every 30 minutes as soon as the device is connected to the access point. I currently still need an Arduino but just as power source and debugging tool. So the actual components are:
- plastic box (from food delivery)
- black paper as mask
- sun and moon downloaded and printed from the internet
- cardboard from a cereal box to shield the LEDs
- 2 LEDs (orange and blue)
- a mini bread board
- an ESP8266
- 2 resistors
- some jumper wires
Prepare the ESP8266
First you need to put the LUA firmware from nodemcu on the ESP8266. I described in this post
how it is done. Once this is done you can use the Esplorer
to transfer lua files to the ESP8266.
Check out the code and adapt it
Checkout the two lua files from here
and adapt them to your needs. Especially your access point and credentials need to be set in the init.lua file. If you’re not living in the GMT+1 timezone you’ll also need to adapt your offset in the nightlight.lua script. In the current version the day/night phases can only be set within the code, but this might change in the future. There is a lightweight webserver available for the lua firmware which might allow setting the time through a web browser.
Transfer the files to the ESP8266
The current version of the firmware crashes and restarts the unit if you try to call the dofile function for a non-existing file. Since the init.lua scripts calls the nightlight.lua script transfer them in the appropriate order (first nightlight, then init). Note: I had some cases where the module would connect to the AP and receive an IP but would further fail to call the google server to get the time. This only happened after clean updates of the firmware and disappeared after a short while.
Did you like this post? Consider supporting me with a virtual coffee or beer.