I am running an application built on spark firmware 0.6.1 on a Electron
I have SYSTEM_THREAD(ENABLED)
When I call Particle.publish()
, sometimes that call blocks for seconds on end. Here is my code:
myLog.info("Particle.publish()");
Serial.flush();
uint32_t microsBefore = micros();
bool returnVal = Particle.publish(eventName, eventData, ttl, PRIVATE);
myLog.info("Publish blocked for %lu us", (micros() - microsBefore));
And here is example of the output from this code:
[Wed Apr 04 10:59:14.569 2018] 0000143132 [app.myParticle] INFO: Particle.publish()
[Wed Apr 04 10:59:14.574 2018] 0000143133 [comm.coap] TRACE: sending message id=43
[Wed Apr 04 10:59:14.574 2018] 0000143134 [system] TRACE: send 78
[Wed Apr 04 10:59:14.574 2018] socketSendTo(0,54.157.249.252,5684,,78)
[Wed Apr 04 10:59:14.574 2018] 143.128 AT send 37 "AT+USOST=0,\"54.157.249.252\",5684,78\r\n"
[Wed Apr 04 10:59:16.751 2018] 145.309 AT read > 3 "\r\n@"
[Wed Apr 04 10:59:16.802 2018] 145.359 AT send 78 "\x17\xfe\xfd\x00\x01\x00\x00\x00\x00\x00S\x00A\x00\x01\x00\x00\x00\x00\x00S9\xfeq\x8f\xd0\x90/\xdf>\\\xd6x\x1a\xf7\x03\xa1\x1a\xb1t\xa2\x8bp\xa3\xd6\xcb\xcer\xd1\xdb\xda\xb7us\x90t\xd3\xecS6\x19\xf1\x82\xd9Vb8#\x811}!\xfd\t\x8b\xac\xe84"
[Wed Apr 04 10:59:16.943 2018] 145.501 AT read + 16 "\r\n+USOST: 0,78\r\n"
[Wed Apr 04 10:59:16.953 2018] 145.511 AT read OK 6 "\r\nOK\r\n"
[Wed Apr 04 10:59:16.955 2018] 0000145517 [app.myParticle] INFO: Publish blocked for 2384064 us
[Wed Apr 04 10:59:16.982 2018] 0000145544 [app.main] WARN: Latency: app.UI_Manager (2668 ms)
It appears that spark firmware is blocking while waiting for the modem to respond.
It also appears that the millis() timestamps of the system messages above are out of order… which is highly suspicious. Specifically, this sequence doesn’t make sense timestamp-wise:
[Wed Apr 04 10:59:14.574 2018] 0000143134 [system] TRACE: send 78
[Wed Apr 04 10:59:14.574 2018] socketSendTo(0,54.157.249.252,5684,,78)
[Wed Apr 04 10:59:14.574 2018] 143.128 AT send 37 "AT+USOST=0,\"54.157.249.252\",5684,78\r\n"
Is this working as intended? I thought spark firmware uses interrupts to wait for modem responses…
In the above example, this blocks my app from running for 2.5 seconds! If this is functioning as intended, it would seem that I will have to queue all my publishing to happen overnight so as not to block my app’s UI from running… which isn’t acceptable…
Update:
Also tried using the Particle.publish(eventName, eventData, PRIVATE, NO_ACK);
function signature with the same results.