[SOLVED] Thingspeak support

It’s really weird, my esp8266 updates thingspeak perfectly, but now trying it on my Ethernet project it is not working perfectly…

That is strange… I’ve just started playing with it. I have an Uno Ethernet shield and ENC28J60… I’m not actively working with them at the moment but if I find anything interesting I’ll be sure to share.

OK, my bad, i had it working on ESP8266 with the code i posted above, but it did NOT have the client.stop() command in it.

once i re-added that, it is working fine on Arduino Mega and updates FOUR channels with 32 different variables all in the one function:

void setup()
  timer.setInterval(180000L, dataLoggingThingspeak); // starts the Thingspeak upload every 180 seconds (3 minutes)
const char* serverThingspeak = "api.thingspeak.com"; //this is the Thingspeak address

String upstairsPlenumCh1APIKey = "zxc";
String upstairsPlenumCh2APIKey = "xcv";
String upstairsPlenumCh3APIKey = "cvb";
String upstairsPlenumCh4APIKey = "vbn";

void dataLoggingThingspeak()
{ //sends the variables to Thingspeak
  Serial.println(F("Starting data logging function (Thingspeak)"));
  Serial.println(F("Preparing Thingspeak Ch1 readings"));

  if (client.connect(serverThingspeak, 80))
  {
    String postStr = upstairsPlenumCh1APIKey;
    postStr += "&field1=";
    postStr += String(medianRoofTemp);
    postStr += "&field2=";
    postStr += String(roofVapourPres);
    postStr += "&field3=";
    postStr += String(medianHouseTemp);
    postStr += "&field4=";
    postStr += String(houseVapourPres);
    postStr += "&field5=";
    postStr += String(medianExternTemp);
    postStr += "&field6=";
    postStr += String(externVapourPres);
    postStr += "&field7=";
    postStr += String(medianLivingTemp);
    postStr += "&field8=";
    postStr += String(livingVapourPres);
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + upstairsPlenumCh1APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(F("Just uploaded to Thingspeak Channel Ch1 ID: 12345"));
  }
  
  client.stop();
  delay(5);

  if (client.connect(serverThingspeak, 80))
  {
    String postStr = upstairsPlenumCh2APIKey;
    postStr += "&field1=";
    postStr += String(medianBed1Temp);
    postStr += "&field2=";
    postStr += String(bed1VapourPres);
    postStr += "&field3=";
    postStr += String(medianBed2Temp);
    postStr += "&field4=";
    postStr += String(bed2VapourPres);
    postStr += "&field5=";
    postStr += String(roofDewPoint);
    postStr += "&field6=";
    postStr += String(houseDewPoint);
    postStr += "&field7=";
    postStr += String(externDewPoint);
    postStr += "&field8=";
    postStr += String(livingDewPoint);
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + upstairsPlenumCh2APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(F("Just uploaded to Thingspeak Channel Ch2 ID: 23456"));
  }

  client.stop();
  delay(5);

  if (client.connect(serverThingspeak, 80))
  {
    String postStr = upstairsPlenumCh3APIKey;
    postStr += "&field1=";
    postStr += String(bed1DewPoint);
    postStr += "&field2=";
    postStr += String(bed2DewPoint);
    postStr += "&field3=";
    postStr += String(setTarget);
    postStr += "&field4=";
    postStr += String(setCooling);
    postStr += "&field5=";
    postStr += String(setWarming);
    postStr += "&field6=";
    postStr += String(setShutOffFunction);
    postStr += "&field7=";
    postStr += String(setLivingOutlet);
    postStr += "&field8=";
    postStr += String(setBedsOutlet);
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + upstairsPlenumCh3APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(F("Just uploaded to Thingspeak Channel Ch3 ID: 34567"));
  }
  client.stop();

  delay(5);

  if (client.connect(serverThingspeak, 80))
  {
    String postStr = upstairsPlenumCh4APIKey;
    postStr += "&field1=";
    postStr += String(closeLivingOutlet);
    postStr += "&field2=";
    postStr += String(closeBedroomsOutlet);
    postStr += "&field3=";
    postStr += String(setToiletOff);
    postStr += "&field4=";
    postStr += String(upstairsPlenumSmoke);
    postStr += "&field5=";
    postStr += String(upstairsPlenumCO2);
    postStr += "&field6=";
    postStr += String(basementPlenumSmoke);
    postStr += "&field7=";
    postStr += String(basementPlenumCO2);
    //postStr += "&field8=";
    // postStr += String(spare);
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + upstairsPlenumCh4APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(F("Just uploaded to Thingspeak Channel Ch4 ID: 45678"));
    Serial.println(F("Just finished the Thingspeak data logging function"));
    client.stop();
    BLYNK_LOG("Finished Thingspeak dataLogging function");

  }
}

i will probably take the delays out too…

Yes, is the same thing I’ve made!

What does Thingspeak support mean? Is it really integrated?
You can do an Arduino program that uploads data to Thingspeak and to Blynk as unconnected clouds.
But is there a Widget that reads the data from Thingspeak?
Can you configure a History Graph to display the data of a Thingspeak channel?

You can use webhook to push data to thingspeak in parallel. There is no way to read data from thingspeak into Blynk app.

Thanks, so the idea is to write the data to Blynk and then from the Blynk App display it in a History Graph and use a Webhook in the app to write it to Thingspeak, correct?
This simplifies/reduces the coding in the Arduino.

Exactly.

I must be doing something wrong because I don’t manage to update the ThingSpeak channel with a WebHook.

The configuration that I have used in the WebHook widget is:

Output: V8
URL: https://api.thingspeak.com/update/api_key=4H8QPQ4xxxxL5H08&field1=/V8/
Method: GET
Content Type: application/json
Body: empty

and of course in the sketch I have:
Blynk.virtualWrite(V8, t);

updating every 10 seconds.

But the ThingSpeak channel is not receiving any data and its graph is not updating.

Any hint would be welcome!

Should be

as webhook is already assigned to pin

Thanks, I changed it to:
Output: V8
URL: https://api.thingspeak.com/update/api_key=4H8QPQ4xxxxL5H08&field1=/pin/
Method: GET
Content Type: application/json
Body: empty

But still not working…

Does that works in browser?

Found it!

The issue was a ? instead of a / in the URL string
It must be:
URL: https://api.thingspeak.com/update?api_key=4H8QPQ4xxxxL5H08&field1=/pin/
instead of:
URL: https://api.thingspeak.com/update/api_key=4H8QPQ4xxxxL5H08&field1=/pin/

Following your hint I found this useful video for a novice like me: https://www.youtube.com/watch?v=Mz2sUhqZWgo

Thanks for your help!

1 Like

Dave,

Would you show me what you did for setting up your variables? I want to do the same setup, but I get no data from the sensor. Would you mind sharing your whole code (minus the keys of course) so I can see how the whole thing worked?

Thanks for any help,

Tom

i used normal procedures.

if you get no data from your sensor, then you have done something wrong with your sensor, not Thingspeak.