BLYNK
BLYNK.IO       📲 GETTING STARTED       đź“— DOCS       âť“HELP CENTER       👉 SKETCH BUILDER

Webhook widget

Hi all,
Is the Webhook functionality available in V2? I couldn’t see a widget but not sure if it is located somewhere else.

Cheers
Steve

Hello. Yes. Webhooks were moved to the web. No widget required anymore - Webhooks - Blynk Documentation

Thanks Dmitriy. I can’t see the developers section in the settings menu. Is this a subscription plan related issue?

Cheers
Steve

Looks like yes. We’ll check with @Pavel

@Dmitriy I think @steve1 means sending webhook from hardware based on some condition. Because webhooks we have are for organizations.

@Pavel we can extend existing webhooke with “device trigger”.

Hi @Pavel and @Dmitriy,
I think @Pavel has it. I am looking for the equivalent of the webhook widget in Blynk V1. I use it to import weather text file and parse json weather conditions on Openweather.

Cheers
Steve

Webhooks can do that. WE just need to extend it with additional trigger that right now is not supported.

I use Openweather, but I don’t use webhook widget

void forecast() {
  WiFiClient client;
  HTTPClient http;  //Declare an object of class HTTPClient

  http.begin(client, "http://api.openweathermap.org/data/2.5/weather?id=yourID&units=metric&lang=fr");  //Specify request destination
  int httpCode = http.GET();     //Send the request

  if (httpCode > 0) { //Check the returning code
    payload = http.getString();   //Get the request response payload
  }
  http.end();   //Close connection
  JsonRequest(); //call Json
}
2 Likes

@PeteKnight
I also Face the same Issue

Same here. I use webhooks to send/PUT to and receive/GET from IFTTT.
I cannot see webhooks options / permission under Settings, haven’t yet been able to figure this one out.
All help/doc welcome.

Thanks!

You need to wait for Blynk to add the functionality, as @Dmitriy said.

Pete.

Blynkers. I am porting my ESP32/8266 Blynk apps to the new Blynk, learning as I go.

However, I have used Blynk’s Webhook widgets to POST measurements and operating info to IFTTT for observation, debugging and data analysis. (The ESP32/8266 did a virtualWrite to a Webhook widget, which then POSTed the info to an IFTTT Applet.) I have an IFTTT account with several IFTTT Applets that receive POSTs from Blynk Webhook widgets. Most then write that data to Google Sheets. It’s a great way to analyze data produced by the ESPs, AND to debug OTA devices running in the wild.

The new Blynk does not (yet) support the Webhook widget.
So what to do?

I found this code from @Blynk_Coeur in our Blynk Community, which got me started. Thanks @Blynk_Coeur.
https://community.blynk.cc/t/webhook-widget/54152/9?u=thorathome
Then I found a great tutorial on ESP32 / 8266 HTTP GET and POST.
https://randomnerdtutorials.com/esp32-http-get-post-arduino/#http-post

I wrote a short sketch to POST to IFTTT using text/plain strings OR by using JSON, which is more powerful. Both options are in the code, below. JSON POSTs allow greater flexibility, especially using character strings, and the code takes up no more memory. I did not find much difference between using text/plain and application/x-www-form-urlencoded Content-type.

I still miss being able to have an IFTTT Applet send data to a Blynk Webhooks Widget or directly to an ESP32/8266. So if anyone has figured that one out, please post.

  • The postToIFTTT() sketch assumes you have a WiFi or Ethernet connection up and running, with or without Blynk.
  • It is presented as a self-contained subroutine using no global variables.
  • It includes one additional library HTTPClient.h.
  • While specific to IFTTT, this can be a starting point for any HTTP POST to an API.

You will want an IFTTT account. Start with free. Even their PRO version is not expensive.
Under IFTTT’s Webhooks documentation is your IFTTT KEY with some simple instructions.
You will need the IFTTT KEY for your POST (and GET) code.
You will also need the name of your IFTTT Applet which consumes the POST and does something with it. (I love Google Sheets!)

I hope it’s helpful, have also posted this code on my Github.
https://github.com/thorathome/Blynk_Examples

#define USE_JSON true
//#define USE_JSON false

#include <HTTPClient.h>

// This is YOUR IFTTT Webhooks KEY (not Blynk's)
#define MY_IFTTT_KEY    "kjdhphw973ihei7heehih" // from Webhooks doc in IFTTT when you have an IFTTT account
// This is YOUR IFTTT Applet that your Blynk sketch will POST to (I use SONOFFs a lot)
#define MY_IFTTT_APPLET "SONOFF_Signal"         // from IFTTT Applet which consumes the webhook POST

// Very helpful article on HTTP GET and POST 
// https://randomnerdtutorials.com/esp32-http-get-post-arduino/#http-post

void postToIFTTT() 
{
  mySerialPln ( "\npostToIFTTT called..." ); 

  // Set up an HTTP client object for the IFTTT POST 
  HTTPClient IFTTTpost;  
  
  // Server name URL
  String IFTTTserverName = "https://maker.ifttt.com/trigger/" + String ( MY_IFTTT_APPLET ) + "/with/key/" + String ( MY_IFTTT_KEY );
  IFTTTpost.begin ( IFTTTserverName );  //Specify request destination, open HTTP connecction
  Serial.print ( "\n\nIFTTT ServerName <" ); Serial.print ( IFTTTserverName ); Serial.println ( ">" ); 

#if USE_JSON
  IFTTTpost.addHeader ( "Content-Type", "application/json" );

  // IFTTT's JSON payload is { "value1" : "xx", "value2" : "mm", "value3" : "gg" }
  // IFTTTrequest = "{ \"value1\" : \"Yo_Bud\", \"value2\" : \"mm\", \"value3\" : \"gg" }";
  String IFTTTrequest = "{ \"value1\" : \"Yo Bud - JSON POST\" }"; // spaces permitted !
  Serial.println (     "JSON POST is     <" ); mySerialP ( IFTTTrequest ); mySerialPln ( ">" ); 

#else
  //IFTTTpost.addHeader ( "Content-Type", "text/plain" );
  IFTTTpost.addHeader ( "Content-Type", "application/x-www-form-urlencoded" );

  // IFTTT's text/plain payload is "?&value1=val1&value2=val2&value3=val3"
  String IFTTTrequest = "?&value1=Hey_Man-text-POST";  // no spaces allowed 
  Serial.print (     "text POST is     <" ); Serial.print ( IFTTTrequest ); Serial.println ( ">" ); 

#endif
  
  int IFTTTreturnCode = IFTTTpost.POST ( IFTTTrequest );     // POST the request to IFTTT
  Serial.print ( "POST return code: " ); Serial.println ( IFTTTreturnCode ); 

  if ( IFTTTreturnCode > 0 ) //Check the returning code (200 is AOK)
  {
    String payload = IFTTTpost.getString();   //Get the request response payload
    Serial.print ( "Payload response from IFTTT POST: " ); Serial.println ( payload );  
  }
  IFTTTpost.end();   //Close HTTP connection
  
} // end postToIFTTT
2 Likes

Good job :+1:

Thanks again. The Blynk Webhook widget I use for POSTing to IFTTT and elsewhere had blocked my porting most of my apps to the new Blynk. Your code got me started on a(n interim) solution.

My other blocker is the Bridge Widget, which I use to communicate in both directions between SONOFF and other similar switches and my controller/scheduler, which talks to them all.

Still learning…

1 Like

I’d suggested to @Blynk_Coeur earlier that a solution to that would be to use the Blynk HTTPS API to achieve the same result.

The code wouldn’t be much different to what you’re doing to call the IFTTT API.
I think I would define a parametrised function which accepts the Blynk virtual pin number and the value that you want to send to that pin.
If you are bridging multiple devices then you could also pass the Blynk Auth token to the function, or maybe a pointer to the Auth token.

The Blynk HTTPS API syntax is different for the new Blynk, but documented here:

https://docs.blynk.io/en/blynk.cloud/https-api-overview

Pete.

1 Like

Don’t work with the same code I use to get weather from Openweather API

void API() {
  WiFiClient client;
  HTTPClient http;  //Declare an object of class HTTPClient

  http.begin(client, "https://fra1.blynk.cloud/external/api/get?token=**************&v1");  

  int httpCode = http.GET();
  Serial.print(" Code : ");
  Serial.println(httpCode);

  //if (httpCode > 0) { //Check the returning code
  String payload = http.getString();   //Get the request response payload
  //}

  http.end();   //Close connection
  Serial.print(" API : ");
  Serial.println(payload);
}

I get :
00:00:28.077 → Code : -5
00:00:28.077 → API : (empty)

if I put https://fra1.blynk.cloud/external/api/get?token=**************&v1 in my browser , I get V1 stream

Hmm, I guess that’s because its an HTTPS request rather than HTTP.

Probably need to include the root certificate in the sketch, but I’m not sure if it’s possible to export that from the browser for the Blynk website.

I’ll do a bit of digging…

Pete.

1 Like

Yes Pete
I think I have to use WifiSSLClient and port 443.

I cant get the keys
2021-06-21_090905
2021-06-21_090729

Digging in progress :stuck_out_tongue_winking_eye:
But it’s not as easy as bridging or using metadata :thinking:

1 Like