Batch File For SIM Activation, Product Registration and Flashing

Hi All,

I am creating a batch file to complete the following steps:

  1. Put device connected via USB into listening mode. (I believe this is necessary to call particle identify)
  2. Call particle identify and store device variables.
  3. Activate SIM
  4. Register the device to a product. (Will have one script for B404X product and one for B524 product)
  5. Flash a bin file that will be provided with script.

Thoughts/Questions that have arisen from the above:

A. I was hoping that using
particle login --u $email --p $password would allow me to call particle token list to get an access token, which I think I need for curl commands to activate the SIM and register device to a product. It seems like particle login requests a password input before returning my tokens and does not accept the --u $email --p $password command. If I type in the password initially, does anyone know how to hand the password into the following response from particle token list via the batch file?
Please enter your password: [input is hidden]

B. Which Access token should I be using for my curl commands, is it __PASSWORD_ONLY__ (active)?

C. When are access tokens created, I seem to have a long list of the __PASSWORD_ONLY__ tokens. Is a new one generated when I use the CLI particle login command?

D. Initially we will only be setting up a few devices at a time, but am interested to know what the rate limits on the api are?

E. Is there a command to exit listening mode or reset the device that I can send to the device? I will get around this by flashing the code, but for subsequent scripts for device that are already setup and deployed would be good to get this functionality.

F. When a BSOM is in listening mode, what is happening under the hood, is it akin to safe mode?

Thanks in advance. I will share script here when complete and working as may be beneficial to others.

you are ordering from the wholesale store, you will get an email with the Device IDs in your order. The recommended method is to import this into the console into the appropriate product which will add the device to your product and activate the SIM for all devices. In the basic (growth) and enterprise plans, billing does not start until the device connects to the cloud.

If you're not doing that:

If you can, using the Particle CLI is easier because it will manage the access token for you, and you'll need it anyway for other steps. particle product device add can add devices to a product, which will also activate the SIM.

If you do need to use curl directly, create a token for use by your script and save it in the script or in a separate file. You can use particle token create or the web-based equivalent. You can also choose how long you want the token to stay valid when you do it this way. Don't attempt to log in from the your script. This covers a, b, and c.

D: The rate limit for activating SIMs and adding to a product is 10,000 requests every 5 minutes. You can find the limits here.

E: It's no longer necessary with the current Particle CLI to put the device in listening mode to use particle identify. However you can enter and exit listening mode using particle usb start-listening and particle usb stop-listening.

F: No, user code continues to run when in listening mode, and user code that writes to USB serial can adversely affect listening mode commands. The main difference is that in listening mode the device will respond to BLE setup requests, and also some commands by USB serial.

Also particle flash --local is the best way to flash your binary to your device by USB. It will automatically flash Device OS and associated files like the bootloader and softdevice if necessary. The Device OS version will match what your user firmware binary targets.

Hi Rick,

Ok thanks a million.

I don't think we did receive an email with the Device IDs. Would this have come from the no-reply@shopifyemail.com address?

That's great, I wasn't aware that adding the device to a product activates the sim. That makes my life simpler.

Is this related to the firmware version? We are using v4.2.0 and I was getting the following response when trying particle identify without being in listening mode
Your device id is undefined Unable to determine system firmware version

Perfect. I think you have answered all my questions, thanks a million as always. I will revert when script is up and working. Can't say I love the batch file syntax. :grinning:

Your device id is undefined Unable to determine system firmware version

Make sure your Particle CLI version is up-to-date using particle update-cli.

There are two ways the Device ID and other identifiers can be determined:

  • Using USB control requests (since around Device OS 0.8.0)
  • Sending the i command in listening mode.

The Particle CLI was recently changed to use the first method, which has the advantage of not requiring being in listening mode, and also works properly even if the user firmware is outputting data to USB serial at the same time.