Receiving Blynk Notifications Every 5 secs

Also, this is incorrect

Blynk.virtualWrite(A0, sensorState);

it should be

Blynk.virtualWrite(Vpin, sensorState);

with Vpin Being the pin your gauge is on.

https://docs.blynk.cc/#blynk-firmware-blynktimer-blynksyncvirtualvpin

Blynk.virtualWrite(A0, sensorState); is working with me, since i have a virtual pin called A0 on that gauge on blynk

no you have the gauge set to the A0 pin. There is no virtual pin A0.

In this case no virtual pin is being used. You are just reading the value of A0 directly from the device. Which means you don’t need to have the void sendSensor() function. Just change the reading rate to 1 second on the gauge widget, and the app will read the A0 pin every second.

oh ok, but that was not my problem, my point is that i need to receive a notification at 1st sec, then initiate timer, i found this link:
Execute the setInterval function without delay the first time
, still reading it

#define BLYNK_PRINT Serial
#include <SPI.h>;
#include <SimpleTimer.h>;
#include <ESP8266WiFi.h>;
#include <BlynkSimpleEsp8266.h>;

char auth[] = "********************************";
char ssid[] = "***************";
char pass[] = "***********************************";
BlynkTimer timer;
const int sensorPin = A0;   

void notification(){

int sensorState1 = analogRead(sensorPin);
  Serial.println("10 min Sensor Value");
  Serial.println(sensorState1);
  sensorState1 = map(sensorState1, 0, 1023, 0, 100);
 Serial.println("10 min Sensor Value after Mapping");
  Serial.println(sensorState1);
  if (sensorState1 >= 51) {         //send notification
  Blynk.notify("Water your plants");
 Serial.println("Water your plants");

    } 
  else if (sensorState1 <= 49) {
   //Blynk.notify("Does not need water");
  Serial.println("Does not need water");
  }
}

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(sensorPin, INPUT);

  notification(); //run notification once. 

  //OR, uncomment the timer below, and comment out the function call above, as an alternate

   //timer.setTimeout(100L, notification); //run notification once after .1 seconds 

  timer.setInterval(600000L, notification);  // to run notification every 10 minutes
  
  
}

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

}

it’s working, but the data is being read every 1 sec?

data read every one second (or whatever frequency is set on the widget). notification sent on start-up, and every 10 minutes thereafter.

water your plant and see if the value changes.

the data didn’t change when i watered the plants, i think because the function is called every 10 mins, so the data will change after 10 mins

the data used for determining the notification will change every 10 minutes. The gauge should change every second.

pin should be: Analog, adc0
reading rate should be: 1 sec

i added a readsensor notification and now it works fine, but when the value is changing from for example 42 to 59, i am not receiving a notification immediately

yeah i have the same as that

you will receive the notification when the notification function runs. that could be up to 10 minutes.

You will not receive a notification the instant it needs water. Not with this code at least.

But do you really need to know the instant the plant needs water?

can this be done?

so whenever the value changes from for example 42 to 56, i will receive an immediate notification, then a notification every 10 mins

it sure can. Will I do it for you, probably not.

there was an example given by @daveblynk that would be a good starting point.

no problem, i will try my best, thanks :smiley:

if you get stuck, post what you have tried and I’m sure you will get some assistance.

1 Like

yeah sure, thanks!!

i have made this, and just worked perfectly

#define BLYNK_PRINT Serial
#include <SPI.h>;
#include <SimpleTimer.h>;
#include <ESP8266WiFi.h>;
#include <BlynkSimpleEsp8266.h>;

char auth[] = "************************************************";
char ssid[] = "*********************";
char pass[] = "****************************************";
SimpleTimer timer;
const int sensorPin = A0;   
int sensorState = 0;
int lastState = 0;
int lastStateWet = 0;

void notification()
{
  if (sensorState >= 51) {         //send notification
  Blynk.notify("Water your plants");
 Serial.println("Water your plants");

    } 
}
void sendSensor(){
 sensorState = analogRead(sensorPin);
 sensorState = map(sensorState, 0, 1023, 0, 100);
Serial.println(sensorState);
Blynk.virtualWrite(A0, sensorState);

if (sensorState >= 50 && lastState == 0) { 
 lastState = 1;                         //toggles message sent state
 lastStateWet = 0;                  //toggles message sent stateWET
 Blynk.notify("Water your plants");
   } 
else if (sensorState <= 48 && lastStateWet == 0)
{
   lastState = 0;
   lastStateWet = 1;
   Blynk.notify("Plants were watered");
 }

}


void setup()
{
 Serial.begin(115200);
 Blynk.begin(auth, ssid, pass);
 pinMode(sensorPin, INPUT);
 timer.setInterval(1000L, sendSensor);
 timer.setInterval(60000L, notification);
}

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

}

thanks all, thank you @Toro_Blanco , @daveblynk , and @PeteKnight , for your help

2 Likes