Blynk Notification from system

Hi I have a problem with blynk notification as I wanted to give alert to the device’s user after the dose of sound passed 0.1(just example limit)

#define BLYNK_TEMPLATE_ID "TMPLYt4o1Hpd"

#define BLYNK_DEVICE_NAME "IoT Sound Monitoring"

#define BLYNK_AUTH_TOKEN "g9a7GGPdS_HdjrZg5qunXZF7gERmYE8i"

#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

#include <LiquidCrystal_I2C.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "xdxd";

char pass[] = "12345678";

BlynkTimer timer;

const byte soundpin = 35;

const byte led1 = 27;

const byte led2 = 26;

const byte led3 = 25;

int lcdColumns = 16;

int lcdRows = 2;

int pinValue,pinValue2;

bool eventTrigger=false;

float sum2;

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

int LoopTime = 100;

byte Speaker[8] = {0b00001,0b00011,0b01111,0b01111,0b01111,0b00011,0b00001,0b00000};

BLYNK_WRITE(V6)

{

  pinValue = param.asInt();

  Serial.print("V1 Slider value is: ");

  Serial.println(pinValue);

}

BLYNK_WRITE(V7)

{

  pinValue2 = param.asInt();

  Serial.print("V1 Slider value is: ");

  Serial.println(pinValue2);

  if(pinValue2==1){

    sum2=0;

  }

}

void setup() {

  pinMode(soundpin, INPUT);

  pinMode(led1, OUTPUT);

  pinMode(led2, OUTPUT);

  pinMode(led3, OUTPUT);

  lcd.init();

  lcd.backlight();

  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  lcd.createChar(0, Speaker);

  //timer.setInterval(250L, sensorDataSend);

}

void loop() {

  Blynk.run();

  timer.run();

  int sum = 0;

  int Analog;

  int SPLref = 80;

  int AvgRef = 130;

  int n = 0;

  int Sum = 0;

  int value;

  int size = 51;

  float act[size] = {};

  float tn[size];

  float Average;

  float dBSPLAvg;

  float dose;

  unsigned long ReadStartTime;

  ReadStartTime = millis();

  while (millis() - ReadStartTime < LoopTime) {

    Analog = abs(analogRead(35));

    Sum = Sum + Analog;

    n++;

  }

  Average = ((float)Sum / n) - 95;

  if (Average < 4) {

    Average = 4;

  }

  dBSPLAvg = SPLref + 20 * log10((float)Average / AvgRef);

  value = dBSPLAvg-50;

  Serial.print(Average, 1);

  //Serial.println("%");

  if(pinValue==1){

  for(int k=0;k<size;k++){

  if(k==value){

  ++act[k];// in sec .7sec

  }

  }

  for(int i=0;i<size;i++){

  tn[i]=(8/2^((50+i)/5))*3600;// in sec

  }

  for(int j=0;j<size;j++){

  sum2+=(act[j]/tn[j]);

  }

  dose=100*sum2;

  Serial.print(",\t");

  //Serial.println(sum2,5);

  Serial.println(dose);  

    lcd.setCursor(0,1);

    lcd.print("Dose:");

    lcd.print(dose,1);

    lcd.print("% ");

    lcd.write(byte(0));

  if(dose>0.1){

      eventTrigger= true;

    Blynk.email("aididhelmi0@gmail.com", "Alert", "Dosage is dangerous!");

    Blynk.logEvent("Dosage is dangerous!","Remove");

    }

  }

  Blynk.virtualWrite(V0, dBSPLAvg);

  Blynk.virtualWrite(V4, dose);

 

  digitalWrite(led1, LOW);

  digitalWrite(led2, LOW);

  digitalWrite(led3, LOW);

  Blynk.virtualWrite(V1, 0);

  Blynk.virtualWrite(V2, 0);

  Blynk.virtualWrite(V3, 0);

  Blynk.virtualWrite(V5, 0);

  lcd.setCursor(0, 0);

  lcd.clear();

  //lcd.print("Loudness:");

  lcd.print(dBSPLAvg, 1);

  lcd.print("dB ");

  if (dBSPLAvg <= 60) {

    digitalWrite(led1, HIGH);

    Blynk.virtualWrite(V1, 1);

    lcd.print("Quite");

  } else if (dBSPLAvg > 60 && dBSPLAvg < 80) {

    digitalWrite(led2, HIGH);

    Blynk.virtualWrite(V2, 1);

    lcd.print("Moderate");

  } else if (dBSPLAvg > 80) {

    digitalWrite(led3, HIGH);

    Blynk.virtualWrite(V3, 1);

    lcd.print("Severe!");

  }

  delay(300);

}


Blynk.email() is a Legacy command. It doesn’t work with Blynk IoT and needs to be removed from your sketch.

The syntax for Blynk.logEvent() is…

Blynk.logEvent("event_code")

or

Blynk.logEvent("event_code", "optional custom message")

According to your screenshots your event code is “sound” so your command should look like this…

Blynk.logEvent("sound")

or

Blynk.logEvent("sound", "additional message regarding sound level")

However, there is a limit of 100 events per 24 hour period, and your code will easily exceed this if it detects a high level of sound for 100 iterations of your void loop.

You should read this for more info on how to avoid this issue…

Also, you shouldn’t have this code in your void loop, and you should use BlynkTimer instead of the blocking delay() commands that you are currently using.
Read this for more info…

Pete.

Is it possible if the lcd operation is created through this function ?

void sensorDataSend()void sensorDataSend()

I don’t understand the question.

Pete.