System manual mode using particle process in seperate thread

Can System manual mode be used in-conjunction with calling particle.procoess in a separate thread?

I wouldn’t see why not, but why do you ask?
Have you tried it and it didn’t work?
With SYSTEM_THREAD(ENABLED) there is little need to call Particle.process()

I was looking doing and would just call particle process in a seperate thread frequently so I dont have to call it through out the code. How frequently should it be called? like every 100ms?

I havnt tried it yet though.

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(MANUAL);

I just tried to do the above but now the cellular doesnt conntect below are the logs. Do you have any idea why its not connecting when in manual mode?

52 [system] TRACE: Connection attempt to 34.237.141.248:5684
0000017952 [system] INFO: Cloud socket connected
0000017954 [system] INFO: Starting handshake: presense_announce=0
0000017954 [comm.protocol.handshake] INFO: Establish secure connection
0000017978 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000023150 [comm.protocol.handshake] INFO: Sending HELLO message
0000023469 [comm.protocol.handshake] INFO: Handshake completed
0000023534 [system] INFO: Send subscriptions
0000023591 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000023591 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000023591 [comm] INFO: Sending TIME request

[ Modem::getSignalStrength ] = = = = = = = = = =0000023685 [comm.protocol] INFO: Posting 'M' describe message
0000023737 [comm.protocol] INFO: rcv'd message type=1
0000023737 [system] INFO: Cloud connected
0000023749 [system] INFO: Cloud: connecting
0000023780 [comm.protocol] TRACE: Reply recieved: type=2, code=0
0000023780 [comm.protocol] INFO: message id 10 complete with code 0.00
0000023780 [comm.protocol] INFO: rcv'd message type=13
0000023805 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000023805 [system] INFO: Loaded cloud server address and port from session data
0000023933 [system] TRACE: Connection attempt to 34.237.141.248:5684
0000023933 [system] INFO: Cloud socket connected

[ Modem::getSignalStrength ] = = = = = = = = = =0000023963 [system] TRACE: SPARK_WLAN_RESET || SPARK_WLAN_SLEEP || spark_cloud_socket_closed() || cloud_socket_aborted
0000023964 [comm.protocol] ERROR: Event loop error 3
0000023964 [system] WARN: Communication loop error, closing cloud socket
0000023964 [system] INFO: Cloud: disconnecting
0000023965 [comm.protocol] ERROR: Event loop error 18
0000023965 [system] WARN: Communication loop error, closing cloud socket
0000023965 [system] INFO: Cloud: disconnecting
0000023967 [system] INFO: Cloud: disconnected
0000023966 [system] INFO: Cloud: disconnected
0000023979 [system] INFO: Cloud: connecting
0000023980 [system] INFO: Cloud: connecting
0000023998 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000023998 [system] ERROR: Failed to load session data from persistent storage
0000024001 [system] INFO: Discarding session data
0000024001 [system] TRACE: Resolving xxx.udp.particle.io
0000024005 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000024005 [system] ERROR: Failed to load session data from persistent storage
0000024007 [system] INFO: Discarding session data
0000024007 [system] TRACE: Resolving xxx.udp.particle.io
0000024635 [system] INFO: Resolved xxx.udp.particle.io to 52.90.182.92
0000024757 [system] TRACE: Connection attempt to 52.90.182.92:5684
0000024757 [system] INFO: Cloud socket connected
0000024759 [system] INFO: Starting handshake: presense_announce=0
0000024759 [comm.protocol.handshake] INFO: Establish secure connection
0000024785 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000025376 [system] INFO: Resolved xxx.udp.particle.io to 52.90.182.92
0000025485 [system] TRACE: Connection attempt to 52.90.182.92:5684
0000025485 [system] INFO: Cloud socket connected
0000025487 [system] INFO: Starting handshake: presense_announce=0
0000025487 [comm.protocol.handshake] INFO: Establish secure connection
0000025513 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000034574 [comm.dtls] ERROR: handshake failed -6800
0000034574 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000034576 [system] WARN: Cloud handshake failed, code=17
0000034624 [comm.dtls] ERROR: handshake failed -6c00
0000034624 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000034627 [system] WARN: Cloud handshake failed, code=17
0000034826 [system] INFO: Cloud: disconnecting
0000034844 [system] INFO: Cloud: disconnected
0000035628 [system] INFO: Cloud: connecting
0000035630 [system] INFO: Cloud: connecting
0000035632 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000035635 [system] ERROR: Failed to load session data from persistent storage
0000035635 [system] INFO: Discarding session data
0000035638 [system] TRACE: Resolving xxx.udp.particle.io
0000035639 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000035639 [system] ERROR: Failed to load session data from persistent storage
0000035641 [system] INFO: Discarding session data
0000035641 [system] TRACE: Resolving xxx.udp.particle.io
0000036899 [system] INFO: Resolved xxx.udp.particle.io to 34.229.191.158
0000037008 [system] TRACE: Connection attempt to 34.229.191.158:5684
0000037008 [system] INFO: Cloud socket connected
0000037009 [system] INFO: Starting handshake: presense_announce=0
0000037009 [comm.protocol.handshake] INFO: Establish secure connection
0000037024 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000037819 [system] INFO: Resolved xxx.udp.particle.io to 18.206.150.141
0000037912 [system] TRACE: Connection attempt to 18.206.150.141:5684
0000037912 [system] INFO: Cloud socket connected
0000037914 [system] INFO: Starting handshake: presense_announce=0
0000037914 [comm.protocol.handshake] INFO: Establish secure connection
0000037940 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000047000 [comm.dtls] ERROR: handshake failed -6800
0000047000 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000047002 [system] WARN: Cloud handshake failed, code=17
0000047050 [comm.dtls] ERROR: handshake failed -6c00
0000047050 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000047053 [system] WARN: Cloud handshake failed, code=17
0000047252 [system] INFO: Cloud: disconnecting
0000047268 [system] INFO: Cloud: disconnected
0000048054 [system] INFO: Cloud: connecting
0000048056 [system] INFO: Cloud: connecting
0000048058 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000048061 [system] ERROR: Failed to load session data from persistent storage
0000048061 [system] INFO: Discarding session data
0000048064 [system] TRACE: Resolving xxx.udp.particle.io
0000048065 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000048065 [system] ERROR: Failed to load session data from persistent storage
0000048067 [system] INFO: Discarding session data
0000048067 [system] TRACE: Resolving xxx.udp.particle.io
0000049095 [system] INFO: Resolved xxx.udp.particle.io to 52.90.182.92
0000049189 [system] TRACE: Connection attempt to 52.90.182.92:5684
0000049189 [system] INFO: Cloud socket connected
0000049191 [system] INFO: Starting handshake: presense_announce=0
0000049191 [comm.protocol.handshake] INFO: Establish secure connection
0000049217 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000049778 [system] INFO: Resolved xxx.udp.particle.io to 34.229.191.158
0000049857 [system] TRACE: Connection attempt to 34.229.191.158:5684
0000049857 [system] INFO: Cloud socket connected
0000049859 [system] INFO: Starting handshake: presense_announce=0
0000049859 [comm.protocol.handshake] INFO: Establish secure connection
0000049885 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000058944 [comm.dtls] ERROR: handshake failed -6800
0000058944 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000058946 [system] WARN: Cloud handshake failed, code=17
0000058994 [comm.dtls] ERROR: handshake failed -6c00
0000058994 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000058997 [system] WARN: Cloud handshake failed, code=17
0000059197 [system] INFO: Cloud: disconnecting
0000059213 [system] INFO: Cloud: disconnected
0000061001 [system] INFO: Cloud: connecting
0000061003 [system] INFO: Cloud: connecting
0000061005 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000061008 [system] ERROR: Failed to load session data from persistent storage
0000061008 [system] INFO: Discarding session data
0000061011 [system] TRACE: Resolving xxx.udp.particle.io
0000061012 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000061012 [system] ERROR: Failed to load session data from persistent storage
0000061014 [system] INFO: Discarding session data
0000061014 [system] TRACE: Resolving xxx.udp.particle.io
0000061596 [system] INFO: Resolved xxx.udp.particle.io to 52.55.104.91
0000061676 [system] TRACE: Connection attempt to 52.55.104.91:5684
0000061676 [system] INFO: Cloud socket connected
0000061677 [system] INFO: Starting handshake: presense_announce=0
0000061677 [comm.protocol.handshake] INFO: Establish secure connection
0000061692 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000062247 [system] INFO: Resolved xxx.udp.particle.io to 107.20.71.170
0000062311 [system] TRACE: Connection attempt to 107.20.71.170:5684
0000062311 [system] INFO: Cloud socket connected
0000062313 [system] INFO: Starting handshake: presense_announce=0
0000062313 [comm.protocol.handshake] INFO: Establish secure connection
0000062339 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000071399 [comm.dtls] ERROR: handshake failed -6800
0000071399 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000071401 [system] WARN: Cloud handshake failed, code=17
0000071449 [comm.dtls] ERROR: handshake failed -6c00
0000071449 [comm.protocol.handshake] ERROR: handshake failed with code 17
0000071452 [system] WARN: Cloud handshake failed, code=17
0000071651 [system] INFO: Cloud: disconnecting
0000071669 [system] INFO: Cloud: disconnected

I found that if I call it too quickly the connection is unstable. If I call it every 500ms the connection remains connected. Below is what I am using.

void PublishQueueAsync::ParticleProcess() {
	static uint32_t prevProcessMillis = 0;
	if (Particle.connected() && Cellular.ready() && millis() - prevProcessMillis >= 500) {
		Particle.process();
		prevProcessMillis = millis();
	}
}

void PublishQueueAsync::threadFunction() {
	// Call the stateHandler forever
	while(true) {
		stateHandler(*this);
		ParticleProcess();
		getRSSI();
		os_thread_yield();
	}
}

My point was, when you use SYSTEM_THREAD(ENABLED) you’d not need to call Particle.process() in your code anywhere.

1 Like

ahh ok, ill give that a go by removing the particle process calls

that did the trick. thanks!