Before creating the topic
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code.Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
Running on ESP32. All other functions work. Just no webhooks sent since 5/19/25
Sketch is below:
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
*************************************************************
Blynk.Edgent implements:
- Blynk.Inject - Dynamic WiFi credentials provisioning
- Blynk.Air - Over The Air firmware updates
- Device state indication using a physical LED
- Credentials reset using a physical Button
*************************************************************/
/* Fill in information from your Blynk Template here */
/* Read more: https://bit.ly/BlynkInject */
#define BLYNK_TEMPLATE_ID "TMPL2DN7rzEkX"
#define BLYNK_TEMPLATE_NAME "Garage"
#define BLYNK_FIRMWARE_VERSION "0.2.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
#define USE_ESP32_DEV_MODULE
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_TTGO_T_OI
#include "BlynkEdgent.h"
#include <HTTPClient.h>
char* ClosedwebhookUrl = "https://www.virtualsmarthome.xyz/url_routine_trigger/activate.php?trigger=ea33430a-f611-4661-aa30-e57278041b7e&token=413caeb9-62d7-43f6-913d-5a79247fc1b8&response=html";
char* OpenwebhookUrl = "https://www.virtualsmarthome.xyz/url_routine_trigger/activate.php?trigger=7609a300-a269-4553-bd15-be7be69752ca&token=cc72b25f-e537-45fb-b652-ef48111681f7&response=html";
char* webhookUrl = "";
#define RELAY_PIN 21
#define SENSOR_PIN 22
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
#define BLYNK_YELLOW "#ED9D00"
bool isDoorOpen;
bool lastDoorStatus;
BlynkTimer timer;
BLYNK_WRITE(V0)
{
// Local variable `value` stores the incoming Status switch state (1 or 0)
// Based on this value, the physical Sensor pin on the board will be on or off:
int value = param.asInt();
if (value == 1) {
Blynk.setProperty(V2, "color", BLYNK_YELLOW); //Yellow
Blynk.virtualWrite(V2,"Checking status");
delay(2000);
isDoorOpen = digitalRead(SENSOR_PIN);
Serial.print("Sensor value =");
Serial.println(isDoorOpen);
if (isDoorOpen){
Blynk.setProperty(V2, "color", BLYNK_RED); //Red
Blynk.virtualWrite(V2,"The Door is OPEN");
webhookUrl = OpenwebhookUrl;
send_webhook();
} else {
Blynk.setProperty(V2, "color", BLYNK_GREEN); //Green
Blynk.virtualWrite(V2,"The Door is CLOSED");
webhookUrl = ClosedwebhookUrl;
send_webhook();
}
} else {
//digitalRead(SENSOR_PIN);
//Serial.print("Sensor value = ");
//Serial.println(value);
}
}
BLYNK_WRITE(V1)
{
// Local variable `value` stores the incoming Open/Close switch state (1 or 0)
// Based on this value, the physical Relay on the board will be on or off:
int value = param.asInt();
if (value == 1) {
if (isDoorOpen){
Blynk.setProperty(V2, "color", BLYNK_YELLOW); //Yellow
Blynk.virtualWrite(V2,"Closing the door");
} else {
Blynk.setProperty(V2, "color", BLYNK_YELLOW); //Yellow
Blynk.virtualWrite(V2,"Opening the door");
}
digitalWrite(RELAY_PIN, HIGH);
Serial.print("Relay value =");
Serial.println(value);
delay(2000);
digitalWrite(RELAY_PIN, LOW);
} else {
digitalWrite(RELAY_PIN, LOW);
Serial.print("Relay value = ");
Serial.println(value);
}
}
void send_webhook() {
// Initialize HTTPClient
HTTPClient http;
http.begin(webhookUrl);
// Send an HTTP POST request
int httpCode = http.POST("");
if (httpCode > 0) {
String response = http.getString();
Serial.println("Webhook response:");
Serial.println(response);
} else {
Serial.println("Error sending request");
}
http.end();
}
void myTimer()
{
// This function describes what will happen with each timer tick
// e.g. writing sensor value to datastream
if ((isDoorOpen) != (lastDoorStatus)) {
if (isDoorOpen){
Blynk.setProperty(V2, "color", BLYNK_RED); //Red
Blynk.virtualWrite(V2,"The Door is OPEN");
lastDoorStatus = isDoorOpen;
Serial.println("The Door is OPEN");
webhookUrl = OpenwebhookUrl;
send_webhook();
} else {
Blynk.setProperty(V2, "color", BLYNK_GREEN); //Green
Blynk.virtualWrite(V2,"The Door is CLOSED");
lastDoorStatus = isDoorOpen;
Serial.println("The Door is CLOSED");
webhookUrl = ClosedwebhookUrl;
send_webhook();
}
} else {
Serial.println(" No status change");
}
}
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
pinMode(SENSOR_PIN, INPUT_PULLUP);
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
timer.setInterval(1000L, myTimer);
}
void loop() {
// Reading sensor from hardware pin 22
isDoorOpen = digitalRead(SENSOR_PIN);
BlynkEdgent.run();
// runs BlynkTimer
timer.run();
delay(10);
}