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.
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
}
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!
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
Good job
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…
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.
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.
Yes Pete
I think I have to use WifiSSLClient and port 443.
I cant get the keys
Digging in progress
But it’s not as easy as bridging or using metadata
It’s off to a bad start
09:35:22.516 -> ........................................................................
09:37:02.384 -> WiFi connected
09:37:02.384 -> IP address:
09:37:02.384 -> 192.168.0.19
09:37:02.384 -> Waiting for NTP time sync: .
09:37:02.901 -> Current time: Mon Jun 21 07:37:03 2021
09:37:02.901 -> Connecting to https://fra1.blynk.cloud/external/api/get?token=xxxxxxxxx&v1
09:37:02.901 -> Using certificate:
09:37:02.901 -> -----BEGIN CERTIFICATE-----
09:37:02.901 -> MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
09:37:02.901 -> EwJSMzAeFw0yMTA1MjUxMTQ5NDBaFw0yMTA4MjMxMTQ5NDBaMBYxFDASBgNVBAMT
09:37:02.901 -> 9ZJZBE/67xMbhoaIwUAkhZEZuVa2+V+AJSBWceWb4HiwRr0ZOBLC/Iv6m1Zhdxc/
09:37:02.949 -> aLLsEdgAwgAxvHGLrE/e/7Woy+HwtHJClagQxPZ2eCGw/SYOkE2X2aoACG1oESUl
09:37:02.949 -> dELwDAuRe0TNX59/0DIdIhfbl5rGGYgyEElzDMYvS+n9IJjc/ntE/Sa0CGgUvxDH
09:37:02.949 -> X4h1oWGnqbxfZK2vAEwSnhIJ2gaBe4UVDxiPW1doRFO/y3HJz3yu0Epkj6miE4r6
09:37:02.949 -> 1NeoSQwgwR0LfqN3t2Fq0Lefd8BpxQiMbTpfaPx2lRGC3ARRXdN29jAtajkWvdOx
09:37:02.949 -> nI7pPvPKB+kUYbS1hQIDAQABo4ICRjCCAkIwDgYDVR0PAQH/BAQDAgWgMB0GA1Ud
09:37:02.949 -> BBRucogk1UO/72z0nb5/Jf9EWIfUnjAfBgNVHSMEGDAWgBQULrMXt1hWy65QCUDm
09:37:02.949 -> H6+dixTCxjBVBggrBgEFBQcBAQRJMEcwIQYIKwYBBQUHMAGGFWh0dHA6Ly9yMy5v
09:37:02.949 -> LmxlbmNyLm9yZzAiBggrBgEFBQcwAoYWaHR0cDovL3IzLmkubGVuY3Iub3JnLzAW
09:37:02.996 -> Lm9yZzCCAQQGCisGAQQB1nkCBAIEgfUEgfIA8AB2AH0+8viP/4hVaCTCwMqeUol5
09:37:02.996 -> K8UOeAl/LmqXaJl+IvDXAAABeaOS13AAAAQDAEcwRQIgcjIVZTZ5USA11qpACq1k
09:37:02.996 -> bfuH4MRVlsNJqCROUsdZD4kCIQCRNuHwisa4DnhiaFh/8Ozft2fNazLCtW6nIw7j
09:37:02.996 -> IGWZzQB2AG9Tdqwx8DEZ2JkApFEV/3cVHBHZAsEAKQaNsgiaN9kTAAABeaOS2JkA
09:37:02.996 -> AAQDAEcwRQIhAL7lJHCRAG6KmmmLKLx+PvjxriKyJoU+19kzRpCAS0bCAiBobP+/
09:37:02.996 -> S0Nx4qbDFGgJSE/qPRa+0j98z/iQ9OG2n51nQjANBgkqhkiG9w0BAQsFAAOCAQEA
09:37:03.042 -> -----END CERTIFICATE-----
09:37:03.042 ->
09:37:10.074 -> Connection failed
to be continue
You can use http, not https.
that works well !!!
11:01:33.496 → Code : 200
11:01:33.496 → API : 11:1:33
11:01:34.296 → Current time: 11:1:34 21 6 2021
11:01:35.320 → Current time: 11:1:35 21 6 2021
11:01:36.324 → Current time: 11:1:36 21 6 2021