Problem with using SYSTEM_THREAD on Electron?

I have this simple code that does not give the expected results. I have a test case to light up the onboard LED D7. The LED D7 goes on and off ONLY when I put SYSTEM_THREAD(ENABLED) in the code. This is the simple LED Blinking test. Here the code.

#include "AssetTracker.h"

SYSTEM_THREAD(ENABLED) //Works only when this line is in the code

void setup()
{
	pinMode(D7, OUTPUT);
	Serial.begin(9600);
}

void loop()
{
	digitalWrite(D7, LOW);
	delay(1000);
	digitalWrite(D7, HIGH);
	delay(1000);
}

Without SYSTEM_THREAD enabled, the LED never lights up which means the code is not executed. Also with Serial.println(), I get now output on hyperterminal. Now in all examples we do not need SYSTEM_THREAD. According to the doc on SYSTEM_THREAD, it shouldn’t really be used, still in Beta. Now when I enable SYSTEM_THREAD in my code, I don’t get data from the GPS. When I read nmea setence with t.prnmea(), I get nothing and at times I get $PGACK,10546 or $PMTK011,MTKGPS08. Reading latitude all the time gives 0.000000.

The firmware on my device was 0.4.8 and I upgraded to 0.5.2 but still the same effect. Has anyone succeeded to run this simple code without SYSTEM_THREAD enabled and it works? Do I need special setting on the electron for this to work?

What is the main LED doing? In the default automatic mode without system threading, user code won’t run until the cloud connection is established, breathing cyan. If the main LED is in any other state (say, blinking green or blinking cyan or blinking dark blue) then user code won’t run, by design.

There is another thread of @rlingeh which goes in a similar direction
Serious connection problems with Electron

Some observations there suggest a connection problem

The SIM card I have is from particle. As I said it matters if I enable SYSTEM_THREAD or not. Non of the examples in the particle docu has worked without me using SYSTEM_THREAD(ENABLED).
@rickkas7 the LED blinks at time CYAN or GREEN which may mean user code is not running as I clearly see but still why then run when I have SYSTEM_THREAD(ENABLED)?. What I need is a clarification if someone has encountered this. It could be my electron is faulty. Why would this code run and I get the LED D7 blinking only when I have SYSTEM_THREAD(ENABLED) in this in Code? If it’s like that by design, then it’s okay. I simply have not seen that used in any example rather it’s not currently adviceable to use it. And when I use it I have other effects of not getting the GPS

#include "AssetTracker.h"
void setup()
{
	pinMode(D7, OUTPUT);
	Serial.begin(9600);
}

void loop()
{
	digitalWrite(D7, LOW);
	delay(1000);
	digitalWrite(D7, HIGH);
	delay(1000);
}

This is why I said in the other thread

But you didn’t ask for clarification there, so I just blab it out unasked:

That instruction donates a seperate thread to the system (where it can run or block) and your application can run unimpressed of any system blocking in its own thread.
That’s why your blink code works with it, but the root cause for your problem (the inability to connect to the cloud) doesn’t get solved by extra threads.

That’s the reason why @BDub suggested to get the code running without SYSTEM_THREAD(ENABLED) first, since clearly we can get out codes (including the doc samples) running with and without SYSTEM_THREAD(ENABLED).

Maybe you reflash Tinker via

particle flash --usb tinker

Then get your Electron into breathing (not blinking) cyan (not any other color) and only after that try to move on.

Okay, thanks!!
Actually I went through this process “particle flash --usb tinker” over the weekend. I need to work on that again. I wanted to first verify here if user code only successfully run with SYSTEM_THREAD enabled and the answer is NO. That’s fine

1 Like