Core continuously resets [SOLVED]

After flashing my program the core works correctly for 5-15 seconds, then the RGB LED starts ‘stuttering’ and blinking irregularly, then the core resets and cycles - this happens indefinitely. I triple-checked my program - nothing special there or any bug that might cause that. I also tried factory reset and reclaiming the core, but after flashing my program I get the same issue.
What should I look for? What might cause that?

here’s a link to the video showing the RGB LED behaviour (my program starts when the RGB is lit in constant red and dies when it starts stuttering):

The core flashes the main LED red for a variety of program errors. It looks you are having a hard fault which is typically when your program follows a wrong pointer or tries to something illegal.

If you can post your code here, we can help you debug it. If you enclose the code in three grave accents on a separate line, above and below the code, it will format nicely. Even better, add cpp after the three grave accents on the top line above your code to get C/C++ formatting.

Just a random guess, but this reminds me of a gotcha I encountered early on. It turns out that you must allow your loop() function to fall through. No while(1) { ... } forever loops in there. Unlike the Arduino, your main loop must exit regularly for other things to happen in the background.

Hope that helps. If not, then do indeed post your code. @bko will sort you out. :smile:

1 Like

no, haven’t got while(1) in my loop()…
I’ll post the code via github

here we go:

code uses a JSON parser:

(but it crashes even before receiving a command so it’s not the issue)

Let me know what are your insights
thanks so much

OK, so a couple of things jump right out.

  • returns the day of the month 1-31, not the day of the week. You want Time.weekday() for that. Given how we are at the end of the month, who knows where you program tried to read from!

  • You malloc the configStr but you never free() it so you might as well just declare that statically. Doing a lot of malloc/free on the JSON string will eventually run the core out of RAM since the memory manager is not perfect. Normally in embedded programming like this, we try to avoid malloc as much as possible.

oops, the weekday() was dum… lack of attention
also decided to reuse the configStr as the jsonStr (as it is being updated anyways) to save memory.

Thanks so much!! It’s working perfectly now

this project has also an iOS app client for setting the timed remote function.
do you think this project is a good candidate for being presented under ‘projects’ for


Hi @idok

Glad to hear that fixed it! Yes, yes, yes! You should write up your project here under “projects” and also on where a lot of other Spark projects are already.

It looks really cool!

Thanks so much!
I will prepare proper documentation and a 3rd repo with the electronics BOM and wiring diagram!