Receiving Blynk Notifications Every 5 secs

I guess the question is, does the code do what you want.

Pete.

yes, i just want to have delays between each notification, just don’t want to get spammed with notifications, but as the same time keep the data updated each 1 sec

Then you need two timers, one every second (seems a bit over the top to me) that takes the readings and updates Blynk, then one every hour that applies whatever logic test you think you need, then sends a notification if appropriate.

Pete,

1 Like

so i will have 2 functions, one for reading sensor that will be called in the setup every 1 sec, and the other is pushing notifications that will be called in the setup every 1 hour, right?

Correct.

Pete.

so the code would look like that:

#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;   
int sensorState = 0; 
void sendSensor(){
  sensorState = analogRead(sensorPin);
  sensorState = map(sensorState, 0, 1023, 0, 100);
Serial.println(sensorState);
Blynk.virtualWrite(A0, sensorState);
}
void notification(){
if (sensorState >= 51) {         //send notification
  Blynk.notify("Water your plants");

    } 
  else if (sensorState <= 49) {
  Serial.println("Does not need water");
  delay(1000);
  }

}


void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(sensorPin, INPUT);
  timer.setInterval(1000L, sendSensor);    // to run sendSensor every 1 sec
  timer.setInterval(600000L, notification);  // to run notification every 10 minutes
  
  
}

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

}

right?

This serves no purpose, except to cause Blynk disconnections.

Otherwise it looks okay at a quick glance. How does it work in practice?

Pete.

yeah you’re right, i am trying it now, thanks for the fast replies, much appreciated :blush:

1 Like

it’s working just fine, but i am waiting 10 minutes at first, then after 10 minutes i will receive a notification, but i want to receive at 1st second a notification then receive every 10 minutes, what should i add to do so?

Add notification(); as the last thing in your void loop to call it immediately, once every time your device is booted.

Pete.

i added it, but i am getting spammed by notifications

I think he miss typed. Add it to the end of your void setup(), not the loop()

1 Like

didn’t work :frowning:

Doh!
That’ll teach me to answer forum questions while watching TV :roll_eyes:

Pete.

1 Like

probably because it takes 1 second to get the sensor valve. I would add an analog read to the notification function .

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");
  }
}

the 1st second notification is still not working

are the serial prints showing up in the serial monitor?

yeah every 1 sec

try again with the edits. see if it is showing the 10 Minute values.

there is no 10 minutes value, i just want to receive a notification if the plants need to be watered every 10 mins for example, but i want to get it at 1st second, then initiate timer