Debugging with the Particle Electron

Developing IoT products is a multifaceted process - writing software, designing hardware, connecting it all to a cloud. There are many points that can go wrong, which is why it is really important to have good tools for debugging. If the problem is somewhere between the network and the modem, this article might help.
The ETSI GSM 07.07 specifies a set of commands used to control a modem. Every commands starts with "AT", which is why the commands are known as "AT commands". Some AT commands are device-specific, but a lot of them are universal. This makes them an invaluable tool for testing the compability between devices and SIM cards, or getting information about the available networks.

Looking on the web, there were no lightweight programs for the Particle Electron that could give a simple response to any AT command entered by the user. All existing solutions were either too bulky, or were really good but only parsed some specific AT commands (like sending an SMS or getting a list of available operators). This is why we decided to create our own solution.


The first step in testing AT commands is getting a device that you can easily interface with. In this article we use the Particle Electron 2G.


The Electron uses the u-blox SARA-G350 to connect to cellular networks. The manufacturer of the module has provided a really comprehensive guide of AT commands you can use on it.

The Particle Electron is also really easy to program and interface with. Just like the Arduino, all Particle Electron programs have two basic functions - setup() and loop().
The setup() function is executed once at startup and then the the loop() function will be executed forever.

To test the AT commands, we use Particle's Cellular API. The first thing we do is call Cellular.on() to turn on the cellular functionality. We also add a delay to wait for the cellular module to turn on and start the Serial interface so we can communicate to the device while it is running.
In the loop() function we wait for the user to enter the command and call Cellular.command(). To see more specifics about using Cellular.command(), read the Particle documentation on it.
The first argument we pass into the command() function is actually another function that we define after the loop() function.
This code snippet is a modified version of the parsing function from the Electron Troubleshooting App written by Brett Walach, one of the engineers behind the Particle Electron.

We also pass AT_TIMEOUT into the Cellular.command() function. This has to be an integer which defines the amount of milliseconds the program will wait for the response before calling a timeout. We have set this to 5 minutes (300000 milliseconds).

We are ready for testing now! Paste the code into your Particle Web IDE and flash it onto the device. You can do it over-the-air or use the USB cable. Once you have flashed the device, you have to connect it to your computer via the USB cable and open a serial monitor. The easiest way is to download the Arduino IDE and select the correct port from Tools -> Port. Open the serial monitor from the same menu and try some commands.

Some commands to try to make sure your SIM card is installed and working properly:
  • AT+CPIN? - a response saying "READY" means that the modem is connected to the SIM card and is not having a PIN code related problem.
  • AT+CCID - will give you the ICCID of the SIM card
  • AT+COPS=5 - this might take some time, but it should return information about the current available networks
  • AT+UDOPN=9 - tells you which network the device is currently connected to
  • AT+CPOL? - returns a list of preferred operators
Get the full program from our GitHub page. There is also a little bit of code there that helps you configure the device to work with a third-party SIM. We used our own SIMs (1oT SIM) and partner SIMs (1oT Partner SIM) for this experiment and they worked great.

Add a comment

Email again: