Problems with events

I’m having problems with events in Blynk. I’m not getting it, even though everything seems to be ok.

The strange thing is that the timeline says that the limit of 100 daily was reached but at the same time it says that there were no events in the period. And I’m not really receiving events on my smartphone (I usually received them in another sketch I used a month ago)

Another thing that suggests a bug is that I have 5 events active but only 3 appear on the timeline.

Here screens with event settings:

Here the sketch:


/********************************
                                | 
 Monitoramento de temperatura   |
                                |
*********************************/

#define BLYNK_TEMPLATE_ID "xxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"
#define BLYNK_AUTH_TOKEN "xxxxx"
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxxx";
char pass[] = "xxxx";

#define ds18b20 D2

float voltagem;
int bat_percentagem;
int bateria = A0;
int sensorValor;
int tempBaixa;
int tempAlta;
int alertaAlta;
int alertaBaixa;
int Alertas;
float calibragem = 0.19; // Meça a voltagem da bateria após os resistores com o multimetro e adicione/dminua o valor e acrescente nesse campo para compensa-los

BlynkTimer timer;
 
// Objeto que tratará da troca de dados com o sensor DS18B20
OneWire oneWire(ds18b20);
DallasTemperature sensors(&oneWire);

//Atualiza os pinos virtuais com os dados salvos no servidor Blynk. Importante em caso de quedas de energia/conexão
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V2, V3, V4, V5, V6);
}

BLYNK_WRITE(V2) // Parâmetro de temperatura alvo
{
  tempBaixa = param.asInt();
}

BLYNK_WRITE(V3) // Parâmetro de temperatura alvo
{
  tempAlta = param.asInt();
}

BLYNK_WRITE(V4) // Parâmetro de alerta
{
  alertaAlta = param.asInt();
}

BLYNK_WRITE(V5) // Parâmetro de temperatura alvo
{
  alertaBaixa = param.asInt();
}

BLYNK_WRITE(V6) // Liga/desliga alertas
{
  Alertas = param.asInt();
}

void getDados()
  {
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);

  sensorValor = analogRead(bateria);
  voltagem = (((sensorValor * 3.3) / 1024) * 2 + calibragem); //multiplique por dois, pois a rede divisora de tensão é feita por dois resistores de 100K
  
  int voltagem_ajus = voltagem * 100;
  bat_percentagem = map(voltagem_ajus, 300, 390, 0, 100); //3V como voltagem mínima da bateria e 3.9V como máxima
  
  if (bat_percentagem >= 100)
  {
    bat_percentagem = 100;
  }
  if (bat_percentagem <= 0)
  {
    bat_percentagem = 1;
  }
  
  Blynk.virtualWrite(V0, tempC);  //Envia temperatura (DS18B20) para o Blynk
  Blynk.virtualWrite(V1, bat_percentagem);  //Envia percentual de bateria para o Blynk
  Blynk.virtualWrite(V7, voltagem);  //Envia voltagem de bateria para o Blynk
  
  if (Alertas == 1){
    
    if (tempC > alertaAlta && tempC < tempAlta) {
      Blynk.logEvent("alta", String("A temperatura da geladeira está ficando alta!!"));
      delay(500);
      }

    if (tempC < alertaBaixa && tempC > tempBaixa) {
      Blynk.logEvent("baixa", String("A temperatura da geladeira está ficando baixa!!"));
      delay(500);
      }
  }
 
    if (tempC > tempAlta) {
      Blynk.logEvent("limitealta", String("A temperatura da geladeira está no limite!!"));
      delay(500);
      }

    if (tempC < tempBaixa) {
      Blynk.logEvent("limitebaixa", String("A temperatura da geladeira está no limite!!"));
      delay(500);
    }

  if (bat_percentagem <=30)
    {
      Blynk.logEvent("bateria", String("A bateria está com a carga baixa! Troque-a com urgência!!"));
      delay(500);
    }
  }  

void setup()
{
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, getDados);
}

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

What can it be?

What do you see if you look at the “1 Week” period?

Do you have the option to reset the notification counter? I think this feature was introduced recently but I’m not sure if it applies to all plans.

Do you mean that you’re not receiving Notifications on your phone, or you can’t see Events in the timeline on your phone? (Events and Notifications aren’t the same thing, an Event can be used to trigger a Notification, but it’s not mandatory).

Do you have “Send to Timeline” selected for all of the events?

Your code is a bit of a mess, with the blocking delays, and no flags to prevent multiple events for each temperature scenario. It also doesn’t have any serial print commands to show you when each of the logical tests have been met.

Maybe reading this would help…

Pete.

Hello Pete,

Thanks for your help.

The images I posted from the timeline were all with all the events.

This is the screen with the weekly timeline. The same as others.

The same with the month

I didn’t find this option. I found “erase data” and I clicked but nothing changed.

The strange thing is that I received a notification since yesterday. Just one. So everything seems fine on the smartphone (IOS). But I should have received several because I tested all hypotheses, with serial print.

I also found it strange and I didn’t have these blocks but as it wasn’t working, I searched the net and found a code with this and put it to see what happened. Nothing has changed of course but I forgot to take them off.

I found a post of yours that teaches this but I’m still struggling to get it to work before improving it. But I will do it now.

I used serial print on all events and they worked correctly. I just took it off to send cleaner to esp.

That wasn’t what I asked, I was asking about how each of your events are configured in the template.

It would be better to add this back in.

Pete.

You say these settings? They were above.

The “new” sketch

/********************************
                                | 
 Monitoramento de temperatura   |
                                |
*********************************/

#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "Monitoramento"
#define BLYNK_AUTH_TOKEN "xxx"
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "xxx";
char pass[] = "xxx";

#define ds18b20 D2

float voltagem;
int bat_percentagem;
int bateria = A0;
int sensorValor;
int tempBaixa;
int tempAlta;
int alertaAlta;
int alertaBaixa;
int Alertas;
float calibragem = 0.19; // Meça a voltagem da bateria após os resistores com o multimetro e adicione/dminua o valor e acrescente nesse campo para compensa-los
bool alertaEnvAlta = false;
bool alertaEnvBaixa = false;
bool alertaEnvLimA = false;
bool alertaEnvLimB = false;
bool alertaBat = false;
BlynkTimer timer;
 
// Objeto que tratará da troca de dados com o sensor DS18B20
OneWire oneWire(ds18b20);
DallasTemperature sensors(&oneWire);

//Atualiza os pinos virtuais com os dados salvos no servidor Blynk. Importante em caso de quedas de energia/conexão
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V2, V3, V4, V5, V6);
}

BLYNK_WRITE(V2) // Parâmetro de temperatura alvo
{
  tempBaixa = param.asInt();
}

BLYNK_WRITE(V3) // Parâmetro de temperatura alvo
{
  tempAlta = param.asInt();
}

BLYNK_WRITE(V4) // Parâmetro de alerta
{
  alertaAlta = param.asInt();
}

BLYNK_WRITE(V5) // Parâmetro de temperatura alvo
{
  alertaBaixa = param.asInt();
}

BLYNK_WRITE(V6) // Liga/desliga alertas
{
  Alertas = param.asInt();
}

void getDados()
  {
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);

  sensorValor = analogRead(bateria);
  voltagem = (((sensorValor * 3.3) / 1024) * 2 + calibragem); //multiplique por dois, pois a rede divisora de tensão é feita por dois resistores de 100K
  
  int voltagem_ajus = voltagem * 100;
  bat_percentagem = map(voltagem_ajus, 300, 390, 0, 100); //2.8V como voltagem mínima da bateria e 4.2V como máxima
  
  if (bat_percentagem >= 100)
  {
    bat_percentagem = 100;
  }
  if (bat_percentagem <= 0)
  {
    bat_percentagem = 1;
  }
  
  Blynk.virtualWrite(V0, tempC);  //Envia temperatura (DS18B20) para o Blynk
  Blynk.virtualWrite(V1, bat_percentagem);  //Envia percentual de bateria para o Blynk
  Blynk.virtualWrite(V7, voltagem);  //Envia voltagem de bateria para o Blynk
  
  if (Alertas == 1){
    
    if (tempC > alertaAlta && tempC < tempAlta && alertaEnvAlta == false) {
      Blynk.logEvent("alta", String("A temperatura da geladeira está ficando alta!!"));
      Serial.println("A temperatura da geladeira está ficando alta!!");
      alertaEnvAlta = true;
      }
      else if (tempC < alertaAlta)
      {
        alertaEnvAlta = false;
      }
  
    if (tempC < alertaBaixa && tempC > tempBaixa && alertaEnvBaixa == false) {
      Blynk.logEvent("baixa", String("A temperatura da geladeira está ficando baixa!!"));
      Serial.println("A temperatura da geladeira está ficando baixa!!");
      alertaEnvBaixa = true;
      }
      else if (tempC > alertaBaixa)
      {
        alertaEnvBaixa = false;
      }
  }
 
    if (tempC > tempAlta && alertaEnvLimA == false) {
      Blynk.logEvent("limitealta", String("A temperatura da geladeira está no limite!!"));
      Serial.println("A temperatura da geladeira está no limite!!");
      alertaEnvLimA = true;
      }
      else if (tempC < alertaAlta)
      {
        alertaEnvLimA = false;
      }

    if (tempC < tempBaixa && alertaEnvLimB == false) {
      Blynk.logEvent("limitebaixa", String("A temperatura da geladeira está no limite!!"));
      Serial.println("A temperatura da geladeira está no limite!!");
      alertaEnvLimB = true;
    }
    else if (tempC > alertaBaixa)
    {
      alertaEnvLimB = false;
    }

  if (bat_percentagem <=30 && alertaBat == false)
    {
      Blynk.logEvent("bateria", String("A bateria está com a carga baixa! Troque-a com urgência!!"));
      Serial.println("A bateria está com a carga baixa! Troque-a com urgência!!");
      alertaBat = true;
    }
    else if (bat_percentaem > 30)
    {
      alertaBat = false;
    }
  }  

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, getDados);
}

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

You’ve posted a screenshot for the alta event only. You’ve said that some of your events appear in the timeline and others don’t, but you’ve provided no more information on which do and which don’t appear.
My question to you is do all of the events have the the “send to timeline” option enabled?

If you comment-out the logEvent lines of code and run the sketch, does it produce the expected result in the serial monitor?

Pete.

All events have the same settings. That’s why I just put one.
So as not to pollute the post so much.

In fact, no event log appears on the timeline. I received a single notification on my smartphone.

I think I found out what’s going on.

I hadn’t set the “flags” and yesterday I hadn’t enabled the timeline. I also configured hourly events. So, at that time it reached the event limit.

Despite this, today I did not receive any alert. If it’s daily, you should alert today. Unless it’s the last 24 hours. Anyway, I’ll wait until tomorrow to confirm.

And yes the alerts on the serial monitor works.

Thanks Pete.

I that case, a simple “Yes” to this question would have been useful…

My understanding is that it’s a rolling 24 hour period. If you spammed the server with over 100 events then it’s 24 hours from when you stopped doing this. That’s why I suggested you comment those logEvent lines out and ensure that your serial monitor is showing that your flag variables are working as needed and that you won’t begin spamming the server again when you un-comment those lines of code.

Pete.

I understood!! I hadn’t thought of that!!