Unable to flash electron successfully via CLI

Been struggeling the whole day with my first Particle device, previously used Arduinos and ESP devices. Some facts which help:

  • used device, probably still claimed under someones account I do not know
  • I will use my own SIM
  • Web IDE did not work as I can't claim the device, so I used CLI.

What I did:
Step1) - download blink-an-led.ino file from web IDE.
Step2) - compile it in CLI using commands particle compile electron blink-an-led.ino
Results is
Compiling code for electron

Including:
blink-an-led.ino

Compile succeeded.

Memory use:
Flash RAM
4368 1540

Saved firmware to: xxx/electron_firmware_1701004269926.bin

Step3) Put device in DFU manually and flash it using USB cable particle flash -v --usb electron_firmware_1701004269926.bin.
Successful result:

Flashing electron device xxx

[█████████████████████████] 100% | Flashing electron_firmware_1701004269926.bin

Flash success!

D7 LED does not start blinking. Only the status LED blinks all the time blue, but that's not the LED i'm trying to address via this program.

I used serial monitor and few times randomly it asked me to enter 63-digit claim code in the serial monitor. I could enter random digits and it would say laim code set.
Not sure if related, why and how this even comes up.

Updated FW via CLI to newest. Have done resets etc.

So how to flash a simple blink to the device?

You are most likely running into an issue because the commands you used only flashed your user firmware application, but Device OS remained at the version from when the device was last used, which is likely an old version. In this case, the device needs to go online to get the parts OTA, which it can't do because it doesn't have an activated SIM.

To fix this, flash the firmware using this command, which will also upgrade Device OS by USB:

particle flash --local electron_firmware_1701004269926.bin

Also be sure your firmware includes

SYSTEM_THREAD(ENABLED);

near the top of your source file, not inside a function. This is necessary otherwise your code won't run until the device is online, which won't happen because the SIM is not activated.

2 Likes

Thanks a lot for these hints! I got the LED blinking :slight_smile:
Will use the particle flash --local command moving forward.

But can you comment on the SYSTEM_THREAD(ENABLED);. When you mean the code won't run otherwise until online, do you mean until data connection is establish? Establish towards what?

Why I'm asking is because I want to use the cellular module only for SMS + call (call acts more of a notification, no mic or speaker needed). No data.
So in that case would I still need to use the system_thread(enabled)?

I was thinking about something like this:

SYSTEM_THREAD(ENABLED);

#define BUTTON 6

String Number01 = "+94000000000";
String Number02 = "+94111111111";
String SMS_MSG = "This Is Test Message.";

void setup() {
Cellular.on();
Serial.begin(9600);

pinMode(BUTTON,INPUT_PULLUP);
}

void loop() {
if(digitalRead(BUTTON) == LOW){
//Send Message to Number 01
sendSMS(Number01,SMS_MSG);
//Send Message to Number 02
sendSMS(Number02,SMS_MSG);
//Call Number 01
makeCall(Number01);
//Call Number 02
makeCall(Number02);
}

}

void sendSMS(String NUM, String MSG){
int point;
Serial.print("Send SMS to : "); Serial.println(NUM);
Cellular.command("AT+CMGF=1\r");
delay(2000);
Cellular.command("AT+CMGS="");
Cellular.command(NUM);
Cellular.command(""\r");
delay(2000);

Cellular.command(MSG); // SMS Text
delay(200);
Cellular.command((char)26); // ASCII code of CTRL+Z
delay(2000);
}

void makeCall(String NUM){
Serial.println("Making a call...");

// Set the phone number to call
Cellular.command("ATD");
Cellular.command(NUM);
Cellular.command(";");

delay(1000);

Serial.println("Call initiated!");

// Wait for the call to connect
// while (gsmSerial.available()) {
// Serial.write(gsmSerial.read());
//}

Serial.println();

// Wait for the call to end (adjust the delay according to your needs)
for(int x=0; x<20; x++){ delay(1000); }

// Hang up the call
gsmSerial.println("ATH");

Serial.println("Call ended!");

// Wait for the module to respond
//while (gsmSerial.available()) {
// Serial.write(gsmSerial.read());
// }

Serial.println();
}

For your application you want:

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);

Threading is a good idea in all situations, and SEMI_AUTOMATIC will mean that Device OS will not attempt to connect to make a cloud connection.

There is a possibility you will need to connect to cellular before being able to send an SMS. The problem will be that Cellular.connect() both connects to cellular (GSM) and establishes a PDP session (GPRS, for TCP/IP). You may need to issue some AT commands to establish the GSM session to the tower before SMS will work. It's been a long time since I've done it and don't remember for sure.

I have been successful with my code and it works as expected as long as I just flashed the device and do not remove power to it.
Once I remove power completly, the code does not seem to run anymore until I re-flash it again.

Just pressign RESET button is okay, but unplugging USB power without battery will not afterwards start running the code.

Does it have to do somethign with the way I'm flashing it?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.