[SOLVED] Thingspeak support

Hi,
Just would like to ask if when will be available the connection to Thingspeak using the API.

Thanks and congrats for the whole blynk project!

1 Like

We are partnering with ThingSpeak, but integration is planned for later.

Is it supported now? I am already using esp8266 with thingspeak to store the data but would I would like to see the data in nice ui provided by Blynk and control the board too.
Thanks

If you are using Blynk on Android - just use the History Graph Widget.

Any one has an example of using WiFi (i.e. ESP8266) to connect to Thingspeak server, while running Blynk as well? Many thanks…

Hi there,

really cool App. I tried it out with an Arduino and an ESP8266 modul. Everything works fine! :clap:

But now I want to connect my sonsors to Blynk as well to Thingspeak. For a continous connection to Blynk, I have to set a multiple connection (“AT+CIPMUX=1”) and connect to both server via different mux_id’s. Right?

The connection to Thingspeak was successful (mux_id1). But how can I connect to Blynk via mux_id2? is there a method like “Blynk.begin(mux_id, auth, wifi, ssid, password)” or something like this? I saw the respectiv funktions in the ESP8266.cpp, like “sATCIPSTARTMultiple” or “sATCIPSENDMultiple”. But do not find a way to tell Blynk to use a specific mux_id to connect!

Would be thankful for help!

I’m interested too to integrate ThingSpeak onto my sketch.
Now I’m trying to integrate TS but with no success, maybe the problem is in the Blynk.begin and ThingSpeak.begin… every constructor try to establish own connection and then interfere with other.
Maybe can be possible to create a connection with the arduino library (in my case WiFi.h) and the attach Blynk and ThingSpeak to this connection?
I mean… now is…

WiFi.begin(ssid, pass);
Blynk.begin(auth, ssid, pass, myBlynkServer, 8442); 

it’s possible to connect to Blynk server upon a existed WiFi connection like…

WiFi.begin(ssid, pass);
Blynk.begin(auth, myBlynkServer, 8442);

Blynk library don’t support multiple connection with esp8266, I’ve tried but don’t works, you must disconnect and reconnect for use more than one connection

i am running Blynk and Thingspeak in the same sketch.

but absolutely no idea how it works, i just know it does - i hacked at the code until it did~! pretty sure it reconnects whenever i send stat to thingspeak though…

this is my cut down code, but still some eccentricities in it… obviously took lots of the variable declarations out…

#define BLYNK_PRINT Serial //this is the debugging for Blynk
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

WiFiClient client;

const char* ssid = "XXX";
const char* password = "YYY";

const char* serverThingspeak = "api.thingspeak.com"; //this is the Thingspeak address
String apiKeyThingspeak1 = "ZZZ"; //Basement plenum control channel readings

char authBlynk[] = "WWW"; //insert token generated by Blynk

SimpleTimer timer;

void setup()
{
  Serial.begin(115200);
  Serial.println(F(""));
  Serial.println(F("BASEMENT VENTILATION PLENUM CONTROLLER - with Thingspeak & Blynk & Running Median & Email & Twitter"));
  Serial.print(F("File name: "));
  Serial.println(__FILE__);
  Serial.println();

  WiFi.begin(ssid, password);
  Serial.println(F("Where's some WiFi??"));
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }

  Serial.println(F(""));
  Serial.println(F("Found some WiFi!"));
  long rssi = WiFi.RSSI();
  Serial.print(F("WiFi signal strength (RSSI): "));
  Serial.print(rssi);
  Serial.println(F(" dBm"));
  Serial.println("");
  Serial.println(F("------------"));

  Blynk.begin(authBlynk, ssid, password);

  while (!Blynk.connect()) {
    // Wait until connected
  }

  timer.setInterval(2L * 60000L, dataLogging); // Setup the data logging function to be called every 120 seconds (2 mins)
  timer.setInterval(10L * 60000L, tweetUptime); // Setup Twitter uptime function to be called every 600 seconds (10 minutes)

}

void dataLogging()

{
  Serial.println(F("Starting data logging function (Blynk then Thingspeak)"));

  long rssi = WiFi.RSSI();
  Blynk.virtualWrite(V0, rssi); // this sends the WiFi Signal Strenght to Blynk

  long uptime = millis() / 60000;
  Blynk.virtualWrite(V20, uptime); // this sends the program uptime to Blynk

  Serial.println(F("Sending to Blynk - BASEMENT readings"));
  Blynk.virtualWrite(V4, baseHum ); // this sends the reading to the Blynk virtual pin
  Serial.print(baseHum);
  Serial.println("%");
  Blynk.virtualWrite(V5, baseTemp); // this sends the reading to the Blynk virtual pin
  Serial.print(baseTemp);
  Serial.println("'C");
  Blynk.virtualWrite(V6, baseDewPoint); // this sends the calculation to the Blynk virtual pin
  Serial.print(baseDewPoint);
  Serial.println("'C");
  Blynk.virtualWrite(V19, medianBaseDewPoint); // this sends the calculation to the Blynk virtual pin
  Serial.print(F("Basement Dew Point (median):"));
  Serial.print(medianBaseDewPoint);
  Serial.println("'C");

  Serial.println(F("Just finished the data logging Blynk section"));

  Serial.println(F("Preparing Thingspeak readings"));

  if (client.connect(serverThingspeak, 80))
  {
    String postStr = apiKeyThingspeak1;
    postStr += "&field1=";
    postStr += String(roofTemp);
    postStr += "&field2=";
    postStr += String(roofHum);
    postStr += "&field3=";
    postStr += String(roofDewPoint);
    postStr += "&field4=";
    postStr += String(houseTemp);
    postStr += "&field5=";
    postStr += String(houseHum);
    postStr += "&field6=";
    postStr += String(houseDewPoint);
    postStr += "&field7=";
    postStr += String(medianRoofDewPoint);
    postStr += "&field8=";
    postStr += String(medianHouseDewPoint);
    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: " + apiKeyThingspeak1 + "\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 ID: ABDC"));
  }
}

void tweetUptime()
{
  long uptime = millis() / 60000L;
  BLYNK_LOG("Tweeting every 10 minutes ;)");
  Blynk.tweet(String("Basement Controller running for ") + uptime + " minutes.");
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates SimpleTimer
}
3 Likes

I’m trying with a WiFi Genuino/Arduino shield, not the ESP8266.

I’m on the same your way… I wanna try out your solution! thanks!

No luck!
I’m not able to use both Blynk and ThungSpeak.
When is planned to integrate ThingSpeak?

this is not very useful for us to help you…

what are you trying to do?

I’m trying to send data to ThingSpeak (while using Blynk)… I’ve tryed with the ThingSpeak library (Arduino) but the sketch reset every way try to upload data, so I’ve tryed to post data with WiFi client but the connectrion to Blynk server is resetted every way try ti post to ThyngSpeak.

This is my sketch…
#define BLYNK_NO_INFO
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi.h>
#include <BlynkSimpleWifi.h>

int status = WL_IDLE_STATUS;

WiFiServer server(80);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "43g32g623g623g6g2356g32g";

// Your WiFi credentials
char ssid[] = "2v45gf4gf46fg23gyf536f";
char pass[] = "4b245g346g234g6f236gr";    

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "b46g32g632g523g52g";             // enter your channel's Write API Key
const int updateThingSpeakInterval = 20 * 1000; // 20 second interval at which to update ThingSpeak

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;

// Initialize Arduino Ethernet Client
WiFiClient client;

void setup()
{
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "cloud.blynk.cc", 8442);
  //Blynk.begin(auth, ssid, pass, server_ip, port);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

  Blynk.config(auth, IPAddress(192,168,1,110),4882);
  
}

void loop()
{
  // read values from pins and store as strings


  String light = String(analogRead(A0), DEC); // read light value

  // find temp value
  float voltage = analogRead(A1) * (3.3 / 1024);  // convert 0-1023 range to 3.3V range
  int tempVal = (voltage - 0.5) * 100;            // convert voltage to temperature in *C
  String temp = String(tempVal);

  // Print Update Response to Serial Monitor
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected) {
    Serial.println("...disconnected");
    Serial.println();
    client.stop();
  }
  // Update ThingSpeak
  if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
    updateThingSpeak("field1=" + light + "&field2=" + temp);
    Serial.println(light);
    Serial.println(temp);

  }
  lastConnected = client.connected();
    
  Blynk.run();
}

void updateThingSpeak(String tsData) {
  if (client.connect(thingSpeakAddress, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    lastConnectionTime = millis();

    if (client.connected()) {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
    }
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

… and this the terminal of the running sketch…

Attempting to connect to SSID: FRITZ!Box Fon WLAN 7390
SSID: FRITZ!Box Fon WLAN 7390
IP Address: 192.168.1.152
signal strength (RSSI):-23 dBm
[28478] Blynk v0.3.3
Connecting to ThingSpeak...

1023
134
[29761] Connecting to 192.168.1.110:4882
H...disconnected

[39782] Connecting to 192.168.1.110:4882
Connecting to ThingSpeak...

1023
279
[49930] Connecting to 192.168.1.110:4882

so what does it show at your Thingspeak page?

ThingSpeak add data normally, but I lost the connection to Blynk server, so if I increase the data rate the Blynk service are unusable.

so thingspeak data update works?

then which bit of blynk doesn’t work?

Maybe I’m writing in bad english… so sorry for this… it seems I cannot explain.
All works… but all works in a “unstable” way.
As you wrote on your post [quote=“Dave 1829, post:9, topic:379”]
pretty sure it reconnects whenever i send stat to thingspeak though…
[/quote] … if I upload data to ThingSpeak every seconds, this mean that I have one disconnection and one reconnection in one seconds, so… in this piece of time Blynk cannot work; so this is equivalent to not have Blynk at all. In the same way if I upload to ThingSpeak every 3 seconds, this time is too small to fit disconnection + upload to TS + reconnection to send/receive data to Blynk.
Isn’t a “elegant” solution for me.
So I’ve asked when it’s possible to have a true implementation of ThingSpeak on Blynk; I’ve seen on some post that this are on the roadmap.
For the moment, to bypass the problem I preferred to put a cheaper ESP8266 in I2C handshake with the “main hardware” (Arduino Mega + WiFi shield) that are only charged to send to ThingSpeak until the main hardware are occupied to manage Blynk and all the other services.
In every way, thanks for your time.

well, i guess it works fine for me as i only update Thingspeak every 120 seconds, not every second…

sorry for your troubles…

The ugly alternative: One ESP for Blynk and another for ThingSpeak! Somehow they both connect to the same DS18B20 without issue. Have not tested with anything else. Think this setup costs an extra $3 (ESP-01 + HLK-PM01)!

2 Likes