Batch-Provision Multiple, Similar Devices using Scripts
After you have set up a Python interpreter so that you can begin to automate many administrative tasks, and can now fetch tokens automatically, you may now want to automate time-consuming tasks like batch-provisioning many new end-devices at once. This tutorial shows how to do this, as well as query devices, and deprovision devices as well.
Overview of this Tutorial
We will be building a script that:
- imports end-device information from a file specified by the user;
- generates/retrieves a subscriber’s authentication token;
- iterates over the input list of end-devices, checking to see if the device has already been provisioned, and then performs ONE of:
- provisions the new device if not already provisioned and the script was called in (default) provisioning-mode;
- skips that device if it has already been provisioned, and the script was called in provisioning-mode;
- skips that device if it has not been provisioned, and the script was called in remove-devices-mode; OR
- removes that device from the subscriber account, if the script was called in remove-devices-mode.
A typical command may look like:
$ python3 provision.py --csv new-devices.csv --subscriber ficticious@subscriber.ac.nz
Password:
Adding 999 new devices...
Success
and will extend the script that was built during the token generation tutorial.
Importing End-Device Provisioning Information
Provisioning a new end-device requires information like:
DevEUI
;AppEUI
;
CSV File for End-Device Parameters
This tutorial uses the standard Python CSV library to parse and import end-device information using the Comma-Separated Values (CSV) format. More information can be found at:
Some disadvantages of CSV are that it is very senstive to changes in the format of the information, and there are many non-standard variants of the format in use.
JSON Files for End-Device Information
Previous Steps
- Setting up a Scripting Environment – Set up a suitable Python interpreter, along with some standard tools and libraries
- Fetching Tokens Automatically – Build a DX API base-class so that tokens are fetched automatically when performing other scripted tasks
Next Steps
- Sending Downlinks to Multiple Devices – Queue up downlinks for multiple devices using a script