Random Device Offline (Clean Loop)

Pete,
Yes I have tried a different USB cable in hopes it will solve the problem

I will copy and paste the default Settings.h file and use the GPIO pin numbers instead of “D” pins as suggested.

When you used a clean Edgent example did you keep Settings.h in its original state and add this button?

I made zero changes to the Settings.h and the other configuration files.

The blocking delays, and the timers that all attempt to run at the same time probably don’t help with your device stability.

Unfortunately with my limited knowledge I don’t know how to make them run one after eachother :c

Take a look at the “Staggering Timers” section…

TBH, you’d be better putting the untouched Edgent example sketch (untouched except for adding-in the two lines of firmware configuration and un-commenting the correct board type) onto a different Wemos and testing that way.

Do you actually need the Edgent functionality? If so, is it just the Blynk.Ait functionality of dynamic provisioning too?

Pete.

Thank you for the Guide to use BlynkTimer, I will have a look and firgure out how to incopparate it in my existing code. I’m a bit hesistant though as I have so many delay() functions to replace…

TBH, you’d be better putting the untouched Edgent example sketch (untouched except for adding-in the two lines of firmware configuration and un-commenting the correct board type) onto a different Wemos and testing that way.

I am doing exactly this. I initially thought it was a bad D1 mini with the notorious underpowered voltage regulator (100mA peak current as opposed to the correct 500mA), but I verified that and my boards have the correct VR.

Do you actually need the Edgent functionality? If so, is it just the Blynk.Ait functionality of dynamic provisioning too?
I’m sorry but what do you mean by needing the edgent function?

You’ve chosen to use the Edgent example as the basis for your sketch.
Edgent is an extremely complex example which provides Blynk.Air (OTA updates) and Dynamic Provisioning (WiFi credentials are enter via the app, and the Auth token is allocated dynamically) as opposed to static provisioning where the WiFi credentials are hard-coded in your sketch along with your Auth token.

Why have you chosen the Edgent example as the basis for your sketch, instead of a much simpler static provisioning example?

Pete.

Interesting!
I assumed for many years now that BlynkEdgent is the libary for Blynk 2.0 and that the other examples were for Blynk Legacy… My bad for the assumption.

I do occasionally use OTA since the D1 mini is housed in a water tight encloser but I don’t mind loosing that function if it means for a more reliable system!

I don’t mind testing it with an alternate libary. Would you recommend the use of example “ESP8266_Standalone” instead? Can I simply paste the main part of my code from Edgent to this?

Yes.

If you’re careful yes, but avoid all the Edgent related stuff.
Personally, I’d start with the standalone example and get it online before going any further. Basically, if it’s not code that you’ve written then leave it out.

It’s possible to add Blynk.Air functionality into the standalone sketch, but I’d do this last of all, once everything else is working correctly.
Details here…

Pete.

Understood, This is my code and I just copy pasted the main section, avoiding Edgent code and it complied succesfully. I will flash it when I get back home and give you an update soon.
Thank you

1 Like

Greetings!
Apologies for the dissapearance, I have been busy trying as suggested and wanted to test and be absolutly sure before giving an update on my situation.

Unfortunately even after convering D pins to GPIO number and reducing the number of delays to the absoulute bare minimum, my device still goes offline. I am still trying to understand millis function which I am practicing to incoperate on another project before doing so on this project, which I can’t risk anymore failure.

I tried moving to “ESP8266_Standalone” but that too goes offline randomly and for many many hours if not days, until I unplug the power. I tried with a blank sketch, just the skeleton code with credential only ,and it still crashes (therefore hopefully concluding that it isn’t the code that is making my device go offline).

I now removed the board from its enclosure and connected it to my computer with the serial monitor open. I will leave it like this till it goes offline again and will upload any crash messages displayed.
Thank you.

You shouldn’t need to use delays at all in the vast majority of situations.

Doing a millis comparison to figure-out if an amount of time has passed isn’t the solution either, in most cases.
millis comparisons only work inside a loop, and the BLYNK_WRITE callbacks don’t loop. You could create a loop, but this would just block code executor be no better than delays, or you could do the millis comparison in the void loop, but that just clutters your void loop, which isn’t what you want either - if you want to avoid disconnections.

Using BlynkTimer is the preferred solution.

So far you’ve been talking about the device going offline, not crashing.
When it crashes what crash dump data do you see in the serial monitor, and have you tried decoding this with the ESP Exception Decoder?

Thats a sensible approach.

Is the device crashing, or simply going offline?
Have you added any code to check when it goes offline, and attempt to re-connect?

This all seems very hypothetical at the moment, because you aren’t providing hard facts and posting the code and full details of the symptoms.

Pete.

Hello Pete!
Up until today I have not logged the serial monitor as the board was in a sealed box, powered with its own power supply. As mensioned I have removed the board and currently monitoring the serial output.

I am yet to comfirm from the serial monitor output whether board is crashing or the simply going offline. However looking at the blynk app timeline, the device is mojority of the time offline for exactly 7 Hours and 42 Minutes and comes back online. Its even gone offline for 2 Days and 8 Hours.

But as I mensioned in my first post, the board is still connected to my router, I confirmed this by viewing the router admin portal.

Also the time displayed in the serial monitor is not my current time where I am living, could that possibly cause any issues?

Please see attached serial monitor when the device booted a couple of hours ago, and the app timeline.

So you’re using the Edgent example againn. Why?

Pete.

The reason is because there seemed to be absolutely no improvements when using ““ESP8266_Standalone” and secondly since the device is in an enclosure and I am tinkering with the code, trial and error changes, to try and resolve this issue, Blynk Air is extremly useful.

Well it didnt take long for the device to go offline and the serial monitor output is interesting.
As suspected before the board isnt loosing connection with the router, nor is the board crashing. It simply looses looses connnection with Blynk’s server and continously tries to establish a connection to the sever and looses it again (as seen in the 3rd attached picture).

What can be causing this? I’ve read Blynk servers will disconnect a device if it recieves spam pings, but nothing in my code will cause that?!

SM 3

Update-
The device is back only after 19 minutes.
Looking at the SM, the board doesnt crash or reboot, it just reconnects to the server after many failed
attempts

As I explained before, it’s very easy to add Blynk.Air to the standalone sketch by pasting the code in the example.

Edgent makes it extremely difficult to make any changes to the connection routines, so it’s a bad starting point for resolving this type of issue.

When you post serial output it’s far better if you copy the text and paste it with triple backticks, the same as when you post code.

The device can’t communicate with the Blynk server anymore. This is probably because daya packets that are intended for the Blynk server aren’t making it through, or your ISP is blocking them.
You could try using port 80 (far easier when you use the non-Edgent) examples) and possibly try turning-on Blynk debugging or Core Debugging (in the IDE).

Pete.

Understood, I will revert back to non edgent Blynk. I am not too keen about Blynk Air at the moment since the board is connected to my computer and as you mensioned earlier, I should focus fixing this before trying to incopperate Air to the code.

Thank you for the SM suggestion, I will keep that in mind

May I know how to change the port to 80 and turn on Blynk debugging for non-edgent sketches?

If you use the “Blynk simple” library files that don’t have “SSL” in their names the port 80 will be used.

Pete.

1 Like

ESP_WiFi Sketch

/*************************************************************
  Blynk is a platform with iOS and Android apps to control
  ESP32, Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build mobile and web interfaces for any
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: https://www.blynk.io
    Sketch generator:           https://examples.blynk.cc
    Blynk community:            https://community.blynk.cc
    Follow us:                  https://www.fb.com/blynkapp
                                https://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP32 chip.

  NOTE: This requires ESP32 support package:
    https://github.com/espressif/arduino-esp32

  Please be sure to select the right ESP32 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill in information from Blynk Device Info here */
//#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
//#define BLYNK_TEMPLATE_NAME         "Device"
//#define BLYNK_AUTH_TOKEN            "YourAuthToken"


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

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

Would this be an example I could you?

Yes.

Pete.

1 Like

Pete isnt “ESP32_WiFi” similar and “ESP8266_Standalone” both using port 80?
If so then I already tried “ESP8266_Standalone” and it still seemed to go offline.
However I will anyways reupload the “ESP8266_Standalone” tonight and hopefully I will wake up and see that the device is still online :confused: