Blynk crashes frequently

obvious question, but have you added your twitter login to the widget and done the twitter authorisation thing?

Totally reasonable question, and yes. The widget says ā€œ[twitter acct] connectedā€ when you tap on it when the app isnā€™t running.

ā€¦and it crashed within a few minutes of starting. Getting frustrated. Iā€™m going to leave it alone for a while.

many people have many personal definitions of crashed

to me - my app has ā€œcrashedā€ when i see in the serial monitor output it has restarted itselfā€¦

if it doesnā€™t respond to buttons presses, my app is ā€œlaggingā€ - not ā€œcrashedā€

can you describe what you mean when you say crashed?

what happens if you change the above to this:

void TempLoop()
{
  // Read DHTs and push to Blynk app
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  t1 = dht1.readTemperature();
  t1F = (int)(1.8 * t1) + 32;
  Blynk.virtualWrite(V0, t1F);
  timer.setTimeout(2000, tempLoop2);

}
void tempLoop2()
{
  t2 = dht2.readTemperature();
  t2F = (int)(1.8 * t2) + 32;
  Blynk.virtualWrite(V1, t2F);
  timer.setTimeout(2000, tempLoop3);
}

void tempLoop2()
{
  t3 = dht3.readTemperature();
  t3F = (int)(1.8 * t3) + 32;
  Blynk.virtualWrite(V2, t3F);
  
  taveF = (int)((t1F + t2F + t3F) / 3);
  Blynk.virtualWrite(V3, taveF);
}

Well, letā€™s find out. Iā€™ve loaded it up. Iā€™ll check in the morning, but it has been running for 20 minutes.

I also ordered an ESP8266 shield to replace the CC3000.

The app keeps running, but it is no longer receiving data from the hardware. The control no longer send data to the hardware, either. Pushing buttons results in an ā€œArduino UNO Offlineā€ error. So it isnā€™t lagging, it has ceased to function even though the app continues to operate.

It didnā€™t work. It crashed after running for a few hours. I restarted the hardware in the morning and it crashed again within minutes. Thanks for the suggestion, though.

So what does the serial monitor output show?

hi!

your sketch is very large and confusing (at least for me). i would recommend a different debug approach:

create a completely new sketch.
in this new sketch use ONLY the strictly necessary communication part of the code, and with simple timer create just a single ā€œuptimeā€ widget, which sends the hw uptime every second to your phone (use push). and see if it works stable for long time. something like this:

#include <BlynkSimpleSerialBLE.h>
#include <SimpleTimer.h>

char auth[] = "xxxxxxxxxx";

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  timer.setInterval(1000L, uptime);
}

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

void uptime()
{
  Blynk.virtualWrite(V0, millis() / 1000);
}

yes, this is not for your hw, it is for ble. but you got the idea. try to do something such basic sketch. and see if it works. if you canā€™t get a long uptime with this, it has no reason further complicate your code with irrelevant functions.

if it works, then try to add step by step a little extra functionality, until it begins to behave badly. just add some code, compile, and wait. if it works, ad some more. at the moment it begins to crash, you should look very closely what was added since the last stable version. the bug will be thereā€¦

also, other thing: i do not know your hw at all, but once i had a very similar problem, random crashes with arduino + enc28j60 ethernet module. after lots of debugging i just find out, that the power source was poor quality, and the fluctuations caused the ethernet module to crash (the code on the arduino worked ok). and since blynk keeps blocking if there is no internet connection, the whole hw becomes unresponsive. after i replaced the 3.3v source for the enc28j60 module, everything worked ok. iā€™m not telling this is the same problem as yours, just worth checking, if nothing else helps, to replace the power source.

EDIT:

  1. hm, if i compile your sketch for arduino uno (your hw has the same atmega328, so it is basically the same) iā€™ve got this:

    Sketch uses 26098 bytes (80%) of program storage space. Maximum is 32256 bytes.
    Global variables use 1468 bytes (71%) of dynamic memory, leaving 580 bytes for local variables. Maximum is 2048 bytes.

the sketch size is not a problem, but 71% used by global variables is not very good! this CAN cause the random crashes, especially if you are using heap (i do not have the patience to check all your code for this, but you should!)
also, please read this excellent article about mcu memory architecture here:

if you read and understand all chapters, you should have a clear image what iā€™m trying to explain. also, there is a way to measure / monitor the free sram during runtime, to see if you are actually running out of ram. (if you upgrade to wemos d1 mini pro, as @Costas recommended, you can get rid about the flash / ram problems, because wemos has a lot :slight_smile:

  1. you should definitely upgrade to latest arduino ide

  2. probably it has nothing to do with the current problem, but try to add L after the values bigger than 32000 in your simple timer functions:

1 Like

Iā€™ll snag the output next time I test it. This project is on hold for a few days until I receive a ESP6866 wifi shield to replace the CC3000.

Howdy wanek

Thank you for all the time you put into that response. I read that article on memory a while back, and it is making a lot more sense to me reading it again. Helps to be further up the learning curve.

When I wrote this code I did something similar to what you described. I wrote the whole thing, but left most of it commented out. I un-commented one part at a time and debugged that part until it worked. I had it all running smoothly, or so I thought. I do like the idea of passing communication off once a second to the app. Iā€™ll give that a go. And Iā€™ll add the Lā€™s. And Iā€™m going to work on cutting down the memory. I donā€™t know how to check for heap use, but Iā€™ll sort that out. My suspicion is that this is either a problem with the CC3000 or a memory issue. Iā€™ve ordered an ESP6866 shield to replace the CC. Iā€™ll work on memory issues as well.

Thanks again for the valuable input.

1 Like

i really hope you will find the source of the problem.

as for the free ram monitoring, there is a function example in the adafruit article, which describes how to monitor the remaining free ram. maybe it could be useful. i used once.

also, another thing (off topic), not just for youā€¦
for a much transparent / better / easier coding, i recommend to use tabs in the arduino ide. as i observed, very few people know how to use properly the arduino ide, and this functionality is not well documented. as limited and dumb as is the official ide, but one can be more productive using these tabs!

the basic idea is, that you should write EVERY function in a separate tab. (for convention, i always use the exactly same name for the function and for the tab name. this is how i learned in object oriented php :slight_smile:

could be awkward in the beginning, but very soon one will realise how much easier it is to manage a large project, using tabs. everything is well explained here, please read: https://liudr.wordpress.com/2011/02/16/using-tabs-in-arduino-ide/

2 Likes

legendary!! :heart_eyes:

i heard about the ā€˜tabsā€™ thing a while back, but forget, you prompted me to find it.

itā€™s /hidden/ here:

DOH - just found that Ctrl + Alt + Left rotates my screen, it does not switch IDE tabsā€¦ how annoyingā€¦ any solution?

1 Like

maybe you should disable screen rotate hotkeys, i assume youā€™re not rotating your screen every day??

1 Like

I have made changes to the memory allocations, assigning consts to PROGMEM, paring down some items to byte from int, and using #define for a few things. The compiled SRAM memory is now down to 49%. Is that a generally reasonable number to generate stable code?

Thanks for your help!

afaik, anything under 65-70% should be ok.
you still have the crashes?

1 Like

Havenā€™t tried yet, but will soon. Iā€™ll have an update.

@q_mech, any progress on this? iā€™m just curious if you found the problem, what was that?

I have made some changes to the code to lessen the dynamic memory use, and got it down to about 50%. I purchased an ESP 8266 shield from Sparkfun and thatā€™s where I am right now. When I try to run the new code I get a ā€œFailed to disable Echoā€ error. Iā€™m chasing down that now.