github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/README.md (about) 1 # arduino-cloud-cli 2 3 arduino-cloud-cli is a command line tool that empowers users to access the major features of Arduino IoT Cloud from a terminal. 4 5 ## License 6 7 This code is licensed under the terms of the GNU Affero General Public License v3.0. If you have questions about licensing or need a commercial license please contact us at [license@arduino.cc](mailto:license@arduino.cc). 8 9 ## Setup 10 11 * Install [the latest release](https://github.com/arduino/arduino-cloud-cli/releases). 12 * A client ID and a secret ID, retrievable from the [cloud](https://cloud.arduino.cc/home/api-keys) by creating a new API key. 13 * Optional: the command `arduino-cloud-cli device create` requires the `arduino-cli` tool installed on the system. 14 So, if you plan to create a device on the Arduino Cloud via CLI, you need to install the `arduino-cli` following the instructions at [https://arduino.github.io/arduino-cli/latest/installation](https://arduino.github.io/arduino-cli/latest/installation) 15 16 17 ## Usage 18 19 This tool follows a "quiet on success/verbose on error" behaviour. This means that when a command execution result is an error, such error is printed. On the other hand, when the command is successfully executed, there is no 'success' feedback on the output: the results of the command, if any, are directly printed without any other feedback. This strategy allows users to save the output of the command in a file. 20 21 However, if the verbose flag `-v` is used, then the behaviour will change: the logs will always be printed out, providing users with feedback on the execution of the command. 22 23 As an example, let's take the `device create` command. We want to save the information of the newly created device in a file. 24 So we simply lunch the command: 25 26 ```bash 27 arduino-cloud-cli device create --name mydevice --format json > mydevice.json 28 ``` 29 30 The resulting mydevice.json will only contain device information in a json format. 31 32 Another example: let's say that the execution of the previous command results in an error. In that case, the json file will be empty and the terminal will print out the error. Now we want to execute the command again with the logs enabled in order to understand the issue. So we execute the following: 33 34 ```bash 35 arduino-cloud-cli device create --name mydevice -v 36 ``` 37 38 ### Authentication 39 40 arduino-cloud-cli needs a credentials file containing an Arduino IoT Cloud client ID and its corresponding secret. 41 Credentials can also include an optional organization ID that specifies the organization to use. 42 You can retrieve these credentials from the [cloud](https://cloud.arduino.cc/home/api-keys) by creating a new API key. 43 44 #### Init 45 46 Once you have the credentials, execute the following command and provide them: 47 48 ```bash 49 arduino-cloud-cli credentials init 50 ``` 51 52 By default it will be created in the [Arduino data directory](https://support.arduino.cc/hc/en-us/articles/360018448279-Open-the-Arduino15-folder) 53 You can specify a different destination folder with the `--dest-dir` option: 54 55 ```bash 56 arduino-cloud-cli credentials init --dest-dir <destinationFolder> 57 ``` 58 59 arduino-cloud-cli looks for its credentials file in different directories in the following order: current working directory, parents of the current working directory, arduino15 default directory. 60 61 This gives you the possibility to use different credentials files depending on the project you are working on. 62 63 #### Reset 64 65 To reset an old credentials file, just overwrite it using this command: 66 67 ```bash 68 arduino-cloud-cli credentials init --overwrite 69 ``` 70 71 #### JSON format 72 73 The credentials file is supported in two different formats: json and yaml. Use the `--file-format` to choose it. Default is yaml. 74 75 ```bash 76 arduino-cloud-cli credentials init --file-format json 77 ``` 78 79 #### Using environment variables 80 81 It is also possible to specify credentials directly in `ARDUINO_CLOUD_CLIENT`, `ARDUINO_CLOUD_SECRET` and optionally `ARDUINO_CLOUD_ORGANIZATION` environment variables. 82 83 Credentials specified in environment variables have higher priority than the ones specified in credentials files. 84 85 Please note that credentials are correctly extracted from environment variables only if all the mandatory credentials parameters (client and secret) are found in environment variables. (think of it as another config file but with higher priority) 86 87 #### Find credentials 88 89 To have information about which credentials would be used in the current folder you can use the following command: 90 91 ```bash 92 arduino-cloud-cli credentials find 93 ``` 94 95 ## Device provisioning 96 97 When provisioning a device, you can optionally specify the port to which the device is connected and its [FQBN](https://arduino.github.io/arduino-cli/latest/FAQ/#whats-the-fqbn-string). If they are not given, then the first device found will be provisioned. 98 99 Use this command to provision a device: 100 101 ```bash 102 arduino-cloud-cli device create --name <deviceName> --port <port> --fqbn <deviceFqbn> 103 ``` 104 105 Here are the FQBNs of the Arduino boards that can be provisioned with this command: 106 107 * `arduino:samd:nano_33_iot` 108 * `arduino:samd:mkrwifi1010` 109 * `arduino:mbed_nano:nanorp2040connect` 110 * `arduino:mbed_portenta:envie_m7` 111 * `arduino:mbed_nicla:nicla_vision` 112 * `arduino:samd:mkr1000` 113 * `arduino:samd:mkrgsm1400` 114 * `arduino:samd:mkrnb1500` 115 * `arduino:mbed_opta:opta` 116 * `arduino:mbed_giga:giga` 117 118 If the device supports more than one connectivity type (Eg: WiFi and Ethernet) the --connection flag can be used to set the desired connectivity 119 120 ```bash 121 arduino-cloud-cli device create --name <deviceName> --port <port> --fqbn <deviceFqbn> --connection <deviceConnectivity> 122 ``` 123 124 Here the list of available connection values: 125 126 * `wifi` to set WiFi connectivity 127 * `eth` to set Ethernet connectivity 128 * `wifiandsecret` 129 * `gsm` to set Gsm connectivity 130 * `nb` to set Narrowband connectivity 131 * `lora` to set Lora connectivity 132 133 ### Devices with LoRaWAN connectivity 134 135 LoRaWAN devices should be provisioned using a specific command. 136 Parameters are the same except for the additional mandatory `--frequency-plan`: 137 138 ```bash 139 arduino-cloud-cli device create-lora --name <deviceName> --frequency-plan <freqID> --port <port> --fqbn <deviceFqbn> 140 ``` 141 142 Here are the FQBNs of the Arduino boards supporting LoRaWAN communication that can be provisioned with this command: 143 144 * `arduino:samd:mkrwan1310` 145 * `arduino:samd:mkrwan1300` 146 147 The list of supported LoRaWAN frequency plans can be retrieved with: 148 149 ```bash 150 arduino-cloud-cli device list-frequency-plans 151 ``` 152 153 ### Generic device 154 155 A generic device is like a virtual device that doesn't need to be attached to an actual physical board. 156 Any actual physical board can connect to Arduino IoT Cloud using the credentials of a generic device. 157 Generic devices can be created using a specific command. 158 An optional `--fqbn` flag can be passed to specify the FQBN of the device, otherwise it will be set to `generic:generic:generic`. 159 160 ```bash 161 arduino-cloud-cli device create-generic --name <deviceName> --fqbn <fqbn> 162 ``` 163 164 The list of supported FQBN can be retrieved with: 165 166 ```bash 167 arduino-cloud-cli device list-fqbn 168 ``` 169 170 ## Device commands 171 172 ### Delete a device 173 174 Devices can be deleted using the device delete command. 175 176 This command accepts two mutually exclusive flags: `--id` and `--tags`. Only one of them must be passed. When the `--id` is passed, the device having such ID gets deleted: 177 178 ```bash 179 arduino-cloud-cli device delete --id <deviceID> 180 ``` 181 182 When `--tags` is passed, the devices having all the specified tags get deleted: 183 184 ```bash 185 arduino-cloud-cli device delete --tags <key0>=<value0>,<key1>=<value1> 186 ``` 187 188 ### List devices 189 190 Devices currently present on Arduino IoT Cloud can be retrieved with: 191 192 ```bash 193 arduino-cloud-cli device list 194 ``` 195 196 It has an optional `--tags` flag that allows to list only the devices having all the provided tags: 197 198 ```bash 199 arduino-cloud-cli device list --tags <key0>=<value0>,<key1>=<value1> 200 ``` 201 202 ### Tag devices 203 204 Add tags to a device. Tags should be passed as a comma-separated list of `<key>=<value>` items: 205 206 ```bash 207 arduino-cloud-cli device create-tags --id <deviceID> --tags <key0>=<value0>,<key1>=<value1> 208 ``` 209 210 ### Untag devices 211 212 Delete specific tags of a device. The keys of the tags to delete should be passed in a comma-separated list of strings: 213 214 ```bash 215 arduino-cloud-cli device delete-tags --id <deviceID> --keys <key0>,<key1> 216 ``` 217 218 ## Thing commands 219 220 ### Create thing 221 222 Create a thing from a thing template. 223 224 Supported template formats are JSON and YAML. The name parameter is optional. If it is provided, then it overrides the name retrieved from the template: 225 226 ```bash 227 arduino-cloud-cli thing create --name <thingName> --template <template.(json|yaml)> 228 ``` 229 230 ### Clone thing 231 232 Create a thing by cloning another thing. 233 234 Here the *name is mandatory*: 235 236 ```bash 237 arduino-cloud-cli thing clone --name <thingName> --clone-id <thingToCloneID> 238 ``` 239 240 ### List things 241 242 Things can be printed thanks to a list command. 243 244 Print a list of available things and their variables by using this command: 245 246 ```bash 247 arduino-cloud-cli thing list --show-variables 248 ``` 249 250 Print a *filtered* list of available things, print only things belonging to the ids list: 251 252 ```bash 253 arduino-cloud-cli thing list --ids <thingOneID>,<thingTwoID> 254 ``` 255 256 Print only the thing associated to the passed device: 257 258 ```bash 259 arduino-cloud-cli thing list --device-id <deviceID> 260 ``` 261 262 Print only the things that have all the passed tags: 263 264 ```bash 265 arduino-cloud-cli thing list --tags <key0>=<value0>,<key1>=<value1> 266 ``` 267 268 ### Delete things 269 270 Things can be deleted using the thing delete command. 271 272 This command accepts two mutually exclusive flags: `--id` and `--tags`. Only one of them must be passed. When the `--id` is passed, the thing having such ID gets deleted: 273 274 ```bash 275 arduino-cloud-cli thing delete --id <thingID> 276 ``` 277 278 When `--tags` is passed, the things having all the specified tags get deleted: 279 280 ```bash 281 arduino-cloud-cli thing delete --tags <key0>=<value0>,<key1>=<value1> 282 ``` 283 284 ### Extract thing template 285 286 Extract a template from an existing thing. 287 288 The template is printed to stdout and its format depends on the global `--format` flag: 289 290 ```bash 291 arduino-cloud-cli thing extract --id <thingID> --format <json|yaml> 292 ``` 293 294 ### Bind thing to a device 295 296 Bind a thing to an existing device: 297 298 ```bash 299 arduino-cloud-cli thing bind --id <thingID> --device-id <deviceID> 300 ``` 301 302 #### Tag thing 303 304 Add tags to a thing. Tags should be passed as a comma-separated list of `<key>=<value>` items: 305 306 ```bash 307 arduino-cloud-cli thing create-tags --id <thingID> --tags <key0>=<value0>,<key1>=<value1> 308 ``` 309 310 ### Untag thing 311 312 Delete specific tags of a thing. The keys of the tags to delete should be passed in a comma-separated list of strings: 313 314 ```bash 315 arduino-cloud-cli thing delete-tags --id <thingID> --keys <key0>,<key1> 316 ``` 317 318 ## OTA commands 319 320 ### Upload 321 322 Perform an OTA firmware update. 323 324 Note that the binary file (`.bin`) should be compiled using an arduino core that supports the specified device (check [here](https://arduino.github.io/arduino-cli/0.27/commands/arduino-cli_compile/) how to compile a sketch using the `arduino-cli`): 325 326 ```bash 327 arduino-cloud-cli ota upload --device-id <deviceID> --file <sketch-file.ino.bin> 328 ``` 329 330 The default OTA upload should complete in 10 minutes. Use `--deferred` flag to extend this time to one week (see an example sketch [here](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/ab0af75a5666f875929029ac6df59e04789269c5/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino)): 331 332 ```bash 333 arduino-cloud-cli ota upload --device-id <deviceID> --file <sketch-file.ino.bin> --deferred 334 ``` 335 336 ### Mass upload 337 338 It is also possible to perform a mass ota upload through a specific command. 339 The fqbn is mandatory. 340 341 #### By device 342 343 ```bash 344 arduino-cloud-cli ota mass-upload --fqbn <deviceFQBN> --device-ids <deviceIDs> --file <sketch-file.ino.bin> 345 ``` 346 347 #### By tags 348 349 ```bash 350 arduino-cloud-cli ota mass-upload --fqbn <deviceFQBN> --device-tags <key0>=<value0>,<key1>=<value1> --file <sketch-file.ino.bin> 351 ``` 352 353 ## Dashboard commands 354 355 ### List dashboards 356 357 Print a list of available dashboards and their widgets by using this command: 358 359 ```bash 360 arduino-cloud-cli dashboard list --show-widgets 361 ``` 362 363 ### Delete dashboards 364 365 Delete a dashboard with the following command: 366 367 ```bash 368 arduino-cloud-cli dashboard delete --id <dashboardID> 369 ``` 370 371 ### Extract dashboard template 372 373 Extract a template from an existing dashboard. The template is printed to stdout and its format depends on the global `--format` flag: 374 375 ```bash 376 arduino-cloud-cli dashboard extract --id <dashboardID> --format <json|yaml> 377 ``` 378 379 ### Create dashboard 380 381 Create a dashboard: dashboards can be created only starting from a template. Supported dashboard template formats are JSON and YAML. The name parameter is optional. If it is provided, then it overrides the name retrieved from the template. The `override` flag can be used to override the template `thing_id` placeholder with the actual ID of the thing to be used. 382 383 ```bash 384 arduino-cloud-cli dashboard create --name <dashboardName> --template <template.(json|yaml)> --override <thing-0>=<actualThingID>,<thing-1>=<otherActualThingID> 385 ```