Particle devices are compact, easy-to-code hardware kits that provide everything you need to build an IoT Solution. Particle devices combine an ARM microcontroller, a communication chip (WiFi, GPRS or 3G) and a web IDE with tons of community examples and Ubidots libraries to get started quickly. Pairing Particle hardware with the Ubidots IoT Application Development Platform gives you the power to connect and sense an environment and then visualize and optimize that space with Ubidots software. 

There are two methods for programming your Particle device to communicate with Ubidots: Over-the-Air-Authentication (OTAA) and Command Line Interface (CLI).

  • Over-the-Air-Authentication (OTAA)- This method we will to use the PARTICLE IDE to create, verify, and upload a code to the device over-the-air. This method requires data usage from the SIM or the Wifi connection.
  • Command Line Interface (CLI)- This method will use the serial port from your PC to create, verify, and upload the code to the device with a USB cable.

Step-by-Step

  1. Using OTAA Method to Verify, Upload, and Debug Code
    – Debugging with OTAA
  2. Using CLI Method to Verify, Upload, and Debug Code
    – Debugging with CLI

1. Using OTAA Method to Verify, Upload, and Debug Code

Over-the-air-authentication (OTAA) is a method to program and verify the code from the Particle IDE web. Then, directly from the web IDE, upload the code to the particle hardware remotely using the cellular network data or WiFi connection. 

1. To begin, log into your Particle account.

2. Select the application that you want to manage. If you don't have any applications yet, the  "Creating a New App in Particle" will prove very helpful in creating your first App.

3. Next, from the left-side pane, select the "device" icon, then select the device that you wish to code by clicking the "star" icon beside each device name. (Be sure that the star turns to yellow to identify the device you will be working with.)

4. Now Verify if the code has any syntax mistakes; to do this, in the top-left sidebar click the “check-mark” icon and verify the code.

IDE Response: 

  • All Clear = “Code verified! Great work.
  • Errors/Failure = "Error: Could not compile. Please review your code." The code has a syntax mistake and requires adjustment. 

5. Check that the device is blinking cyan indicating if the hardware is connected to Particle Cloud. If the LED is not blinking cyan, please refer to Particle documentation to set the device mode.

6. Next, Upload the code by selecting the “lightning-bolt” icon above the verification icon. 

IDE Response:
Successful: "Flash successful! Your device is being updated."

7. After the device has been flashed, wait a couple minutes until the device begins to blink cyan again.

Debugging with OTAA

Once you are able to code in Particle's IDE, it is recommended to add a Debugger to know if the code is running correctly. A good option to Debug your code is adding a print line Serial.println(). This line of code will print a string or a variable (even both) through the serial port, allowing you to see in which execution step a message was printed or failed. This functionality is helpful in any code and best applied when included before a key function or loop to identify the most common breakdowns in the code.

  • If you want to print a text, write the message between quotations marks i.e. Serial.println("Text")
  • If you want to print a variable, you need to write the variable's name i.e. Serial.println(variable_name) 

IMPORTANT NOTE: Be sure to add Serial.begin(115200) into the Setup of the code to open the Serial communication.

Implementing Print Lines

The sample code below include 3 useful print line examples. The first example is located before loop begins, the second is located inside the loop, and the third is after the loop to verify the code is complete.
Copy and paste the below sample code into the Particle Web IDE, or add the print lines directly into your own code following the below structure.

By using the sample code below in the Particle IDE you can expect to each Serial.println() function to print each execution of the code in the serial monitor.

void setup() {
    Serial.begin(115200);
   
}
void loop() {
    //First print line
    Serial.println("Hello world");
 
  for(int i = 0; i < 5 ; i++){
      //Second print line
      Serial.print("Step number: ");
      Serial.println(i);
  }
  //Third second line
  Serial.println("Goodbye world");
  // Wait 60 seconds
  delay(60000);
}

Debugging the Code

1. Time to debug the code. Please refer to the Particle's guide to install the serial terminal provided by Particle. Once the installation has completed, open a new serial terminal window on your PC, then copy and paste the command below into the terminal window; press "enter" to execute the below request in the serial terminal of Particle.

Particle serial monitor

After a few seconds the serial terminal will begin to print messages received from the Particle hardware.

With this confirmation of the completed Serial.println("Text") = Goodbye World the debugger has verified the code has a good syntax and your device is ready to be uploaded using the OTAA method with the perfect firmware to run your Ubidots powered IoT Apps.

2. Using CLI Method to Verify, Upload, and Debug Code

Command Line Interface (CLI) is a way of managing Particle hardware code and devices from your computer’s command terminal. To work with the CLI method, a New App is required in the Particle IDE. If you don't have an App, check out the article Creating a “New App” in the Particle IDE for additional assistance. 

  1. To begin, install the CLI onto your PC. To do so, simply follow Particle's installation guide.
  2. Next, with the CLI activate and a New App created, launch a programming IDE that supports C/C++. For this article, we use the Atom editor. Open the editor and select File –> "Open Folder" to open the a new modal window.
  3. A new window modal window will appear. Locate and select your project folder previously made when creating a new App. Then press "Ok".
  4. Next, in the left sidebar you will find the "My_New_App.ino" is located in "src" folder and titled the same as your project; click to open it.

5. Open a new terminal window of your computer and locate the folder where you saved the "New App." Then copy and paste the command below into the terminal window to compile the project. Be sure to replace "device" with the exact type of Particle hardware that you're using. i.e. particle compile electron -or- particle compile photon.

particle compile device 

Press enter to execute the command and compile the project. If everything is going well you'll receive a "Compile Succeeded" message and a new .bin file will be created.

Troubleshooting: If something is wrong with your code you'll receive a "Compile failed: Compiler encountered an error" message and the compiler will identify the possible errors.

1. Once the code have been compiled successfully, connect the Particle hardware to your PC using the USB cable and port.

2. Place the Particle device in listening mode. To do so, press the device's "MODE" button for three seconds, until the RGB LED begins to blink dark blue.

Copy and paste the command below to flash your device. Replace "firmware" with the name of the .bin file created in the 5 step.

particle serial flash firmware.bin

Press enter to execute the command. The compiler will then ask a confirmation if the device is blinking blue, press enter to continue.

 Once the device has been flashed properly, you'll see a "Flash success!" message. You need to wait a couple minutes until the device begins to blink cyan. If the device does not begin reporting a proper connection (Cyan color), please refer to the Particle documentation for additional troubleshooting information.

Debugging with CLI

Once you are able to code in Particle's IDE, it is recommended to add a Debugger to know if the code is running correctly. A good option to Debug your code is adding a print line Serial.println(). This line of code will print a string or a variable (even both) through the serial port, allowing you to see in which execution step a message was printed or failed. This functionality is helpful in any code and best applied when included before a key function or loop to identify the most common breakdowns in the code.

In the Atom Editor, copy and paste the sample code below into the development window and then save it (Cntl + S).

void setup() {
    Serial.begin(115200);
   
}
void loop() {
    Serial.println("Hello world");
 
  for(int i = 0; i < 5 ; i++){
      Serial.print("Step number:");
      Serial.println(i);
  }
  // Wait 60 seconds
  Serial.println("Goodbye world");
  delay(60000);
}

1) Time to debug your code. Please open a terminal window from your PC, then copy and paste the command below into the terminal window. Press enter to execute. This will automatically open the CLI serial provided by Particle.

Particle serial monitor

After a seconds, the serial terminal will begin to print messages as the test is completed.

Now you're ready to code, debug, verify and upload a code to integrate your Particle devices with Ubidots using CLI method over serial port. For more information, please refer to the complete documentation from Particle documentation web.

With this technical resource from Ubidots, you are now one step closer to sending data to Ubidots platform. Please see the below articles for additional assistance in setting up and programming your Particle hardware to communicate with Ubidots.

Did this answer your question?