Notification Oddities

I’m using a ESP8266 Chinese 4 relay module for remote site monitoring. A PIR sensor (voltage free contact) feeds an input set up for notification to my Android phone. If the app is running on the phone, the notification comes in immediately, but if the phone is asleep (even if the app was running when phone is put into standby), the notification is very unreliable. Sometimes is immediate, other times only notifies when the phone is woken. The notification widget is set for ‘Normal’ and I allow notifications and interruptions and lock screen notifications. Same on an older phone with older Android, so not peculiar to my phone (Honor V20).
Snipped code below - just shows PIR stuff.

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG  //debug o/p via comms
                    //shows comms with wifi/server

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

int pir_state_new = LOW;  //PIR input mod
int pir_state_old = LOW;

BlynkTimer timer;  //create a Blynk Timer object

void myTimerEvent() //called every second from timer interrupt

  //PIR input mod
  pir_state_new = digitalRead(D4); //low when triggered

      if (pir_state_new != pir_state_old)  //if change
       pir_state_old = pir_state_new;
       WidgetLED led1(V8);            //only send on change of state
       if (pir_state_new == 1)
        //Serial.println("Alarm!");        //only alarm on change to HIGH


void setup()
  // Debug console
  //Establish link with Blynk server
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
  pinMode(D4, INPUT_PULLUP);  //PIR mod input

void loop()
{;  // talks to Blynk server and deals with requests;  // Initiates BlynkTimer

Priority high priority gives more chances that your message will be delivered without any delays


Thanks Pete. Yes, I tried that first, of course. No better. Definitely seemed to be a phone related problem, so was just wondering if anyone else had played with this potentially brilliant function.