Device is turning off after about a day

I have a project that’s running on a wemos d1 mini, and it seems like it’s turning itself off after about a day.

Any ideas why? Could it some error? Maybe it’s because I left prints in the project? I don’t have any explicit sleep commands in the code.

Is there a way to see a log or stack trace? the device is connected to the power all the time

PS: I know this isn’t Wemos’ forum but their forum is dead and it’s popular here.
PPS: again a log in Blynk would be very helpful, maybe you could offer this as a feature?

What you mean by that? No network/serial port activity? Or just disappears from network and Blynk server?
There is a loging feature in Blynk. It’s serial LOG with possibility to turn on DEBUG messages

In my experience device lockup’s (I assume that’s what you’re experiencing) are usually caused by bad coding or a poor quality power supply.

Post your code (correctly formatted) and more info on the suysmptoms you’re experiencing.

Pete.

https://pastebin.com/SYRcwF41

char auth[] = "";
char ssid[] = "";
char pass[] = "";
 
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations
#define BLYNK_NO_FLOAT     // Disable float operations
 
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
 
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
 
extern "C" {
  #include "user_interface.h"
}
 
IRsend irsend(D3);  
BlynkTimer timer;
 
int khz = 38;
uint16_t ACOnColdCode[] = {8936,4440,704,1576,716,480,656,536,660,1624,656,1624,656,1628,652,540,660,536,656,1624,660,1624,656,540,652,540,660,536,656,536,656,540,652,540,652,544,660,536,656,536,656,540,652,1628,652,1632,660,1620,660,536,656,536,656,540,652,544,660,532,656,1628,652,540,652,1632,652,540,660,536,656,1624,656,540,652,19836,656,536,656,540,652,540,652,544,660,532,688,508,684,508,684,512,680,516,688,504,688,508,684,508,684,512,680,1600,660,536,688,504,688,512,680,512,680,512,688,508,684,508,684,512,680,520,684,504,688,504,688,508,684,512,680,512,692,504,688,504,688,508,684,1596,684};
uint16_t ACOffCode[] = {8964,4412,660,1624,656,536,656,540,656,540,648,1632,660,1624,660,532,660,536,688,1592,688,1596,652,540,684,512,680,516,688,504,688,508,684,508,684,512,680,512,684,512,688,508,688,504,688,1596,684,1596,684,512,680,512,692,504,688,504,688,508,684,1596,688,508,684,1600,680,512,680,516,688,1592,688,508,684,19800,688,508,684,512,680,512,680,516,688,504,688,508,684,508,684,512,680,512,680,516,676,516,688,508,684,512,680,1600,684,512,680,512,688,508,684,508,688,508,684,508,684,512,680,516,688,504,688,508,684,508,684,512,680,516,688,504,688,508,684,508,684,512,680,512,680};
uint16_t ACOnHotCode[] = {};
uint16_t FanToggleCode[] = {1324,356,1304,376,440,1248,1272,408,1272,416,432,1260,440,1256,444,1252,492,1208,440,1256,440,1252,1280,6968,1272,404,1304,376,476,1212,1304,376,1304,384,468,1228,440,1256,444,1252,436,1260,440,1256,444,1252,1308,6920,1308,372,1300,380,468,1220,1300,380,1300,388,472,1220,468,1228,472,1224,476,1224,464,1232,468,1228,1300,6944,1308,368,1300,380,472,1216,1300,380,1300,388,472,1224,464,1232,468,1228,472,1224,468,1228,472,1224,1304,6952,1300,376,1300,380,472,1216,1300,380,1300,388,464,1228,472,1224,476,1220,468,1232,468,1228,472,1220,1308};
uint16_t BiasLightOn[] = {9150,4400, 600,550, 600,500, 600,550, 600,550, 600,500, 600,550, 600,500, 650,500, 600,1650, 550,1650, 600,1600, 600,1650, 600,550, 600,1600, 650,1550, 650,1600, 650,1550, 650,1600, 600,500, 650,500, 650,500, 600,500, 650,500, 600,500, 650,500, 650,500, 600,1600, 650,1550, 650,1600, 600,1600, 650,1600, 600,1600, 650};
uint16_t BiasLightOff[] = {9150,4400, 600,500, 600,550, 600,550, 600,500, 600,550, 600,500, 600,550, 600,550, 600,1600, 600,1650, 600,1600, 600,1600, 650,500, 650,1600, 600,1600, 650,1550, 650,500, 650,1550, 650,500, 650,500, 600,500, 650,500, 600,500, 650,500, 650,1600, 600,500, 650,1600, 600,1600, 650,1600, 600,1600, 650,1550, 650,1600, 650};
bool preventBiasLightToday = false;
 
void SendIRCommand(uint16_t* IRCommandArray, uint16_t len){
  irsend.sendRaw(IRCommandArray, len / sizeof(IRCommandArray[0]), khz);
  // indicate on control led that a transmission is ongoing
  turnControlLedOn1Sec();
}
 
/// region bias light
 
void CheckTurnBiasLightOn(){
  timeClient.update();
  int currHour = (timeClient.getHours() + 2) % 24;
 
  if(currHour > 6 && currHour < 22 && !preventBiasLightToday){
    SendIRCommand(BiasLightOn, sizeof(BiasLightOn));  
  }
}
 
void preventBiasRelight(){
   preventBiasLightToday = false;
}
 
void toggleBiasLight() {
  Serial.print("BiasLight");
  if(preventBiasLightToday){
    Serial.println(" on");
    SendIRCommand(BiasLightOn, sizeof(BiasLightOn));
  }
  else{
    Serial.println(" off");
    timer.setTimeout(21600000, preventBiasRelight);
    SendIRCommand(BiasLightOff, sizeof(BiasLightOff));  
  }
  preventBiasLightToday = !preventBiasLightToday;
}
 
// BiasLight
BLYNK_WRITE(V7)
{
  int pinValue = param.asInt();
  if(pinValue == 1){
    toggleBiasLight();
  }
}
 
/// endregion bias light
 
// ACOnCold
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();
  if(pinValue == 1){
    //ACOnCold();
    timer.setTimer(500, ACOnCold, 3);
  }
}
 
// enter area
BLYNK_WRITE(V5)
{
  Serial.println("enter area");
  int pinValue = param.asInt();
  if(pinValue == 1){
    timer.setTimer(500, ACOnCold, 3);
  }
}
 
void ACOnCold(){  // todo to be refactored
  Serial.println("ACOnCold");
  SendIRCommand(ACOnColdCode, sizeof(ACOnColdCode));
}
 
// ACOff
BLYNK_WRITE(V2)
{
  int pinValue = param.asInt();
  if(pinValue == 1){
    SendIRCommand(ACOffCode, sizeof(ACOffCode));
    Serial.println("ACOff");
  }
}
 
// exit area
BLYNK_WRITE(V8)
{
  Serial.println("exit area");
  int pinValue = param.asInt();
  if(pinValue == 1){
    SendIRCommand(ACOffCode, sizeof(ACOffCode));
    Serial.println("ACOff");
  }
}
 
// ACOnHot
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt();
  if(pinValue == 1){
    SendIRCommand(ACOnHotCode, sizeof(ACOnHotCode));
    Serial.println("ACOnHot");
  }
}
 
// fanToggle
BLYNK_WRITE(V4)
{
  int pinValue = param.asInt();
  if(pinValue == 1){
    SendIRCommand(FanToggleCode, sizeof(FanToggleCode));
    Serial.println("fanToggle");
  }
}
 
// control led
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if(pinValue == 1){
//    turnControlLedOn1Sec();
    toggleControlLed();
  }
}
 
bool controlLedToggle = false;
void toggleControlLed(){
  if(controlLedToggle){
    turnControlLedOn1Sec();
    timer.setTimeout(1000L, turnControlLedOff);
  }
  else{
    turnControlLedOff();
  }
  controlLedToggle != controlLedToggle;
}
 
void turnControlLedOn1Sec(){
  Serial.println("turnControlLedOn1Sec");
  digitalWrite(LED_BUILTIN, LOW);
  timer.setTimeout(1000, turnControlLedOff);
}
 
void turnControlLedOff(){
  Serial.println("turnControlLedOff");
  digitalWrite(LED_BUILTIN, HIGH);
}
 
void setup()
{
  Serial.println(ESP.getResetInfo());
//  Serial.println(ESP.getResetInfoPtr());
  pinMode(D3, OUTPUT);
  digitalWrite(D3, LOW);  
  pinMode(BUILTIN_LED, OUTPUT);     // set onboard LED as output
  digitalWrite(BUILTIN_LED, HIGH);  // led logic is inverted
  // Debug console
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
 
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
 
  irsend.begin();
 
  //  Force the ESP into client-only mode
  WiFi.mode(WIFI_STA);
 
  //  Enable light sleep
//  wifi_set_sleep_type(LIGHT_SLEEP_T);
 
  timeClient.begin(); // to turn on the bias light in the morning automatically
  CheckTurnBiasLightOn();
  timer.setTimer(1800000, CheckTurnBiasLightOn, 1);
 
  Blynk.syncAll();
}
 
void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
 
}

I added the blynk debug and Serial.println(ESP.getResetInfo()); just now.

I didn’t check in the router to see if it’s still connected but I see in the Blynk app that it was disconnected.

Have you tried without putting the ESP into Light Sleep mode? Try that just for test purpose.

How?

This // wifi_set_sleep_type(LIGHT_SLEEP_T); is commented BTW.

Ah, ok then…

Make sure you are not running out of timer slots…

1 Like

Good point.

This can be monitored with this command: timer.getNumTimers();

Running on another timer loop of course :stuck_out_tongue: perhaps like this

  // Timed Lambda Function - Active timer counter
  timerCheck.setInterval(1000L, []() {  // A new timer named timerCheck runs every second
    Blynk.virtualWrite(vPin, timer.getNumTimers());  // Displaying the # of active timers named "timer"
    Serial.println(timer.getNumTimers());  // Printing the # of active timers named "timer"
  });  // END Timer Function

1 Like

Wait every time I do setTimer and setTimeout it defines a new timer slot and it isn’t being released on its own?

They should release when finished… but depending on how you call them, they can actually double/triple up if recalled before finishing. Adds up if you have a few going and/or some button mashing.

they way i read the docs, it is supposed to - but in reality it does not seem that this is always the case…

its that kind of stuff that can really drive you bonkers when debugging an issue.
However I understood that BlynkTimer had dealt with issues like that, that were present in SimpleTimer - which is one of the reasons to switch.

@Yamashiro, let us know what you’re findings are on this, I’m curious. Also instead of using a ‘timed’ timer check as @Gunner suggested, you alternatively could consider to add this line:

Serial.print(String("Active timers: ") + timer.getNumTimers());

after every timer you initiate and keep an eye on the Serial output.

or a bit more fancy:

if(timer.getNumTimers() > 15){ Serial.print(String("DANGER WILL ROBINSON, current No of initiated timers exceeds safety limits: ") + timer.getNumTimers());}

(irc, max timers originally was 10 and has been upped to 20 in blynktimer, but I might be wrong-ish there)

Up to 16 per named timer instance.

well, then i at least was spot on with my if >15 :sunglasses:

that’s actually a quite interesting remark! I’ve never though of the possibility to initiate more than one timer, but its quite obvious now you mention it and a nice possible workaround if you ever get stuck in that corner!

1 Like

OK, I got a log with an exception, I have a feeling it’s some kind of memory leak in Blynk library because it hapeens after several login retries, maybe @Gunner will know.

The numbers are the amount of timers (I used only 1 timer in the code so 1 is what print this), it looks like the heap is fine though.

log: https://hastebin.com/awajiyovav.vbs (pastebin is under heavy load now and it’s too long to paste here)

Nope… but then I am not a developer :stuck_out_tongue: However, it is unlikely a Library issue else there would be many more indications from the thousands of other users.

There are some certificate errors too, which aren’t that common i think… The decreasing heap is clearly visible, but that might be an ESP Arduino core issue too.

What?! you’re not a Blynk dev? But you’re all over the forum and for a long time too.

1 Like

Hehe, meet the @Gunner then - the most helpful hand on this forum :smiley:

1 Like