webHook can't exchange information with virtual pin

I tried to execute WEB HOOK GET example from here
->> Blynk Example Browser
for my project but it’s not work…

so I search similar documents to solve this problem
and I guess that webHook and virtual pin are not communicate each other. because when I tried to set webHook datastream to V0 and webHook url to /pin/, it cause error “URL is invalid”
++ /pin/ color is not green, just like other letters.

below code is my device code

  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  This example shows how to fetch data using WebHook GET method

  App project setup:
    WebHook widget on V0, method: GET, url: /pin/
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "---"
#define BLYNK_DEVICE_NAME "---"
#define BLYNK_AUTH_TOKEN "---"


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
// Allow for receiving messages up to 512 bytes long
//#define BLYNK_MAX_READBYTES 512

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

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "blynkTest";
char pass[] = "98765432";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

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

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BLYNK_WRITE(V0)
{
  Serial.println("WebHook data:");
  Serial.println(param.asStr());
}

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

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  Blynk.virtualWrite(V0, "https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras/logo.txt");

  // You can perform HTTPS requests even if your hardware alone can't handle SSL
  // Blynk  can also fetch much bigger messages,
  // if hardware has enough RAM (set BLYNK_MAX_READBYTES to 4096)
  //Blynk.virtualWrite(V0, "https://api.sunrise-sunset.org/json?lat=50.4495484&lng=30.5253873&date=2016-10-01");
}

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


this is device code, and virtual pin V0 setting
I hope to find my mistakes and solve this problem😞


and this is image when url error occurred

This sketch belongs to blynk legacy and you’re using blynk IOT so it’s not gonna work because there isn’t webhook widget in blynk IOT.

In the second image you can’t use /pin/ as url, to use the webhook you have to create a webhook and assign it to a virtual pin then you have to send data to the virtual pin to trigger the webhook

By using Blynk.virtualWrite , I confirmed that webHooks were triggered.
However, when the code below is executed, the result value is not json or str data from webHooks, but the value stored in the V0 virtualPin is output as it is.

BLYNK_WRITE(V0)
{
  Serial.println("WebHook data:");
  Serial.println(param.asStr());
}

How do I receive json, str, etc. files to the device using webHooks?

@proof please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

oops… I modified it🙂

You should review what the code looks like now, because by adding the triple backticks inline with the first line of code, that code isn’t visible.

Pete.

thank you pete.
It is first time to post in blynk community… not familiar for me🤔

I suspect that you don’t understand how the webhook is meant to work, either in Blynk Legacy or in Blynk IoT.
That leads me to question whether or not you are actually using the correct tool to achieve you overall task.

The Webhook is used to retrieve data from a 3rd party service, such as a weather forecasting service that provides an HPPP(s) API.
In this situation, the URL in the Webhook configuration needs to be the API call that is needed to retrieve your data from the 3rd party service. That includes all of the user specific data such as username, password, access token etc.

If this is a static API call (i.e you need to always make the same call, to obtain the current weather for your specific location for example) then the Webhook is very straightforward. Once you’ve put your API call into the Webhook and configured the settings correctly, so that pressing the “Test Webhook” button produces a valid response, then the process is very simple.
Every time you trigger the virtual pin associated with the Webhook with any data whatsoever, the Webhook will be triggered and it will return the results to the device.

However, if you want the Webhook call to be more dynamic, so that parameters such as latitude and longitude are passed to the Webhook, enabling you to adjust the ASP call parameters from the app, then the value, then you need to configure the Webhook so that the value passed on the virtual pin that triggers the Webhook is incorporated into the API call.

So, assuming you are actually using the correct tool to achieve your goal, you first task is to get the API call working with static values in the API call.
Once you’ve done this then you can move on to receiving the response data into the sketch running on your hardware device.

I’d suggest that you also read the documentation
https://docs.blynk.io/en/blynk.console/settings/developers/webhooks

Pete.

2 Likes

Thanks for replying!!:laughing::laughing:
Actually, my goal is to get weather information through openweathermap.
So I got 200OK, webHook successfully get using static API call as your advice.
Now I wonder how to get data to hardware device

How are you triggering the webhook from your sketch?

Pete.

1 Like

This topic might help you

1 Like
/*************************************************************
  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  This example shows how to fetch data using WebHook GET method

  App project setup:
    WebHook widget on V0, method: GET, url: /pin/
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLt1lklOEA"
#define BLYNK_DEVICE_NAME "esp"
#define BLYNK_AUTH_TOKEN "VRz4uWTJ4FkEj3rRXrYkCi37ScD1sp7Q"


// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
// Allow for receiving messages up to 512 bytes long
//#define BLYNK_MAX_READBYTES 512

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

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "blynkTest";
char pass[] = "98765432";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

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

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BLYNK_WRITE(V0)
{
  Serial.println("WebHook data:");
  //delay(6000);
  Serial.println(param.asStr());
}

BLYNK_WRITE(V2)
{
  Serial.println("button:");
  Serial.println(param.asStr());
  Blynk.virtualWrite(V0, "V0 Data");
  Blynk.syncVirtual(V0);
}

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

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  Blynk.virtualWrite(V0, "V0 Data");

  // You can perform HTTPS requests even if your hardware alone can't handle SSL
  // Blynk  can also fetch much bigger messages,
  // if hardware has enough RAM (set BLYNK_MAX_READBYTES to 4096)
  //Blynk.virtualWrite(V0, "https://api.sunrise-sunset.org/json?lat=50.4495484&lng=30.5253873&date=2016-10-01");
}

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

The code above is the full sketch and the one below is how I trigger the webHook.

BLYNK_WRITE(V2)
{
  Serial.println("button:");
  Serial.println(param.asStr());
  Blynk.virtualWrite(V0, "V0 Data");
  Blynk.syncVirtual(V0);
}

->> I read that webHook is triggered when data is sent to V0.
I created a button that uses V2 and made it possible to trigger a webHook whenever the button is pressed.

Why are you doing this?..

What do you see in the Webhoook Logs tab?

Are you waiting at least 1 minute between webhook triggers?

Pete.

1 Like

When I ckicked button twice, Serial monitor and Webhook Logs show like below:

button:
1
button:
0
WebHook data:
V0 Data
WebHook data:
V0 Data
button:
1
button:
0
WebHook data:
V0 Data
WebHook data:
V0 Data

I used syncVirtual… This is because BLYNK_WRITE(V0) did not work when this was not used.

And does it work when it is used?

When you call the API from your web browser, how may characters does it return?
With the Legacy webhooks there was a limit to the number of characters that that the response could have, and if this was exceeded the response wasn’t returned.

Some OpenWeather API calls return far more data tan you actually need.

If you can’t get oit working then you can make the API call to openWeather durectly from your sketch…

Pete.

2 Likes

Oh, there was a character limit. When I call the api from the browser, it returns 797 characters. May I know what the character limit of the webHook is?:flushed:

The Legacy limit was 256 bytes.
This could be increased by adding:

#define BLYNK_MAX_READBYTES 1024

where 1024 is the new maximum.

I have no idea if Blynk IoT is limited in the same way, or if the limit can be increased in the same way.

Pete.

1 Like

Thank you for your answer
I listened to your advice and did some research.

But unfortunately, the mega2560 and esp8266 models I use cannot use the HTTPClient library.
I decided to keep using webHook.
I called https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras/logo.txt as an exercise
It triggers in webHooks Logs, but the code below is not called and in the end I couldn’t check Bylnk in the Serial window.
(++ I removed syncVirtual)

BLYNK_WRITE(V0)
{
  Serial.println("WebHook data:");
  Serial.println(param.asStr());
}

The number of characters Call from API doesn’t seem to be the problem, but I don’t know why it doesn’t work.:cry:

That’s not a call to a valid GitHub API, it’s simply a web URL

Pete.