BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Delay before Connecting to Blynk Server

Hi Blynkers,

An easy one for those with experience, which is not me yet.

Currently my project connects to the Blynk Server at power up & sends a notification after 7 minutes and every 7 minutes after that.
Instead to save resources, I want it to connect to the Server and send a message only after first 10 minutes has elapsed, then on loop every 7 minutes after.

Here’s what I have so far:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "***************************";
SimpleTimer timer1;

// WiFi credentials.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxxxxxxxxx";

void setup()
{
  // Debug console
    Serial.begin(74880);
    Blynk.begin(auth, ssid, pass);             //connect to Blynk Server
    timer1.setInterval(420000L, sendSensor);     // Send notification every 7 minutes
}

void sendSensor(){
  Blynk.notification("Blynk: Gate Left Open");
}

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

Firstly, can you please edit your post to format your code properly.

Try changing this:

timer1.setInterval(420000L, sendSensor);

To this:

timer1.setTimeout(180000L, [](){
    timer1.setInterval(420000L, sendSensor);
});

This should set your timer to every 7 minutes but offset the start by 3 minutes.

Despite the explanation of how to correctly format code in the text that appears when you create a new topic, and being asked by @JustBertC to edit your post to correct the issue, you haven’t added the correct formatting takes to allow your code to display correctly.
As a result I’ve removed your unformatted code.

Please edit your initial post to add-in your correctly formatted code. The code must have triple backticks at the beginning and and end. Triple backticks look like this:
```

Pete.

1 Like

OK, your initial explanation was not 100% clear.

When you have formatted your code as required then I will have a look at it for you - because now I do not know code you are using.

Hi All,

I hope someone may be able to assist with my project.
To save on resources, I want to have a delay of 10 minutes before connecting to the Blynk Server after my ESP8266 is powered up.
(ie. I only want to connect to Blynk Server when it will need to notify. If the device powers up then powers down within first 10 minutes there is no need to connect to the Blynk Server at all.)

Here’s what I have so far:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "***************************";

// WiFi credentials.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxxxxxxxxx";

void setup()
{
Serial.begin(74880);

"wait ten minutes, then connect to Blynk Server " 
Blynk.begin(auth, ssid, pass);             //connect to Blynk Server
"do something here"    
}


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

Thanks in advance.

This is basically the same question that you asked 3 weeks ago, so I’ve merged the two topics.

Maybe it would help if you explained what resources you think you’ll be saving by taking this approach. It would also help if you gave more information about what this device does, what sort of environment it will be operating in.

Pete.

1 Like

Connected or not to blynk server, you can’t save anything because wifi module is activated at start
you need

WiFi .mode( WIFI_OFF );
WiFi.forceSleepBegin();
delay( 1 );

https://www.bakke.online/index.php/2017/05/21/reducing-wifi-power-consumption-on-esp8266-part-2/