Tutorial: Part 5 – The Software – IOT ESP32 Solar Powered WiFi Night Light
Using the REST Software
Here is your chance to build a solar powered WiFi remote control ESP32 based nightlight for use outdoors. The full Solar Powered Nightlight kit comes with mounting pylons and a water proof enclosure.
This is a great beginners Kit!
This is an easy to build kit with no soldering required.
The Solar Powered Night Light is WiFi controllable using the REST interface built into the software. For example:
Sending the command inn a browser (of course, using your IP# for your Solar Night Light):
https://192.168.1.154/
you will get (assuming you have the right IP Address)
{"variables": {"solarVoltage": 1.52, "batteryVoltage": 4.14, "solarCurrent": 0.00, "batteryCurrent": 2.40, "loadCurrent": 1.20, "loadVoltage": 4.97, "currentLEDMode": 0, "darkLight": 0, "Version": "005"}, "id": "", "name": "SDL_ESP32_BC24_SOLARNL", "hardware": "esp32", "connected": true}
Look at all that information! Data! This tells us a lot about the solar power system and what is going on with the system! Not only it is cool to look at, it makes a great science project too.
This is a five part tutorial series:
- - Part 1 - What is the Ultimate Solar Power WiFi NightLight?
- - Part 2 - Parts List for the Night Light
- - Part 3 - Step by Step Assembly
- - Part 4 - Putting it in the Box
- - Part 5 - the Software and REST Interface for the Night Light
The Kit contains the powerful ESP32 dual core processor mounted on the BC24 24 RGBW Programmable LED board with Grove Connectors! No Soldering!
You can see and buy the entire kit here.
Usually, the first step to using the BC24 SOLARNL software is to setup your WiFi connection.
Setting Up Your WiFi
WiFi Connection Sequence – Provisioning
The BC24 Night Light has three methods for getting an IP from your Wireless Access Point. These are:
- – SmartConfig
- – WPS Button on AP
- – Local AP on ESP32 (192.168.4.1)
Note: This was developed for the BC24 ESP32 Based 24 RGBW Pixel LED Board
SmartConfig
This method uses the TI method of provisioning “SmartConfig” was invented by TI. You can refer to it here:
https://community.particle.io/t/smart-config-the-missing-manual-now-available/442
In order to do SmartConfig, you need a smartphone or tablet (Android or iOS) that connected to WiFi network (which you want ESP32 to connect to) and installed a special application. On this application, you just supply the ssid and password of WiFi network so that the application can use, encode them and then broadcast (via UDP) encoded ssid and password (under packet format) over the air. When this software is being run, the ESP32 (with the SmartConfig software loaded) will capture these packets, decode back ssid and password and use them to connect to Wifi network.
After connecting to WiFi, the ESP32 will use mDNS to multicast a message to the application to notify that it has successfully connected to WiFi.
The source code of special application is supplied by Espressif. You can download at:
https://github.com/EspressifApp/EsptouchForAndroid
https://github.com/EspressifApp/EsptouchForIOS
This application is also available on App Store. You can use it to test SmartConfig feature.
- For Android, this application is available under name “IOT_Espressif” or another application “ESP8266 SmartConfig” (this is for ESP8266 but you can use it for ESP32):
https://play.google.com/store/apps/details?id=com.cmmakerclub.iot.esptouch
https://play.google.com/store/apps/details?id=com.espressif.iot
– For iOS, this application is available under name “Espressif Esptouch”:
https://itunes.apple.com/us/app/espressif-esptouch/id1071176700?mt=8
There is also another app on the iOS Appstore, search on “SmartConfig”
Color sequence
Default Time: 15 seconds to hit Smart Config on app, 30 seconds timeout on response
– Three White Lights
– Three Red on failure
– Three Green on success
WPS Button on AP
Wi-Fi Protected Setup (WPS; originally, Wi-Fi Simple Config) is a network security standard to create a secure wireless home network.
Introduced in 2006, the goal of the protocol is to allow home users who know little of wireless security and may be intimidated by the available security options to set up Wi-Fi Protected Access, as well as making it easy to add new devices to an existing network without entering long passphrases.
This library will wait 60 seconds (in the example) for the WPS packets to be recieved by the ESP32.
A major security flaw was revealed in December 2011 that affects wireless routers with the WPS PIN feature, which most recent models have enabled by default.
This software does not use the PIN feature.
Color sequence
Default Time: 30 seconds timeout if no WPS button sent from AP
– Three White Lights
– Two White Lights during search
– Two Red Lights on failure
- Two Green on success
Local AP (192.168.4.1)
For the third provisioning method, the ESP32 is set up as an access point (192.168.4.1) – look at your list of WiFi APs on your computer when it is running. A small web server is started that will allow you to select the AP that you want the ESP32 to connect to and then you can enter the password for the access point. It runs for 60 seconds by default.
Color sequence
Default Time: 60 seconds timeout if No completed Webform returned
– One Blink of single White Light
– One Blinking White Light during AP page active
– One Red Light on failure
– One Green on success
Remember that all of these features may fail and have to be repeated. Nature of the beast.
Once Connected
Once the WiFi Connection has been made, the BC24 Solar Night Light software will blink Green.
The BC24 remembers your last connection.
Resetting the BC24 Solar Night Light to Default Values
To reset the BC24, hold down the mode button while hitting the reset button. This will clear the WiFi credentials as well as reset other values to default values.
Using the REST Interface for your BC24 Solar Night Light
The BC24 Solar Powered Night Light contains a fully functional REST interface for control and reporting information.
Finding your IP Number
Use an IP Scanning program (Angry IP Scanner for Mac or Windows) and look for a new IP Address. You can switch your unit on and off if you aren’t sure which IP Number it is.
That will be your IP address. You can also check your AP Access Point (Router) for the address (under something like attached devices – it depends on your router. Check the manual).
Some routers won’t report new IP devices immediately. Power cycle your router to force the detection.
Write down your IP #. It will probably not change very often depending on your router.
We will use the IP# above, but yours will definitely vary from this #.
Note: If the BC24 is not powered up (battery too low or such), then the REST interface will not respond.
Your First REST Command
Open a browser (Safari or Chrome has been tested) and type:
you will get (assuming you have the right IP Address)
{"variables": {"solarVoltage": 1.52, "batteryVoltage": 4.14, "solarCurrent": 0.00, "batteryCurrent": 2.40, "loadCurrent": 1.20, "loadVoltage": 4.97, "currentLEDMode": 0, "darkLight": 0, "Version": "005"}, "id": "", "name": "SDL_ESP32_BC24_SOLARNL", "hardware": "esp32", "connected": true}
You are connected!
All of the BC24 Solar Power Night Light commends return fully formatted JSON data which makes it easy to parse and get the values you want.
The REST Commands
Variables
To retrieve the value of a specific variable, type:
https://192.168.1.154/solarVoltage
where “solarVoltage” is the variable name. Case matters.
for example:
https://192.168.1.154/solarVoltage
returns:
{"solarVoltage": 1.58, "id": "", "name": "SDL_ESP32_BC24_SOLARNL", "hardware": "esp32", "connected": true}
returns current Solar Panel Voltage in Volts
BC24 Solar Powered Night Light REST Variables | |
solarVoltage | Solar Panel Voltage in Volts |
batteryVoltage | Battery Voltage in Volts |
solarCurrent | Solar Panel Current in mA |
batteryCurrent | Battery Current in mA |
loadCurrent | Load (BC24) Current in mA |
loadVoltage | Load (BC24) Voltage in mA |
currentLEDMode | Numeric Value of current LED Mode for the BC24 (see below) |
darkLight | State of the darkLight Variable – 0 for dark, 1 for light. Only affects Clock brightness in V004 |
Version | Returns the version of the software, formatted as “VXXX” (V004 for example) |
SolarNL LED Modes
As of V005, here are the numeric constants for the currentLEDMode value
RAINBOW 0
FIRE 1
CLOCK 2
Default Administration Password
The default password is “admin”. You can change this with the “setAdminPassword Below
Functions
Functions are called with Parameters in the following form, for example (where the admin password is “admin”:
https://192.168.1.154/clock?params=admin
and it returns
{"return_value": 1, "id": "~f", "name": "SDL_ESP32_BC24_SOLARNL", "hardware": "esp32", "connected": true}
REST Commands | |||
Function | Desc | Parameters | Returns |
setAdminPassword | reset Administration Password | https://192.168.1.118/setAdminPassword?params=oldpassword,newpassword
Parameters are old and new password, separated by a “,” |
return_value will be 1 if the command succeeded and 0 if it did not (such as invalid password) |
clock | Sets the mode for the BC24 Clock Display. | https://192.168.1.154/clock?params=adminpassword | return_value is 1 if it succeeds or 0 if the password fails. |
rainbow | Sets the mode for the BC24 Rainbow Display. | https://192.168.1.154/rainbow?params=adminpassword | return_value is 1 if it succeeds or 0 if the password fails. |
fire | Sets the mode for the BC24 Fire Display. | https://192.168.1.154/fire?params=adminpassword | return_value is 1 if it succeeds or 0 if the password fails. |
setDarkLight | Sets the BC24 LEDs Darker (0) or Brighter (1) | https://192.168.1.154/setDarkLight?params=adminpassword, mode
First Parameter is administration password. Second parameter is “0” or “1” As of V005, only affects Clock Brightness |
return_value is 1 if it succeeds or 0 if the password fails. |
setClockTimeOffsetToUTC | Sets Time Offset to seconds from UTC. For example, Pacific Standard Time is -25200 | https://192.168.1.154/setClockTimeOffsetToUTC?params=adminpassword, offset
Parameter is administration password |
return_value is 1 if it succeeds or 0 if the password fails. |
setTurnOn | Overrides the check for Solar Panel Voltage < 2.0V | https://192.168.1.154/setTurnOn?params=adminpassword, mode
Parameter is administration password |
return_value is 1 if it succeeds or 0 if the password fails. |
led | Sets the LED Connected on the BC24 to On (“0”) or Off (“1”) Note – V005 will also blink this LED when the ESP32 is running | https://192.168.1.154/led?params=1 | Return value is 1. Values other than 0 and 1 have no effect. |
How to Program Your BC24 Solar Night Light
The BC24 ESP32 comes programmed with the released version of the software when the BC24 boards are programmed.
Download the Arduino IDE 1.8.5 (or higher) to start from arduino.cc
Installation of the IDE
See the Tutorial on:
Download The Software
Download and Install the software below in your Arduino IDE. If you don’t know how to do this read one of the many tutorials on how to copy sketches into the Arduino IDE for your machine type.
https://github.com/switchdoclabs/SDL_ESP32_BC24_SOLARNL