You might have noticed, we like the concept of Smart Homes, and physical devices you can control remotely from an API using your local Wifi network. Specifically, we’re talking about Energenie sockets, a brand of electrical sockets controlled by radio. We’ve introduced previously these sockets in posts like Control Energenie with ESP8266, Control energenie with Pebble or Raspberry Pi and Energenie but this time, we’re going to show you how we built the same Energenie radio controller with a NodeMCU web server.
NodeMCU
NodeMCU is an open source IoT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module. Source
The concept behind this is the same as our ESP8266 implementation. But, there are a few advantages of using NodeMCU instead.
- Easier development
- Lua scripting (easier than C++)
- Standard 5V microusb power input
- More stability (ESP8266 was constantly restarting (memory leak on C++?))
- Easier wiring (No need for reset button or PIN0 hack)
- More pins available than our previous ESP-01 module (this is ESP-12)
- Fully dedicated SDK (ESPlorer)
Lua examples on NodeMCU
Lua scripting is very simple and easy to learn. Similar to python at first, but without the alignment restriction; you use end
tags to mark the end of a statement. These are a few examples
LED blink
1 2 3 4 5 6 7 8 9 10 |
|
Web server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
More examples are available on their official website
Control radio energenie via web server
In this script we will combine the previous web server with a simple function to send radio signals.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
Again, as always, our code and all the details about this project are available on Github