Receive Serial Message While Connecting to Cloud

Hi there,

My Electron sits on a place where the cellular signal is very weak, so it takes minutes to connect to the cloud.

While it is connecting, it seems my application code is blocked. In the code, I try to read Serial messages from an Arduino board. Even after I enable the SYSTEM THREAD, I still cannot receive the Serial messages when Electron is connecting to the cloud.

I am thinking to use Semi-automatic mode instead of Automatic mode, but it seems that the user code will be blocked in the same way when I call “particle.connect()”.

Is there any way for me to receive Serial messages and then make Electron sleep while it is connecting to the cloud?

Thanks.

Is there any way for me to receive Serial messages

Yes, you need to do two things:

  • Add SYSTEM_THREAD(ENABLED)
  • Make sure you don’t call anything from loop() that will block.

The second part includes (but is not limited to):

  • Particle.publish()
  • Cellular.RSSI()

Also don’t call Particle.connect() more than once.

then make Electron sleep while it is connecting to the cloud?

That is not possible. The microcontroller stops running in sleep mode, and cannot control the modem to complete the connection process.

@rickkas7 Thank you. But I don’t know what you mean. Do you mean I must include “Particle.publish()” or “Cellular.RSSI()” in the user code? What is the reason?

BTW, I tried the SYSTEM THREAD. But it made no difference. The user code is still blocked while Electron is trying to connect to the cloud.

No, you must not call Particle.publish or Cellular.RSSI(). Possibly other calls, when not connected to the cloud.

The most likely possibilities are:

  • You didn’t successfully enable system thread
  • There’s some code in your loop that’s blocking the loop, preventing your code from processing the serial port

It’s impossible to say without the code.

1 Like