Hi,
I have some problems with the notifications from the new Blynk app.
My problem is that I receive only the “offline” notification with sound and pop-up message on my mobile phone, for the rest of the notifications I can see it on the Timeline and on the notifications tab in the mobile phone but without sound and pop up message, and another one think is that I can see notifications in the mobile phone app but these notifications are missing on the desktop timeline and they shows them several minutes later.
I’m a very newbie with Blynk, C++…
The code below is not written by me, the code works fine with the “old” blynk app.
It monitors the water level in a tank and sends an alert when the water level falls below a certain level.
Thanks in advance!
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxxxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#include "BlynkEdgent.h"
#include <SimpleTimer.h>
#include <Wire.h>
SimpleTimer timer1; // for TOF10120 Sensor
SimpleTimer timer2; // for counting seconds and minutes
// for TOF10120 Laser Rangefinder Sensor
unsigned char ok_flag;
unsigned char fail_flag;
unsigned short lenth_val = 0;
unsigned char i2c_rx_buf[16];
unsigned char dirsend_flag=0;
int x_mm; // distance in millimeters
int Sensor_actual_value;
float y_inches; // distance in inches
int secs;
int minutes;
int hours;
int litresOfWater;
int distanceToWater;
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
Wire.begin();
timer1.setInterval(1000L, TOF10120);
timer2.setInterval(1000L, Time_check);
}
void loop() {
timer1.run(); // Initiates SimpleTimer
timer2.run();
BlynkEdgent.run();
}
void TOF10120()
{
x_mm = ReadDistance();
Sensor_actual_value = x_mm;
litresOfWater = 1290 - Sensor_actual_value;
distanceToWater = Sensor_actual_value / 10;
x_mm = map(x_mm, 0,600,100,0);
Serial.println(x_mm);
// Serial.print(" mm");
Serial.println(Sensor_actual_value);
Blynk.virtualWrite(V5,Sensor_actual_value / 10);
Blynk.virtualWrite(V6,1290 - litresOfWater);
Blynk.virtualWrite(V7,litresOfWater * 1);
Blynk.virtualWrite(V8,litresOfWater * 2);
}
int serial_putc( char c, struct __file * )
{
Serial.write( c );
return c;
}
void SensorRead(unsigned char addr,unsigned char* datbuf,unsigned char cnt)
{
unsigned short result=0;
// step 1: instruct sensor to read echoes
Wire.beginTransmission(82); // transmit to device #82 (0x52), you can also find this address using the i2c_scanner code, which is available on electroniclinic.com
// the address specified in the datasheet is 164 (0xa4)
// but i2c adressing uses the high 7 bits so it's 82
Wire.write(byte(addr)); // sets distance data address (addr)
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(1); // datasheet suggests at least 30uS
// step 3: request reading from sensor
Wire.requestFrom(82, cnt); // request cnt bytes from slave device #82 (0x52)
// step 5: receive reading from sensor
if (cnt <= Wire.available()) { // if two bytes were received
*datbuf++ = Wire.read(); // receive high byte (overwrites previous reading)
*datbuf++ = Wire.read(); // receive low byte as lower 8 bits
}
}
int ReadDistance(){
SensorRead(0x00,i2c_rx_buf,2);
lenth_val=i2c_rx_buf[0];
lenth_val=lenth_val<<8;
lenth_val|=i2c_rx_buf[1];
delay(300);
return lenth_val;
}
void Time_check()
{
secs = secs + 1;
if ( secs >= 59 )
{
minutes = minutes + 1;
secs =0;
if(minutes == 5) // notification message is sent after every 2 minutes, change this number as per your requirement
{
if (Sensor_actual_value > 500) // if the tank is almost empty
{
Blynk.logEvent("check_water_level");
secs = 0;
minutes = 0;
}
if (Sensor_actual_value < 300) // if half filled or the tank is full
{
secs = 0;
minutes = 0;
}
}
}
}