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.
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:
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:
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
you should definitely upgrade to latest arduino ide
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:
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.
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
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?
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.