Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By edwin
#57343 Great project. Will be trying to add a thingspeak module, possibly a Twitter module.
Just a remark on the Transmitter library. That one is not really maintained anymore by the owner, but there is a fork that is maintained and adds some new features: https://github.com/yoh-there/RemoteSwitch.
In the examples there is even an esp8266 example.
Thanks for your great article
User avatar
By edwin
#57388 To add Thingspeak functionality do the following:
under the section: Emoncms configuration add:
Code: Select all//
// 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:
Code: Select allvoid  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: " + host + "\r\n" +
"Connection: close\r\n\r\n");
}

Ofcourse one still needs to setup a Thingspeak channel, but I trust it is well known how to do that.
Great series of articles from Krzysztof
User avatar
By krzychb
#57443 Hi @edwin,

Thank you nice review :D and update regarding newer Transmitter library.
I took a note to try it out.

Regarding sending the data to various cloud services I have prepared another article specifically on Emoncms, ThingSpeek and KeenIO including some perfromance benchmarking - https://github.com/krzychb/EspToCloud
User avatar
By edwin
#57478 Yes I had seen that Krzysztof, interesting article as well.
Just a remark, I understood from your writings that you thought one couldnt combine measurements in one graph in Thingspeak. However that is very well possible andeven dead simple, but maybe I misunderstood.
Thingspeak is actually pretty flexible: I noticed I made a mistake in my Thingspeak module. Where i write "Host: " + host + "\r\n" +
that ofcourse should be
"Host: " + thingspeakServer + "\r\n" +
because 'host' is the emoncms host.
nevertheless, even with that mistake it worked
Your Humidifier article really made me go a leap forward