Hi i’m running the demo of webhook with wemos D1 with a little variation ( timer each 5 seconds ) but i don’t receive any result. Here is the code and the debug…in webhook widget i set only V0, iunderstand than url is in code.
Thanks for your time.
Code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG // Optional, this enables more detailed prints
// Allow for receiving messages up to 512 bytes long
#define BLYNK_MAX_READBYTES 4096
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
Serial.println("WebHook data:");
Serial.println(param.asStr());
}
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
Serial.println("Event Timer...");
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 setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Setup a function to be called every second
timer.setInterval(5000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
As per the comments in the sketch the url in the widget must follow the regular format so the minimum is: https://raw.githubusercontent.com/pin/ (where the last 5 characters of the url will be highlighted in green).
/pin/ is useful for real world projects as it allows users to change the url on the fly so for example they would enter their specific long and lat in Terminal for sunrise api
/* WebhookV10.ino https://community.blynk.cc/t/webhook-widget-demo-does-not-return-any-value/15687/2
V0 Webhook widget with url as https://raw.githubusercontent.com/pin/ last 5 characters will be GREEN
V1 Button to manually trigger Webhook but will trigger from setup() or can be set with BlynkTimer etc
*/
#define BLYNK_PRINT Serial
#define BLYNK_MAX_READBYTES 1024
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char server[] = "blynk-cloud.com";
char ssid[] = "xxxx";
char pass[] = "xxxx";
char auth[] = "xxxx";
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass, server);
Blynk.virtualWrite(V0, "/blynkkk/blynk-library/master/extras/logo.txt");
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V0){ // Webhook: in widget as GET https://raw.githubusercontent.com/pin/ last 5 characters will be GREEN
Serial.println("WebHook data:");
Serial.println(param.asStr());
}
BLYNK_WRITE(V1){ // Webhook button for "https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras/logo.txt"
if (param.asInt() == 1) {
Serial.println("Webhook triggered");
// in widget as GET https://raw.githubusercontent.com/pin/ last 5 characters will be GREEN
Blynk.virtualWrite(V0, "/blynkkk/blynk-library/master/extras/logo.txt");
}
}
thank you guys, and if i want to make the last part of the url dynamic, what have i to configure on the widget and how to pass the parameter in the arduino?