BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Number of entries increase on Thingspeak but the values aren’t being displayed on the graphs


#1

Hi,
I am having a problem similar to this. The sensor readings are being sent to Blynk over bluetooth and are updating every 15 seconds. I’m trying to use the webhook to update thingspeak every 30 seconds. The number of entries increase on Thingspeak as I want but the values aren’t being displayed on the graphs.
This is the code I have and how I’ve set up the webhook:

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void setup()
{
  // Debug console
  Serial.begin(9600);
  SerialBLE.begin(9600);

  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  dht.begin();

  // Setup a function to be called every 5 second
  timer.setInterval(10000, sendSensor);
  timer.setInterval(10000, sendLDR);
  timer.setInterval(30000, SendtoThingspeak);
  
}

void loop()
{
  Blynk.run();
  timer.run();
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

// Write DHT22 values to Blynk
  Blynk.virtualWrite(V4, h);
  Blynk.virtualWrite(V5, t);
}

void sendLDR()
{
  float ldr = analogRead(ldr);

 // Write LDR values to Blynk
  Blynk.virtualWrite(V6, ldr);
}

void SendtoThingspeak()
{
  Blynk.virtualWrite(V3, t, h, ldr);
}
Output: V3
URL: http://api.thingspeak.com/update?api_key=XXXXXXXXX&field1=/pin[0]/&field2=/pin[1]/
Method: GET
Content type: applicatipn/json
Body: empty

When I change /pin[0]/ to an actual value, that value will be displayed on the thingspeak graph.
I’ve been trying to figure this out for a couple of weeks and really need help.
Thanks in advance!!


Webhook and multiple values in Thingspeak (again) SOLVED
#2

Please don’t tack new issues into older topics. I moved your post into its own topic.

That is because the API URL needs an actual value, it is a Web browser like process and not meant to work with variables, at least directly like that.

You would need to first build up a String using text and data variables and then use that completed String as the final URL. I do not have any handy examples, sorry.


#3

#4

Thanks for replying!
So what you’re saying is that I must create a separate string for all the different sensors and then update the URL so that it looks like this:

http://api.thingspeak.com/update?api_key=XXXXXXXXX&field1=string t&field2=string h

Did I understand correctly?


#5

Please see post 11

There are all you need there I think


#6

see the bellow that it seems to get the job done!

    if (client.connect(server,80)) {  //   "184.106.153.149" or api.thingspeak.com
    String postStr = apiKey;
           postStr +="&field1=";
           postStr += String(t);
           postStr +="&field2=";
           postStr += String(h);
           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: "+apiKey+"\n");
     client.print("Content-Type: application/x-www-form-urlencoded\n");
     ///client.print("Content-Length: "); 
     /// see https://community.thingspeak.com/forum/announcements/sending-data-to-thingspeak-api-from-device-but-channel-is-not-updated-what-changed/#p7929
     ///client.print(postStr.length());
     client.print("Content-Length: ");
     client.print(String(postStr.length()));
     client.print("\n\n");
     client.print(postStr);
     timer.setTimeout(200L, []() {  // Lambda Reconnection Timer Function activating once in 200 milliseconds
      yield();
      client.stop();
      } );  // END Timer Function
    }

#7

I have added that to my code so i know looks like this

// create ble serial instance
SoftwareSerial SerialBLE(10, 11);   // Rx, Tx

#define DHTPIN 13          // Pin DHT22 is connected to
#define ldrPIN A0          // Pin LDR is connected to

#define DHTTYPE DHT22   // DHT 22


float t;
float h;
float ldr;

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void setup()
{
  // Debug console
  Serial.begin(9600);
  SerialBLE.begin(9600);

  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  dht.begin();

  // Setup a function to be called every 5 second
  timer.setInterval(10000, sendSensor);
  timer.setInterval(10000, sendLDR);
  timer.setInterval(30000, SendtoThingspeak);
  
}

void loop()
{
  Blynk.run();
  timer.run();

   if (client.connect(server,80)) {  //   "184.106.153.149" or api.thingspeak.com
    String postStr = 1CO81IDJXVZVGRDV;
           postStr +="&field1=";
           postStr += String(t);
           postStr +="&field2=";
           postStr += String(h);
           postStr +="&field3=";
           postStr += String(ldr);
           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: "1CO81IDJXVZVGRDV"\n");
     client.print("Content-Type: application/x-www-form-urlencoded\n");
     ///client.print("Content-Length: "); 
     /// see https://community.thingspeak.com/forum/announcements/sending-data-to-thingspeak-api-from-device-but-channel-is-not-updated-what-changed/#p7929
     ///client.print(postStr.length());
     client.print("Content-Length: ");
     client.print(String(postStr.length()));
     client.print("\n\n");
     client.print(postStr);
     timer.setTimeout(200L, []() {  // Lambda Reconnection Timer Function activating once in 200 milliseconds
      yield();
      client.stop();
      } );  // END Timer Function
    }
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

// Write DHT22 values to Blynk
  Blynk.virtualWrite(V4, h);
  Blynk.virtualWrite(V5, t);
}

void sendLDR()
{
  float ldr = analogRead(ldr);

 // Write LDR values to Blynkd
  Blynk.virtualWrite(V6, ldr);
}



void SendtoThingspeak()
{
  Blynk.virtualWrite(V3, t, h, ldr);
}

I’m getting errors that client and server aren’t delcared. Sorry if this is a stupid question, I’m not good a coding, but what do I delcare client and server as?


#8

I am not able to debug your sketch right now, but from my very fast observation I saw that you missed:

#include <ESP8266WiFi.h;

WiFiClient client;

The above should be written before
void setup() { …

ALSO MOVE THINGSPEAK UPDATES OUT OF loop. You can not update these values so much often, needed to pout in a timer function and to activate each let’s say 20 seconds ( 20000L timer value ).

Try it and let me know


#9

I tried this. But I’m still getting errors. I’m not using any Wifi module in this project. All I have is an arduino, sensors and the bluetooth module: https://www.aliexpress.com/item/OPEN-SMART-Wireless-Serial-Bluetooth-Transceiver-Master-Slave-Module-Compatible-with-3-3V-5V-for-Arduino/32797227393.html

Do I need a wifi module for this project to work?