Code works if USB connection from computer, but not if USB power from wall

I had a similar issue today and managed to fix it. Hoping this post helps anyone else in the same boat.

My code doesn’t use HTTP posts’s but rather I use SEMI AUTOMATIC and a finite state machine (FSM) to control the connection, based on code from @rickkas7 (thank you!).

Issue was that in my code the Electron was rebooting after calling Cellular.on().

I have external circuitry on a carrier board that accepts 12v input and regulates down to 5v for the Electron. When I had plugged in external power AND the usb cable for serial.print debugging the Cellular.on() call worked fine. BUT once I removed the usb cable and powered only from the DC external adapter the Electron would reboot immediately after calling Cellular.on(). Weird.

I initially thought must be 5v USB related but triple checked all my schematics and I’m not using 5V from the USB anywhere.

Adding a small non-blocking delay of 500ms after Cellular.on and before the next command fixed the issue for me. Not sure how this is related to USB but glad it worked. It works fine now running off just the external power.