Blynk crashes frequently

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.

I swapped out the CC3000 for an ESP8266 only to have it crater on me. Before I buy another one, let me ask this - what is the best option for hardware?

I am using a RedBoard with a wifi shield. I chose this route because I need the hardware to keep running even if it loses contact with my phone for an extended period of time. So a setup that simply responds to the phone app won’t cut it.

First option - let’s assume I keep the RedBoard. What is the best wifi option?

Second option - if we ditch the RedBoard, is there a better option than the above?

I’d go for the Wemos any day. Since @Costas introduced us to that … it’s so easy in usage and so cheap. The only thing is it has only one analog port, but you can buy a simple multiplexer for that.

1 Like

Wish I’d known that to start with. But now I’d have to rewrite all my code, come up with a 3.3V power supply, and its not clear to me if I would have enough free D lines for all nine of my digital input and output lines. Got any ideas for a shield or breakout for a Redboard/UNO instead?

I think the UNO has plenty of digital ports, right?

I swapped out the CC3000 for an ESP8266, which bricked on me. I’m on my second ESP, and can’t get past a “Failed to Read Echo” error. Getting pretty fed up with this.

Do you mean “Failed to Disable Echo”? If so, I found this recent post for ESP8266 on Uno… might work for you?

And it isn’t clear if you figured out the Twitter issue. I am guessing you are using Cloud Server? If not, then Twitter will not work on Local Server. Also there may be an issue with twitter on IOS.

1 Like

I hope you’re not feeding 5v in to the ESP TX/RX pins… the UNO is 5v and the ESP can only take up to 3.7v before burning out.

You really need to get yourself an ESP8266 dev board like the WeMos D1 Mini or NodeMCU clone… then you can ditch the UNO and use a multiplexer.