Mobile App Offline Notification of ESP8266, But Data Is Being Reported

Hello All,

I have a project where I am attempting to monitor my RV battery level. I want the nodeMCU to start up, take a reading, send the data to Blynk, then go to sleep for an hour (have also tried 1/2 hour). The device looks to be doing just that. I am seeing the data reported to Blynk but I am periodically getting Offline Notifications from the mobile app for this device but when I look, there will have been data reported within the past few minutes.

• NodeMCU ESP8266 v12
• iOS 16
• Blynk server
• Blynk Library version 2.0

#define BLYNK_TEMPLATE_ID "xxxxxxxxx"
#define BLYNK_DEVICE_NAME "Battery Monitor"
#define BLYNK_AUTH_TOKEN "xxxxxxxxx"
#define BLYNK_PRINT Serial
// #define BLYNK_HEARTBEAT 3600

#include <ESP8266WiFi.h>
#include "wifi_secrets.h"
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
char auth[] = BLYNK_AUTH_TOKEN;
WidgetRTC rtc;
BlynkTimer timer; // Announcing the timer

// WiFi
char ssid[] = SECRET_SSID;
char password[] = SECRET_PASS;
WiFiClient espClient;

float vOUT = 0.0;
float v = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float correctionfactor = -0.2;
int value = 0;
const int voltageSensor = A0;
String currentTime;
String currentDate;

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
  //The ESP8266 tries to reconnect automatically when the connection is lost
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);
}

void readSensor() {
  Serial.println("Starting Voltage Read");
  value = analogRead(voltageSensor);
  vOUT = (value * 3.20) / 1024.0;
  v = vOUT / (R2 / (R1 + R2));
  v = v + correctionfactor;
  Serial.print(v);
  Serial.println("V");

  Blynk.virtualWrite(V0, v); // Send voltage reading
  delay(300);

  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println("Going to sleep...");
  //ESP.deepSleep(6e+7); // 1 minute
  ESP.deepSleep(1.8e9); // .5 hour
  //ESP.deepSleep(3.6e9); // 1 hour
}

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  digitalWrite(LED_BUILTIN, LOW);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  initWiFi();

  // Start Blynk
  Blynk.begin(auth, ssid, password);
  rtc.begin();
  delay(1000);
  timer.setInterval(1000L, readSensor);
}

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

Thanks for any help!

Phil

Blynk treats a device as being offline if the keep-alive connection between the device and the server has closed and the heartbeat interval (normally 45 seconds) has expired.

When your device goes into deep sleep it closes the keep-alive connection, so after 45 seconds the Blynk server will report that the device is offline. This is expected behaviour.

Blynk have recently introduced a user definable “Offline Ignore Period” in the Info tab of the Template screen.
You could try changing this value and see if it gives the results you’re looking for.

Pete.

1 Like

Thank you, Pete. I forgot to mention that I had the Offline Ignore Period set to 2.5 hours which probably explains why I was seeing the entries in the timeline about every 2.5 hours.

2022-08-16 at 7.53 AM

Interestingly, I set
#define BLYNK_HEARTBEAT 3600
and have noticed no alerts since 16:51 PT, over 16 hours ago. Am I safe to assume the BLYNK_HEARTBEAT value should match (or slightly exceed) the deep sleep timer value?

If that’s the case, do you think I can probably lower the Offline Ignore Period value?

Personally, I’d do it the other way and keep the heartbeat period low and set the offline ignore period high - provided it produces the desired results.

Pete.

Hello sir,

Adjusting the heartbeat low and offline ignore period higher does not provide the proper results.

I currenlty have the:

  • Deep Sleep set to 1 hour
  • Heartbeat to 3600 seconds (1 hour)
  • Offline Ignore Period to 1 hour 5 mins

This is still producing random Offline mesasges. I’ve also noticed that if I increase the Offline Ignore Period, it actually impacts other notifications in the Events section as well. Should that be occurring?

Well, unless you elaborate on exactly what…

means in detail then it’s impossible to say.

I doubt very much if these are truly random,
There will almost certainly be a pattern to this behaviour.

Pete.

Meaning, if I have the offline ignore period set to 2h 30m, other Event Notifications (ex. Low Battery Alert) seem to also be delayed by that amount.

The device is currently setup to report battery status. If it’s below a certain threshold, it will send an Event such as Battery Critical to the Timeline. Then it will sleep for 1 hour. According to Blynk, the device will report for a few hours (anywhere from 2-4 intentional events in the Timeline) then report offline stating it was offline for ~30 mins. If you notice in the photo below, it reported at 12:37, 1:34 and 2:30 then went “offline” about 30 minutes later. Came back “online” at 3:27 once the device woke up to report again.

For testing, I have the “Battery Critical” threshold very high to ensure I see the reports in the Timeone. I was also seeing gaps in the Event reporting…
2022-08-24 at 2.39 PM
Another example
2022-08-24 at 2.39 PM

I added some logic to send payload to another platform to better track the gaps as I wasn’t sure if the issue was with Blynk or possibly the device not waking (which I was skeptical)

Now for the really strange part… I had the device off for about 12 hours, while I was not able to work on it. Plugged it back in and after almost 48 hours of running it has not reported any offline events. The only thing that changed was adding a Pushover.net notification to better track the gap in Blynk reporting I was seeing.

Just a reminder, I currently have the:

  • Deep Sleep set to 1 hour
  • Blynk Heartbeat to 3600 seconds (1 hour)
  • Blynk Offline Ignore Period to 1 hour 5 mins