Serial Stops in FSM AppNote

Hello,

I believe there might be a serial logger bug related to sleep whenever we sleep. Using switch case methodology from the appnote below, my serial logger completely falls apart after sleeping.
https://docs.particle.io/datasheets/app-notes/an010-finite-state-machines/#04-case-function

My firmware project is based on this FSM, so I though it was related to my code but when I reduced it back to this example, the problem still persists.

Here is a serial log:

....
0000022817 [system] INFO: Cloud connected
0000022818 [app] INFO: connected to the cloud in 22529 ms
0000022818 [app] INFO: about to publish {"a0":273}
0000023566 [app] INFO: successfully published {"a0":273}
0000023567 [app] INFO: going to sleep for 20 seconds
0000044204 [app] INFO: successfully published {"a0":273}
0000044204 [app] INFO: going to sleep for 20 seconds
0000065425 [app] INFO: successfully published {"a0":276}
0000065425 [app] INFO: going to sleep for 20 seconds
....

Notice how following statements never occur even though the device is waking??

  • Log.info(“woke from sleep”)
  • Log.info(“connected to the cloud in %lu ms”, millis() - stateTime)

On my personal firmware project, the serial never recovers. So I dont even get half of the messages after waking. There seems to be some magical pattern of events that fix it for this state machine code (since the last two printouts occur) but I don’t see any obvious reasons. If I add two random delay(500); calls after waking, that sometimes causes more post-sleep printouts to occur but its not a solution.

Are you using USB serial or UART serial? It can take anywhere from 2 to 10 seconds for USB serial to reconnect after sleep mode, and the logging messages will be lost during that time period, unless you wait for Serial.isConnected().

If you are debugging code where you need to read the log messages immediately after wake, you will probably want to use UART serial with an adapter, because the UART serial port can remain open during sleep.

Thanks ricckas, yeah I am using USB serial.

I will set your answer as the solution after I confirm with an FTDI adapter.

Warm regards.