Using the techniques described in this topic (How to force a handshake for OTA updates) to get a firmware update to happen I could never get the above disableUpdates
, System.on(firmware_update_pending, ...)
, enableUpdates
to work. I correctly get notified that updates are pending and re-enable them but they fail every time:
0000032633 [comm.protocol.handshake] INFO: Sending HELLO message
0000033248 [comm.protocol.handshake] INFO: Handshake completed
0000033250 [system] INFO: Send spark/device/claim/code event
0000033474 [system] INFO: Send spark/device/last_reset event
0000033693 [system] INFO: Send subscriptions
0000033908 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000033908 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000033909 [comm] INFO: Sending TIME request
0000034217 [comm.protocol] INFO: Sending 'M' describe message
0000034446 [comm.protocol] INFO: rcv'd message type=1
0000034446 [system] INFO: Cloud connected
0000034446 [app] INFO: sent 2 events
0000034508 [comm.protocol] INFO: rcv'd message type=13
0000034720 [app.state.ModemControl] INFO: Transition: connecting -> syncing
0000034761 [comm.protocol] INFO: rcv'd message type=13
0000034871 [comm.protocol] INFO: Sending 'S' describe message
0000035156 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000035165 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000035165 [comm.protocol] INFO: rcv'd message type=1
0000035228 [comm.protocol] INFO: Received TIME response: 1540409570
0000035229 [comm.protocol] INFO: rcv'd message type=12
0000035229 [app.syncTime] TRACE: timeSyncedLast: 35228ms
0000035231 [app.metricsPublisher] TRACE: Added new entry (now length 62 bytes):
1540409570,4.07,83.8,0,0.000530208,0.000125,0,0,0,0,0,0,0,0,0
0000035328 [comm.protocol] INFO: rcv'd message type=13
0000035631 [comm.protocol] INFO: Sending 'A' describe message
0000035863 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000035863 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000035864 [comm.protocol] INFO: rcv'd message type=1
0000035864 [app.metricsPublisher] TRACE: Returning next event of 1 entries (61 chars)
0000036513 [app.deferredUpdate] INFO: Firmware update pending!
0000036575 [comm.protocol] INFO: rcv'd message type=13
0000036575 [comm.protocol] INFO: rcv'd message type=5
0000036576 [app.metricsPublisher] INFO: Published 61 chars, 0 bytes remaining
0000036576 [app.deferredUpdate] INFO: Re-enabling firmware updates
My messages of Firmware update pending
is receiving the pending update system event. And I then System.enableUpdates()
. But then nothing else is ever received from the cloud and the update fails every time.
So to handle this, if I get stuck waiting for the update that’s never going to arrive I Particle.publish("spark/device/session/end", PRIVATE | WITH_ACK)
(to force a handshake next reboot) and then System.reset(FRESH_BOOT_RESET_MAGIC)
. When it reboots, in my setup()
code where I normally System.disableUpdates()
I instead check for System.resetReasonData() == FRESH_BOOT_RESET_MAGIC
and if so I don’t disable updates, connect to the cloud, and wait for the update to come. That seems to work.
Hopefully this will save someone else the somewhat painful journey I’ve just been on.