A solar-powered ESP8266 WiFi module joins the IoT

Lead Image © Oleksiy Tsupe, 123RF.com

A Place in the Sun

We take an inexpensive ESP8266 WiFi/processor combination and turn it into a solar-powered device.

In the previous issue's SwitchDoc Labs column [1], I looked at the ESP8266 [2] microcontroller plus WiFi front end and three types of firmware, along with the advantages and disadvantages of each. In particular, I looked at the Adafruit Huzzah ESP8266 WiFi/CPU [3], which I also use for the project in this issue.

In the beginning, I wanted to build two ESP8266 devices to test sun-tracking solar panel efficiencies. Rather quickly, I found I was consumed with learning about the ESP8266, setting up a REST interface, and indulging in a little bit of 3D printing, so I'll have to wait until the next issue to look at sun tracking with the units. Therefore, the unit I am creating here is really just the basis for an IoT device, because all I am doing is focusing on the solar power aspects of the project in this column.

ESP8266

To review, the main features of the Huzzah ESP8266 chip include:

  • Secure digital input/output (SDIO) 2.0, serial peripheral interface (SPI), universal asynchronous receiver/transmitter (UART), inter-integrated circuit (I2C)
  • Integrated radio frequency (RF) switch, digitally-compensated crystal oscillator (DCXO), power management unit (PMU)
  • Integrated RISC processor, on-chip memory, and external memory interfaces
  • Integrated MAC/baseband processors
  • Integrated interchip sound (I2S) interface for high-fidelity audio applications
  • Fully integrated WiFi solution

Additionally, I will use the Arduino IDE, which is a well-used, proven path to compiling code for small computers using C/C++, with hundreds of libraries for all sorts of purposes. Arduino IDE compatibility has dramatically expanded the possibilities for using the ESP8266 in IoT applications that need web and Internet connectivity. Before continuing, refer to the Adafruit tutorial [4] for instructions on using the ESP8266 with the Arduino IDE.

Solar-Powered ESP8266

The purpose of this project is fivefold:

  1. Demonstrate ESP8266 on solar power.
  2. Measure EPS8266 power consumption dynamically.
  3. Show how to use a REST interface to send data to a database on a Raspberry Pi.
  4. Display the data from the Rasp Pi on graphs using MatPlotLib.
  5. Add a stepper motor to the solar panel to track the sun and measure the results compared with not tracking (next project).

For this series, I use an IoT device designed by SwitchDoc Labs that is based on the ESP8266 WiFi/processor connected to a SunAirPlus solar power system [5]. The "SolarPowerESP8266" is an IoT base system that I will be using in several applications. It consists of five major pieces (Table 1; Figure 1):

Table 1

Parts List

Part

Description

Source

Price

Link

ESP8266

ESP8266 Huzzah Breakout board

Adafruit

~$10

https://www.adafruit.com/products/2471

SunAirPlus

Solar power controller/charger/data collector

SwitchDoc Labs

~$45

http://www.switchdoc.com/?p=1332

LiPo battery, 6,500mAh (can use smaller)

Rechargeable LiPo battery (can use lower capacity)

Adafruit

~$30

https://www.adafruit.com/products/353

FTDI cable

Cable for programming from PC or Mac

SwitchDoc Labs

~$11

http://www.switchdoc.com/?p=2868

6V 3.5W solar panel

Solar panel to connect to SunAirPlus

Voltaics Systems

~$39

http://www.voltaicsystems.com/3-5-watt-panel

Figure 1: Project parts, clockwise from left: solar panel, SunAirPlus, Huzzah ESP8266, rechargeable LiPo battery pack. Not shown, Raspberry Pi.
  • Adafruit Huzzah ESP8266 WiFi/CPU (programmed with the Arduino IDE)
  • SunAirPlus solar power controller/charger data collector
  • LiPo battery
  • 6V, 3.4W solar panel
  • Raspberry Pi for data logging/analytics/display

The system works as follows (Figure 2): SunAirPlus is hooked up to a solar panel and a LiPo battery. SunAirPlus handles all the complexities of properly charging and discharging a LiPo battery. It also supplies 5V to the ESP8266.

Figure 2: Block diagram of solar-powered ESP8266.

SunAirPlus also contains an INA3221 three-channel current and voltage sensor. It reads current and voltage from the battery and the solar panel and the voltage and current going to the load (the ESP8266), allowing you to see exactly what is going on in your solar panel system. The more data the better.

The ESP8266 is connected to the 5V power supply from the SunAirPlus (SunAirPlus is smart enough to take power from whatever is hooked to it – from either the battery, the USB power connector, or the solar panel) and to the I2C bus on SunAirPlus. SunAirPlus handles the translation from the 3.3V I2C bus of the ESP8266 to the internal 5V I2C bus of the SunAirPlus.

The software on the ESP8266 periodically (every second) stores the values in a circular buffer. If the server doesn't retrieve the data, the buffer just loops around and starts overwriting the oldest data with the most current data. The ESP8266 sets up a web server on port 80 and implements a REST interface. When a web browser addresses the ESP8266, the web server (http://192.168.1.129 on my local network – your number will be different) sends a JSON-formatted string [6] back to the browser (or a computer like the Raspberry Pi). The ESP8266 software also prints information to the serial interface if you have the FTDI cable [7] connected.

Listing 1 shows the printout as the ESP8266 starts up, connects to the local network, and then begins sampling data from SunAirPlus. When the ESP8266 is queried by a web browser (or a computer), Listing 2 shows what is printed on the serial port.

Listing 1

ESP8266 Output at Startup

----------------
SolarPower ESP8266
----------------
Connec.......
Local WiFi connected, IP address: 192.168.1.129
Server started
Free heap on ESP8266:33080
--------SAP Data-------
LIPO_Battery Bus Voltage: 4.06 V
LIPO_Battery Load Voltage: 4.07 V
LIPO_Battery Current: 113.20 mA
Solar Cell Bus Voltage: 3.63 V
Solar Cell Load Voltage: 3.63 V
Solar Cell Current: 0.00 mA
Output Bus Bus Voltage: 4.98 V
Output Bus Load Voltage: 4.99 V
Output Bus Current: 92.00 mA
--------
Free heap on ESP8266:33080
--------SAP Data-------
LIPO_Battery Bus Voltage: 4.06 V
LIPO_Battery Load Voltage: 4.07 V
LIPO_Battery Current: 114.80 mA
Solar Cell Bus Voltage: 3.62 V
Solar Cell Load Voltage: 3.62 V
Solar Cell Current: 0.00 mA
Output Bus Bus Voltage: 4.98 V
Output Bus Load Voltage: 4.99 V
Output Bus Current: 88.80 mA
--------

 

Listing 2

ESP8266 Output to the Serial Port

--------
Buffer Count=9
Request received
GET /
RestDataString HTTP/
Sending command
Command: s
State: x
State of buffer at the start:
Added to buffer: RestDataString
Added to buffer: 32696 | 32523,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,104.00 | \
  33538,4.05,4.06,132.40,3.62,3.62,0.00,4.98,4.99,102.00 | 34554,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,102.40 | \
  35570,4.05,4.06,131.60,3.62,3.62,0.00,4.98,4.99,102.40 | 36586,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,102.40 | \
  37602,4.05,4.06,131.60,3.62,3.62,0.00,4.98,4.99,110.00 | 38618,4.05,4.06,133.20,3.62,3.62,0.00,4.98,4.99,102.00 | \
  39634,4.05,4.06,132.00,3.62,3.62,0.00,4.98,4.99,102.00 | 40650,4.05,4.06,130.80,3.62,3.62,0.00,4.98,4.99,102.00
Added to buffer: 1
Added to buffer: SolarPowerESP8266
State of buffer at the end: HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS
Content-Type: application/json
Connection: close
{"RestDataString": "32696 | \
  32523,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,104.00 | 33538,4.05,4.06,132.40,3.62,3.62,0.00,4.98,4.99,102.00 | \
  34554,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,102.40 | 35570,4.05,4.06,131.60,3.62,3.62,0.00,4.98,4.99,102.40 | \
  36586,4.05,4.06,131.20,3.62,3.62,0.00,4.98,4.99,102.40 | 37602,4.05,4.06,131.60,3.62,3.62,0.00,4.98,4.99,110.00 | \
  38618,4.05,4.06,133.20,3.62,3.62,0.00,4.98,4.99,102.00 | 39634,4.05,4.06,132.00,3.62,3.62,0.00,4.98,4.99,102.00 | \
  40650,4.05,4.06,130.80,3.62,3.62,0.00,4.98,4.99,102.00", "id": "1", "name": "SolarPowerESP8266", "connected": true}

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content