ESP8266 with webserver-MQTT-Emoncms-Thingspeak-OTA

The graph shows that  when in automode, the humidifier is switched on when the  humidity  goes  2 degrees (the hysteresis) under the Setpoint
The graph shows that when in automode, the humidifier is switched on when the humidity goes 2 degrees (the hysteresis) under the Setpoint

On Github, Krzysztof has published a truly excellent series of articles regarding the use of an ESP8266 that reads a humidity sensor and publishes the data on a personal webserver, as well as on emoncms (an energymonitoring cloud) and allows to  take action depending on the reading of the  sensor, either manually or automatically and to do that via a webserver, or via MQTT or OpenHAB.
Anyone who is interested in this subject should surely read his  set of articles that starts basically from scratch and keeps adding functionality.

As I am not really partial to emoncms, but more of a Thingspeak user, I decided to add a Thingspeak module to his program.
As a base I used this program.
To add Thingspeak functionality do the following:
under the section: Emoncms configuration add:

//
// Thingspeak configuration
//
const char* thingspeakServer = "api.thingspeak.com";
const char* writeAPIKey = "yourThingspeakWriteApi";
// function prototypes required by Arduino IDE 1.6.7
void  sendDataToThingspeak(void);

in the main loop (thus in void loop(void) )
above (or below) sendDataToEmoncms();
add: sendDataToThingspeak();

Add a tab called “Thingspeak” and add there the following:

void  sendDataToThingspeak(void)
{
// make TCP connections
WiFiClient client;//this one is probably not necessary
const int httpPort = 80;
if (!client.connect(thingspeakServer, httpPort)) {
return;
}

String url = "/update?key=";
url += writeAPIKey;
url += "&field1=";
url += String(humidity);
url += "&field2=";
url += String(humiditySetPoint );
url += "&field3=";
url += String(humidifier);
url += "&field4=";
url += String(autoMode);

url += "\r\n";

// Send request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + thingspeakServer + "\r\n" +
"Connection: close\r\n\r\n");
}

Ofcourse one still needs to setup a Thingspeak account, but that is well known how I presume. One also needs to setup an Emoncms account, buthat is well described in the series of articles, or one can decide to delete that functionality.
For MQTT I have used a public broker, but one can decide to set it up on say a Raspberry Pi

Advertisements