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

Webhook returns 0/1 instead of data

Dear all,

Can somebody help me to get the web data in my home automation again?

I’ve been using legacy Blynk for a while now and recently decided to switch to the new app and online console. I’ve setup my home automation project using my Arduino MKR1000 and most of it works seamlessly. Except for the webhook :frowning: I used to use the webhook widget to retrieve data from weerlive.nl to decide whether or not to lower or raise our sunscreens, but after I’ve set-up the webhook in Blynk console the only return I get when triggering the virtual pin is the value I sent to the pin at that time. In the legacy version I never experienced this. I’ve included a copy of a simplified sketch that illustrates my challenge. The webhook is now triggered by a button in my app, but in practice it gets triggered from my code. The result is the same.

The things I’ve checked based on the things I found on the forum:

  • api returns less than 1024 characters. Increasing size to 4096 doesn’t help me
  • I’ve explored the HTTPClient type hardcoding, but don’t think that’s supported by the Arduino I have
  • The log shows the webhook is triggered by the button action

My code

// 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           "xxxx"
#define BLYNK_DEVICE_NAME           "Cani12"
#define BLYNK_AUTH_TOKEN            "xxxx"

// Comment this out to disable prints and save space
#define BLYNK_PRINT SerialUSB

#include <BlynkSimpleWiFiShield101.h>
#include <ArduinoJson.h>
#define BLYNK_PRINT Serial
#define BLYNK_MAX_READBYTES 1024

char auth[] = BLYNK_AUTH_TOKEN;

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

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

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
  
BLYNK_WRITE(V1) 
{
  String json = param.asStr();
  Serial.println("WebHook data:");
  Serial.println(json);
}

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

Output in the monitor is
WebHook data:
0
WebHook data:
1

The DATASTREAM / ‘Choose Datastream’ input is set to V1. For some reason when editing it is sometimes empty. When reloading it’s shown again

@Captaincrunch1999 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.

Thanks. I’ve edited the post. rookie mistake.

You may wish to read this…

I have a feeling that the Blynk IoT Webhook simply makes the API call, and doesn’t return the response body, but @Dmitriy has yet to confirm this.

Pete.

thanks, the issue looks rather similar indeed and I think you are right that it makes the API call and does not response the body. So far I was not able to find a solution for that, but didn’t realize from the post you refer to that it may be an issue for Blynk to fix instead of me not doing things right :smiley: .

That’s correct. Webhooks are not used to return the body. As webhook is part of organization, so it’s not clear where the body should be returned to.

I would have expected that to be the device/datastream that triggered the webhook, in the same way that it worked with the Webhook widget in Legacy.

Maybe a checkbox that says “Return result to same device/datastream” would make that more flexible?

Pete.

1 Like

That is what I thought. In the legacy version writing to a virtual pin would result in the webhook data on the same virtual pin. That’s why I used this pin in the Webhook version too. Not sure how to set it up in a different way. If it doesn’t use the same data stream, what do I use to trigger the webhook?

The bottom line is that the current Blynk IoT widget has no way to return the body, and I don’t know of a way to make an API call direct from the device using an Arduino + ESP-01 combination.

The current solution would probably be to use a NodeMCU or ESP32 instead of the Arduino.

Pete.

ok, that confirms my concerns. Let’s hope the Blynk IoT webhook implementation is updated at some point so I can keep using the MKR1000 and the current code. For short term I will keep using the legacy version, it worked good enough. I do have a MKR1010 lying around which is said to have an ESP32 module. I’ll start building a code to access the api data without use of the webhook. Good reason to learn that too.

Guido

What type of data are you trying to obtain?

Pete.

Weerlive.nl is a Dutch weather website. The most accurate I could find for local conditions that provides a free api too. I use temperature, windspeed, sunrise, sunset and cloud conditions from the generated json file to determine whether sunscreens should be lowered or not.

We’ll add it. I didn’t expect somebody used this feature.

thanks @Dmitriy, highly appreciated. It was the easiest implementation for the MKR1000 I could find. Since @PeteKnight his recommendations I’ve decided to work on the MKR1010 too, but so far unsuccessful* so it would help me and hopefully others switching from legacy version to Blynk 2.0 as well

*I do manage to import a JSON file on the Arduino now without using webhook but with the ArduinoHttpClient library, but for some reason Blynk keeps disconnecting. Might lead to another post sometime :smiley: