Checking AT Commands on Electron

The depends on what you want.
Will you only activate the connection once (then setup()) otherwise your logic dictates where it has to go (loop(), function, callback, …).

That’s alot!
I have made some process. I am now at the level of testing the network to prepare for sending data to the server. The network is tested with AT commands like AT+CREG? (for network strength) and AT+CIFSR (to make sure there is wireless). For this I first call Cellular.connect() and this should be fine since I am not using a 3rd party SIM. So I use the default APN data from Particle. When I run the code I will provide below, at one point the LED blinks white and I am getting output with IP address showing that there is network. But then after sometime it changes to blink blue (listening mode) and at this point I constantly get the message there is no network. Once it blinks blue, it continues until I reset. I can’t explain this phenomenon. One issue I face is that I have not really seen that the SIM card is activated. Every time I do it (using the web interface) I get to the window where it says “Setup was unsuccessful. Your Electron failed to connect to the Particle cloud.” I have been having this for the past 3 days after I got all the data to activate. But then when I run my code and get an IP address at one point I feel it’s activated but still this issue that at one point there is no longer a connection, I don’t know if I am missing a Cellular function that I need to call or the SIM card is for real not activated. Below is the code.

#include "AssetTracker.h"

SYSTEM_THREAD(ENABLED)
String gAtResponse;

int callbackAT(int type, const char* buf, int len, char* param)
{
	gAtResponse = buf;
	gAtResponse[len]='\0';
	Serial.println("Length: " + (String) len+ " Buff:"+gAtResponse);
	return WAIT;
}

int bOnce = 0;

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

void loop()
{
	while (true) {
		if (Cellular.ready()) {
			Serial.printlnf("There is connection: %d");
			break;
		}
        Cellular.connect();
        delay(1000);
	}

	char response[32] = "";
	f (bOnce < 1) {
	     //Prepare for GRPS
		err = Cellular.command(callbackAT, response, 10000, "AT+CGATT=1\r\n");
		Serial.println("Set GPRS: "+gAtResponse);
		bOnce++;
	}
     //Check network strength
	err = Cellular.command(callbackAT, response, 10000, "AT+CREG?\r\n");
	if (err == RESP_OK)
		Serial.println(gAtResponse);
	
	//Make sure we have Wireless: here the IP Address
	err = Cellular.command(callbackAT, response, 10000, "AT+CIFSR\r\n");
	if (err == RESP_OK)
		Serial.printlnf("Check wireless: "+gAtResponse);
	else
		Serial.println("Wireless fails :"+gAtResponse);
	delay(1000);
}

In order to setup the Electron (and not het the result shown in your image) you need to get your Electron into breathing cyan.
Which should happen automatically in AUTOMATIC mode (as your code is), but in AUTOMATIC you would not call Cellular.on()/Cellular.connect() unless you before disconnected or turned off the modem.

In non-AUTOMATIC you’d also need to call Particle.connect().

But it would be advisable to get your device set up before you flash your own code.
To go back to a known good state of your Electron use (in DFU mode)

particle flash --usb tinker
particle update
particle flash --usb tinker

Then setup your device and only after you got that done successfully carry on with your own code.

That sounds really great. That’s really what I have been missing. I have seen in a couple of documentation
particle flash --usb tinker. I will try that.
Thanks

It looks like I still need to do a lot of think due to DFU errors
This is what I get. Actually I am compiling using CLI:
Here the errors I get. It means I need to installed DFU driver first?

F:\Particle\firmware>particle update
!!! There was an error trying execute DFU utilities.

!!! For help with installing DFU Utilities, please see:
https://docs.particle.io/guide/tools-and-features/cli/#advanced-instal
!!! You may also find our community forums helpful:
https://community.particle.io/

Error code: 1
F:\Particle\firmware>particle flash --usb tinker
Error writing firmware...dfu-util is not installed

You might find this utility useful to install CLI with all dependencies (including dfu-util)

Otherwise you can download dfu-util from the project home
http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/win32-mingw32/
or if you have Windows 64bit
http://dfu-util.sourceforge.net/releases/dfu-util-0.9-win64.zip

copy dfu-util.exe somewhere on your HDD and add it to your system PATH.