Blynk double connect with deep sleep

  1. My wake times to connect, send one value and return to sleep were too long (aprox 10 seconds)
  2. I shortened some of the 5000 delays in the library to 1000 per suggestions on board and got it down to 3-5 sec
  3. With the debug ON you can see a 2nd connect message. (duplicate?)

Here is what I get now as output.

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld
~+⸮⸮⸮Connecting to cxxxxxx
[1274] Connected to WiFi
[1274] IP: 192.168.86.26
[1274] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.8 on NodeMCU

[1283] Free RAM: 45696
[1286] Connecting to blynk-cloud.com:8442
[1447] <[02|00|01|00] 7df9c35910e242958b41cdfd423a24f1
[1549] >[00|00|01|00|C8]
[1549] Ready (ping: 1ms).
[1549] <[11|00|02|00]Hver[00]0.4.8[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Oct 22 2017 07:36:31[00]
[1651] >[00|00|02|00|C8]
[2550] Connecting to blynk-cloud.com:8442
[2670] <[02|00|01|00] 7df9c35910e242958b41cdfd423a24f1
[2776] >[00|00|01|00|C8]
[2776] Ready (ping: 1ms).
[2776] <[11|00|02|00]Hver[00]0.4.8[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Oct 22 2017 07:36:31[00]
[2890] >[00|00|02|00|C8]
72.50
[3233] <[14|00|03|00|0C]vw[00]10[00]72.500
total time : 3097

Looks like a double connect (one second apart)

Here is my code snippet :

#define BLYNK_PRINT Serial 
#define BLYNK_DEBUG 

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

#include <Arduino.h>
extern "C" {
#include <user_interface.h>
}

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h> 
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board - GPIO02
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

float tempF;
unsigned long starttime;

// how long to sleep between checking and TX temp/batt values - in seconds
#define SLEEP_LENGTH 60

// Blynk auth
char auth[] = "xxxxxxxxxxxxxxxxxxf1"; 

/* WiFi credentials */
char ssid[] = "cxxxxxxx";
char pass[] = "xxxxxxxxxxx";


void setup()
{

  
  Serial.begin(74880); // default wake up baud after rst
  starttime=millis();
 
  
  // rst_info *rinfo = ESP.getResetInfoPtr();
  // Serial.println(String("\nResetInfo.reason = ") + (*rinfo).reason + ": " + ESP.getResetReason() + "\n");
  

  Blynk.begin(auth, ssid, pass);
    while (Blynk.connect() == false) {
    Serial.print("atempting Conection"); //Wait until connected
     
   }

  Blynk.run();


  //do work here.......   
  DS18B20.begin();
  DS18B20.setResolution(10);
  DS18B20.requestTemperatures(); 
  tempF = DS18B20.getTempFByIndex(0);
  
  Serial.println(tempF);
  Blynk.virtualWrite(10, tempF); //virtual pin V10
 
  Serial.print("total work time : ");
  Serial.println(millis()-starttime);
  
  ESP.deepSleep(SLEEP_LENGTH * 1000000,WAKE_RF_DEFAULT);   // default mode
  delay(100);
}

void loop()
{
 //do nothing here. The Setup() function takes care of it all as the ESP resets each time after it wakes from sleep
}

Can anyone figure why the 2nd connect is happening…?

please edit your post and format the code properly before posting. otherwise no one will bother to read it.

@doronby I fixed your formating… please use this method yourself in the future.

Blynk - FTFC

Thanks !
Now can anyone figure out the double connect messages?

Might be the Blynk.run() you have in the setup? Is it causing any problems?

took that line out… still works… still double connect.

But is it causing any problems? Or is this just an exercise in curiosity :thinking:

By the way… why is this in your setup? I believe Blynk.begin() will already wait until connection.

And another observation… please repost both the serial monitor output an the actual sketch that generated it… you two prior displayed are NOT one from the other, as evidenced in the time printout: If you changed that, what else might you have changed that could generate the 2nd connect msg?

Thanks for the suggestion.

I took out the blink.connect loop and the 2nd connect is now gone.
I still have a problem:
Wake time sometimes (every 30-40 times) goes to over 300 seconds… when it is normally 2-4 seconds.

Here is the updated output.

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld
⸮
 Temp :73.40
 RSSI:-43

 **Wake time : 1.93**

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld
⸮
 Temp :73.40
 RSSI:-43

 **Wake time : 4.40**

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld
⸮
 Temp :73.40
 RSSI:-48

 **Wake time : 302.99**

and the updated code:

// #define BLYNK_PRINT Serial
#include <Blynk.h>


// #define BLYNK_DEBUG

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Arduino.h>
extern "C" {
#include <user_interface.h>
}

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board - GPIO02
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

float tempF;
unsigned long starttime;
float waketime;

// how long to sleep between checking TX temp/rssi values - in seconds
#define SLEEP_LENGTH 15

// Blynk auth
char auth[] = "xxxxxxxxxxxxxx";

/* WiFi credentials */
char ssid[] = "xx";
char pass[] = "xxxx";


void setup()
{

  starttime = millis();
  Serial.begin(74880); // default wake up baud after rst

  DS18B20.begin();
  DS18B20.setResolution(10);
  DS18B20.requestTemperatures();

  WiFi.setOutputPower(0);
  Blynk.begin(auth, ssid, pass);

  //  while (Blynk.connect() == false) {
  //    Serial.print("atempting Conection"); //Wait until connected
  //  }
  // Blynk.run();

  tempF = DS18B20.getTempFByIndex(0);

  Serial.print("\n Temp :");
  Serial.println(tempF);
  long rssi = WiFi.RSSI();

  Serial.print("\ RSSI:");
  Serial.println(rssi);

  Blynk.virtualWrite(10, tempF); //virtual pin V10
  Blynk.virtualWrite(11, rssi); //virtual pin V11

  waketime = (millis() - starttime) / 1000.0;
  Blynk.virtualWrite(13, waketime ); //virtual pin V13


  Serial.print("\n Wake time : ");
  Serial.println(waketime);



  ESP.deepSleep(SLEEP_LENGTH * 1000000, WAKE_RF_DEFAULT);  //try the default mode
  delay(100);
}

void loop()
{
  //do nothing here.
  //The Setup() function takes care of it all.
  //as the ESP resets each time after it wakes from deep sleep
}

Sounds like something gets ‘stuck’ in the Blynk.begin() call.

Glad you resolved your original question.

Blynk.begin() IS a blocking call (until connected).

Search this forum for other topics on Deep Sleep with Blynk… perhaps there might be some suggestions that can be applied to your script.

I am now doing WiFi.begin and it seems to speed things up. (big delays in Blynk.begin…???)
I also had to resort to a sort of watchdog to get past these 300 seconds events…
I now get ‘wake time’ of ~1.9 seconds 90% of the time and once in a while, eit goes up to 2.98 and even up to 4,92 sec.
Watchdog kicks in ~1% of the time. (no connect for >15 seconds) so no big power on for 300 seconds.

// #define BLYNK_PRINT Serial
#include <Blynk.h>
#include <Ticker.h>

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


/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board - GPIO02
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

char auth[] = "xxxx7df9c35xxxxx910e242958xxxxxx";

#define SLEEP_LENGTH 60

//SSID of your network
char ssid[] = "cxxxxx";
//password of your WPA Network
char pass[] = "pxxxxxx";
int status;
float tempF;
unsigned long starttime;
float waketime;

volatile int watchdogCount = 0;

Ticker secondTick;

#define debug 1
#define results 0

void ISRwatchdog() {
  Serial.print("*");
  watchdogCount++;
  if ( watchdogCount == 10 ) {
     // Only print to serial when debugging
     (debug) && Serial.println("The watch dog barks!");
     ESP.deepSleep(SLEEP_LENGTH * 1000000, WAKE_RF_DEFAULT);  //try the default mode
     // ESP.reset();
  }
}


void setup()
{
  
  starttime = millis();
  secondTick.attach(1, ISRwatchdog);
  
  Serial.begin(74880); // default wake up baud after rst
  WiFi.setOutputPower(0);

  status = WiFi.begin(ssid, pass);
  while ( status != WL_CONNECTED) {
    (debug) && Serial.print(".");
    status = WiFi.status();
    delay(100);
  }
  Blynk.config(auth);
  Blynk.connect(); 

  DS18B20.begin();
  DS18B20.setResolution(10);
  DS18B20.requestTemperatures();
  tempF = DS18B20.getTempFByIndex(0);
  (results) && Serial.print("\n Temp :");
  (results) && Serial.println(tempF);
  long rssi = WiFi.RSSI();

  (results) && Serial.print("\ RSSI:");
  (results) && Serial.println(rssi);

  Blynk.virtualWrite(10, tempF); //virtual pin V10
  Blynk.virtualWrite(11, rssi); //virtual pin V11

  waketime = (millis() - starttime) / 1000.0;
  Blynk.virtualWrite(13, waketime ); //virtual pin V13

  Serial.print("\n Wake time : ");
  Serial.println(waketime);

  //delay(100);
  ESP.deepSleep(SLEEP_LENGTH * 1000000, WAKE_RF_DEFAULT);  //try the default mode
  //delay(100);
}

void loop () {}
1 Like