Hi, I have some issues with notification, hope someone can help me.
I’m building a temperature controller that sends a notification if the temperature is greater than a threshold, everything works but after 20 or so notifications, Blynk stops recording the event and sending notification.
I know the free plan allow to send 100 notifications so what could be the issue.
Here is the function that control the notification:
#include <Arduino.h>
//Temperature libraries
#include <OneWire.h>
#include <DallasTemperature.h>
//Blynk connection libraries
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//Wifi Manager libraries
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
//Blynk ID
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
BlynkTimer timer;
#define INTERVAL 5000l /*BlynkTimer timer interval*/
#define MY_INTERVAL 60000
void tempRequest(); /*temperature reading and output*/
int myTimer(unsigned long timer1);
unsigned long current_time, time_diff;
#define TEMP_PIN 12 /*temperature sensor signal pin*/
#define MIN_TEMP 0 /*min temperature threshold*/
#define MAX_TEMP 100 /*max temperature threshold*/
OneWire oneWire(TEMP_PIN);
DallasTemperature temp(&oneWire);
float temp_C; /*temperature in celsius*/
int threshold;
bool FIRST = true;
void setup() {
Serial.begin(9600);
//BEGIN WIFI MANAGER CONFIG
WiFiManager wifiManager;
wifiManager.setTimeout(120);
if (!wifiManager.autoConnect("WiFi Temperature", "password"))
{
Serial.println("failed to connect, we should reset as see if it connects");
delay(3000);
ESP.reset();
delay(5000);
}
else
{
Serial.println("connected ");
}
//BLINK SETUP AND CONNECTION
Blynk.begin(BLYNK_AUTH_TOKEN, WiFi.SSID().c_str(), WiFi.psk().c_str());
Blynk.syncAll();
timer.setInterval(INTERVAL, tempRequest);
temp.begin();
}
void loop() {
Blynk.run();
timer.run();
}
void tempRequest()
{
temp.requestTemperatures();
temp_C = temp.getTempCByIndex(0);
Serial.print("Temperature is: ");
Serial.print(temp_C, 1);
Serial.println(" C");
Serial.println(" ");
Serial.println(time_diff);
Serial.println(" ");
Blynk.virtualWrite (V0, temp_C); /*send temperature value to blynk*/
/*Warning notification*/
if (temp_C > threshold)
{
if ((myTimer(MY_INTERVAL)) || FIRST)
{
Blynk.logEvent("max_temp"); /*send push notification to app*/
Serial.println(" ");
Serial.println ("TEMPERATURE IS TOO HIGH");
Serial.println(" ");
FIRST = false;
}
}
else
{
FIRST = true;
current_time = millis() + 5000; /*Set timer to 0*/
}
}
int myTimer(unsigned long timer1)
{
int ret = 0;
time_diff = millis() - current_time;
if (time_diff >= timer1) /*&& RUN)*/
{
current_time = millis();
ret = 1;
}
/*---------------------------------------------*/
/*debug prints*/
Serial.print("Timer value: ");
Serial.println(timer1);
Serial.print("Current time: ");
Serial.println(current_time);
Serial.print("Millis value: ");
Serial.println(millis());
Serial.print("Time difference: ");
Serial.println(time_diff);
Serial.print("Return value: ");
Serial.println(ret);
Serial.println(" ");
/*----------------------------------------------*/
return ret; /*function return value*/
}
/*INCREMENT*/
BLYNK_WRITE (V1)
{
int pinData = param.asInt();
if (pinData == 1){
if (threshold == MAX_TEMP)
{
threshold = MAX_TEMP;
}
else
{
threshold ++;
}
Blynk.virtualWrite (V3, threshold);
}
}
/*DECREMENT*/
BLYNK_WRITE (V2)
{
int pinData = param.asInt();
if (pinData == 1){
if (threshold == MIN_TEMP)
{
threshold = MIN_TEMP;
}
else
{
threshold --;
}
Blynk.virtualWrite (V3, threshold);
}
}
/*SYNC THRESHOLD*/
BLYNK_WRITE(V3)
{
threshold = param.asInt();
}