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
Great tip, thank you. If your want to use emoncms, be aware that the JSON string krzychb assembles is incorrect; it does not adhere to json standards. Formal JSON requires the keyword to also be enclosed in quotes. Some parsers are easy on this and it seems emoncms uses such parser.
Thanks Jeroen. I am not really partial to Emoncms, it is mainly focussed on Energy monitoring, hence my addition of Thingspeak, but useful to know your correction.
Just for completeness sake I will see if I can add a Twitter module as well, not because I need it, but because I can 🙂
All in all though Krzysztof wrote a great educational piece.
Hi Jeroen,
Thank you for pointing out the issue with JSON.
Format provided in Emoncms API documentation looks like below:
https://emoncms.org/input/post.json?json=power:200
I will add a note in my repository that it may not work elsewhere, as it does not conform the standard.
Krzysztof
Thanks for the feedback Krzysztof
I also tried to connect a DHT 11 to a NodeMCU but that didn’t work with the standard DHT library from ADA fruit.
Had to adjust the library file and copy some other library files to compile without any errors..
Indeed. Although the error is described somewhere on the Adafruit forum, as far as I know it still is in the library
Tom I reasise my reply must have been cryptic. I presumed you were talking about a problem with the adafruit library and the dht sensor that Idescribed elsewhere. I wasnt aware of a compilation error, but i am happy you had it solved
http://www.electromanaweb.wordpress.com