How to use the command "particle" (with examples)
1: Logging in and creating an account (particle setup)
Code:
particle setup
Motivation:
The particle setup
command allows you to log in or create a new account for the Particle CLI. This is necessary to access your Particle devices and perform various operations.
Explanation:
Running particle setup
will prompt you to either log in with your existing Particle account credentials or create a new account if you don’t have one. You will be asked to enter your email and password to authenticate.
Example Output:
? Please enter your email address: example@example.com
? Please enter your password (typing will be hidden): [hidden]
Logged in successfully!
2: Listing devices (particle list)
Code:
particle list
Motivation:
The particle list
command allows you to view a list of your Particle devices that are associated with your account. This is helpful to check the status and details of your devices.
Explanation:
Executing particle list
will retrieve information about all the devices linked to your Particle account. It will display details such as the device ID, name, online/offline status, last connection date, and firmware version.
Example Output:
Retrieving devices... (this might take a few seconds)
[123456789012345678901234] Photon - My Device 1 [online]
[abcdefghabcdefghabcdefgh] Electron - My Device 2 [offline]
3: Creating a new Particle project (particle project create)
Code:
particle project create
Motivation:
The particle project create
command allows you to create a new Particle project interactively. This streamlines the process of setting up a project with the necessary files and dependencies.
Explanation:
Running particle project create
will prompt you to enter the name and location for your new project. It will then generate the project structure, including a project.properties
file for setting project configurations and dependencies.
Example Output:
? Project name: MyProject
? Creating new project in directory: /path/to/project
Successfully created project files!
4: Compiling a Particle project (particle compile)
Code:
particle compile device_type path/to/source_code.ino
Motivation:
The particle compile
command allows you to compile a Particle project for a specific device type. This is necessary to generate the firmware binary file that can be flashed onto the device.
Explanation:
When using particle compile
, you need to specify the device type (e.g., Photon, Electron) and the path to the source code file (path/to/source_code.ino
). This command will compile the source code and generate the firmware binary file.
Example Output:
Compiling code for photon...
Including:
/path/to/source_code.ino
...
Compile succeeded.
5: Flashing a device with a specific app remotely (particle flash)
Code:
particle flash device_name path/to/program.bin
Motivation:
The particle flash
command allows you to update a Particle device remotely with a specific application firmware binary file. This is useful when you want to deploy a new version of your application to a device without physically accessing it.
Explanation:
Executing particle flash
requires providing the device name and the path to the firmware binary file (path/to/program.bin
). The command will remotely flash the specified firmware onto the device.
Example Output:
Including:
path/to/program.bin
...
Flash success!
6: Flashing a device with the latest firmware via serial (particle flash –serial)
Code:
particle flash --serial path/to/firmware.bin
Motivation:
The particle flash --serial
command allows you to update a Particle device with the latest firmware binary file via serial connection. This is useful when you need to flash a device that doesn’t have a reliable internet connection.
Explanation:
Running particle flash --serial
requires providing the path to the firmware binary file (path/to/firmware.bin
). This command will establish a connection with the device via serial and flash the latest firmware onto it.
Example Output:
Including:
path/to/firmware.bin
...
Flash success!
7: Executing a function on a device (particle call)
Code:
particle call device_name function_name function_arguments
Motivation:
The particle call
command allows you to execute a specific function on a Particle device. This is useful for remotely triggering actions or retrieving data from the device.
Explanation:
Using particle call
requires specifying the device name, the function name, and any arguments required by the function. This command will invoke the function on the device and execute the corresponding logic.
Example Output:
Calling function function_name on device device_name with arguments function_arguments...
Function called successfully!
Conclusion
In this article, we explored various use cases of the Particle CLI command and provided code examples for each scenario. We covered logging in, listing devices, creating a project, compiling code, flashing devices remotely, flashing devices via serial, and executing functions on devices. By understanding these examples, you can effectively interact with Particle devices and manage your Particle projects.