SunLeaf to Cloud Communication: Connecting to Thingspeak

A project log for SunLeaf

A solar powered wireless picopower sensor module with cloud Datalogging and control geared towards plant and environmental monitoring

shane kirkbrideshane kirkbride 08/16/2016 at 14:350 Comments


This is a short log demonstrating how this is done with the SunLeaf module. We have end to end communication between the SunLeaf and the cloud. Right now this is a demonstration of feasibility in that this processor stack (ESP8266 and STMF446RE) can successfully post data to a cloud based server. We all know it will work in theory but it is always nice to prove things work in practice too. This is the purpose of this log.

Code algorithm

Below is an overview of what the code does. There are three high level tasks. First we initialize all the drivers and the SLIP protocol. Then we attach the callbacks. Lastly we put the STM into sleep mode. In sleep mode all power is cut to the sensors and the ESP is also put into sleep mode. When an interrupt is fired then it wakes up and preforms the data post. The programming interrupt will be an external pin change.

The STM code is here. We'll migrate it to Git shortly. .

This will work with the ESP-Link software as-is:

The SunLeaf ESP-Link fork is going to have quite a few changes but use this repo for now.

Data Output Overview

We have not yet connected the sensors and incorporated the sensor drivers. That will be for another post. The data we are uploading is very-psudo-random data generated by the STM not-so-random number generator. Right now we are simulating temperature, light and humidity data. After we build the Kalman filter then we'll upload the estimates as well. You can see the raw data and how not very random the STM number generator is. It is better than looking at the same value each post. Currently we post once per minute. In the future this will be pre-set to once every 10 mins and we will give the user the ability to change the frequency as needed.

Here is the output of the serial debug channel on the STM.

This output shows the state the ESP and the SLIP connection are in. It also shows if the wifi is connected and if the post is successful.

SunLeaf Thingspeak Channels

We will update this section as we create more channels. Later in the project life we'll migrate to a Viviaplanet cloud server but this shows proof of concept until that time.