Blynk webhook to ThingSpeak


I have followed the documentation by entering required info in web hook.
However, no data is sent to ThingSpeak.

Manually verified by posting the following does push the data to ThingSpeak.
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=342

I tried GET and POST, both with same negative result.
The test webhook will return with sending webhook for infinity.

In Arduino code, no changes is done to parse info from measurement or Blynk to ThingSpeak. Just rely on web hook.

Please help to provide guidance. What has gone wrong?
Thanks.

Code as follows.

#define BLYNK_TEMPLATE_ID   "XXXXXXXXXXXX"

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

#include "DHT.h"
#include <Arduino.h>
//#include <ThingSpeak.h>                           //ThingSpeak

BlynkTimer timer;

char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
char ssid[] = "XXXX";
char pass[] = "XXXX";


// Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

#define LED 4
#define LIGHT A6
#define SOUND A2
#define PIEZO  5                    
#define DHTPIN 3                    
#define DHTTYPE DHT11 // DHT 11     
DHT dht(DHTPIN, DHTTYPE);           

ESP8266 wifi(&EspSerial);


const byte fanPin = 6;
int duty = 0;                       
double temp, humi;                  

int autoValue = 0;
int lightLimit = 400;
int soundLimit = 1000;
int tempLimit = 30;
int light_adc;
int soundState;


BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
  digitalWrite(LED, pinValue);
}

BLYNK_WRITE(V5)
{
  duty = param.asInt();
  digitalWrite(fanPin, duty);
  Serial.println("Blynk switch V5 is: ");
  Serial.println(duty);
}

BLYNK_WRITE(V6) //Automation
{
  autoValue = param.asInt();
}

BLYNK_WRITE(V7) //Light Threshold
{
  lightLimit = param.asInt();
}

BLYNK_WRITE(V8) //Sound Threshold
{
  soundLimit = param.asInt();
}

BLYNK_WRITE(V9) //Temperature Threshold
{
  tempLimit = param.asInt();
}


void myTimerEvent()
{
  light_adc = analogRead(LIGHT);
  soundState = analogRead(SOUND);
  
  temp = dht.readTemperature();     
  humi = dht.readHumidity();        
  
  Serial.println("Light ADC: " + String(light_adc));
  Serial.println("Ambient Sound: " + String(soundState));
  
  Blynk.virtualWrite(V1, light_adc);
  Blynk.virtualWrite(V2, temp);     
  Blynk.virtualWrite(V3, humi);     
  Blynk.virtualWrite(V4, soundState);     

  Serial.println("Blynk switch V5 is: " + String(duty));
}

void setup()
{
  pinMode(LIGHT, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(fanPin, OUTPUT);
  pinMode(SOUND, INPUT);

  Serial.begin(9600);
  delay(10);

  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  dht.begin();                      

  Blynk.begin(auth, wifi, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);  
}

void loop()
{
  Blynk.run();
  timer.run(); 
  
  if (autoValue == 1){
    if (light_adc < lightLimit){
      digitalWrite(LED, 1);
    }
    else{
      digitalWrite(LED, 0);
    }
    if (soundState > soundLimit){
      Blynk.virtualWrite(V10, "Find some quiet time.");
    }
    else{
      Blynk.virtualWrite(V10, "It is peaceful now.");
    }
    if (temp > tempLimit){
      digitalWrite(fanPin, 1);
    }
    else{
      digitalWrite(fanPin, 0);
    }
  }
  else{
    Blynk.virtualWrite(V10, "I will not suggest.");
  }
}```

Hey there,
First of all, you must read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Hi John,
I did comment out the following lines, but it doesn’t work.

    if (light_adc < lightLimit){
      digitalWrite(LED, 1);
    }
    else{
      digitalWrite(LED, 0);
    }
    if (soundState > soundLimit){
      Blynk.virtualWrite(V10, "Find some quiet time.");
    }
    else{
      Blynk.virtualWrite(V10, "It is peaceful now.");
    }
    if (temp > tempLimit){
      digitalWrite(fanPin, 1);
    }
    else{
      digitalWrite(fanPin, 0);
    }
  }
  else{
    Blynk.virtualWrite(V10, "I will not suggest.");
  }```

Have you tried this url ?
Are you sure it’s working properly ?

Yes, manual enter is working.
A data will be recorded in ThingSpeak.

Okay, now to trigger the webhook, all you have to do is write data to the virtual pin and it should work.

I have tried and it remain unsuccessful, for both Post and Get.
I did not enable, but just test webhook and wait for more than 30 sec. The test webhook goes infinity again.
I have just enabled the webhook and it doesn’t yield positive result either.
Look at the snapshot below, there is entries going into ThingSpeak but the value is not recognized. This is the same observation before John made some change at his end.

Try this, add a button and assign it to virtual pin V1, now when you click the button it should trigger the webhook.

After adding the following code and button in Blynk interface, the device is disconnected from Blynk very often until no measurement is made.

{
  int webhookStatus = param.asInt();
  Serial.println("Webhook status is: " + String(webhookStatus));
}```

All you need is

Blynk.virtualWrite(V1,1); 

To trigger the webhook

I have tried to use button to write 1 to V1, and disable the sensor measurement. It doesn’t work either.

How did you configure your datastream ?
Post a screenshot please.

Here you go John.


V1 to V4 is what I need to push to ThingSpeak.

Try this

Blynk.virtualWrite(V1,1023); 

Have done so. No difference.

Are you assuming that the /pin/ on the end of the URL will be replaced with the value that you send to V1?

If so, what part of the Blynk IoT webkook documentation led you to believe that this is how to do that?

Pete.

Yes, that is my understanding that the value of /pin/ will be replaced with V1, and send to ThingSpeak.
Is this not the right method? As webhook does have a few options of get, push, put and delete.

Pete.

I do not. I am referring the web searches and find successful example before.
Blynk App Webhook Multiple Values to Thingspeak - Need Help With My Project - Blynk Community
and this
blynkkk.github.io/webhook.md at master · blynkkk/blynkkk.github.io · GitHub

These are examples for the Blynk Legacy webbook widget, which works in a totally different way.

Also, the webhook in Blynk IoT doesn’t currently return any values to the trigger pin, so this:

wouldn’t work if it was part of the BLYNK_WRITE(V1) callback, and certainly won’t work in the way that you appear to have used it.

Also, one think that you seem to be overloking is that Blynk IoT is limited to making just one webhook call per minute, which could be affecting your testing results significantly.

I haven’t used the Blynk IoT webhook - if I was going to make those external API calls from an ESP device then I would prefer to do that as an API call directly in the sketch - but looking at the documentation and the webhook interface screen in the console, I would assume that you would need to add dynamic data such as "{device_pinValue}" to include the value of a virtual pin in the API call.

Pete.