The Provision Device script is used to register and provision your Saluminator® device with Azure IoT Central. This enables your Saluminator® to use all of the features of the IoT Central Saluminator® application that enables sending and visualizing telemetry, running jobs and communicate from the cloud to the Saluminator® device.
- FILE: provisiondevice.py
- LOCATION: ./software/src/provisiondevice.py
- DEPENDANCIES:
Let's look at all the options by running the script with --help option...
python ./provisiondevice.py --helpOutput
----------------------------------------------------------------------------------------------------------------
HELP for provisiondevices.py
----------------------------------------------------------------------------------------------------------------
BASIC PARAMETERS...
-h or --help - Print out this Help Information
-v or --verbose - Debug Mode with lots of Data will be Output to Assist with Debugging
-d or --debug - Debug Mode with lots of DEBUG Data will be Output to Assist with Tracing and Debugging
OPTIONAL PARAMETERS...
-r or --registerid - This numeric value will get appended to your provisioned device. Example '1' would
result in a device provisioned with the name: saluminator-1
USAGE: -r 5
DEFAULT: 1
NOTE: The Prefix for your devices is located in the config.json file ['Device']['Device Name Prefix']
-n or --numberofdevices - The value is used to enumerate and provision the device(s) count specified.
NOTE: LIMIT OF 10 DEVICES PER SESSION. You can run the provisiondevices.py via
a script and indicate --registerid with the sequential numbering if you want to
provision more devices.
USAGE: -n 10
DEFAULT: 1
----------------------------------------------------------------------------------------------------------------Example
python provisiondevice.py --verbose --registerid 1 --numberofdevices 1The script executes the following actions...
- Loads the config.json file.
- Loads the devicecache.json file.
- Loads the secrets.json file.
- Add the tables for the recipe life-cycle tracking, auditing, and the current status of the relays.
- Table names: tracking, audit and relay
- Generate the fine grained “by hour” recipe entries into the recipe life-cycle tracking table.
- Add events for all database create activities to auditing table.
This fisrt parameter that gets filled in is the naming pattern for the database. This is verbose and it designed to make it easy to look at the file name and see the active recipe name. This items is located in the config.json file:
"Database Naming Pattern": "active_recipe_{recipe_name}.db"Based on the parameter passed into the script for --recipename, we first lookup that recipe and all of it's details from the recipes.json file. Click here for the details on the parameters in the recipes.json file and an detailed explanation of Recipe Management...
For example, we find Salumi Toscano in the recipe array...
[
{
"Name": "Salumi Toscano",
"Incubate": {
"Cycle Time Toggle": 1,
"Cycle Time": 12,
"Temperature": {
"Desired": 85,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
},
"Humidity": {
"Desired": 90,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
}
},
"Cure": {
"Cycle Time Toggle": 24,
"Cycle Time": 25,
"Temperature": {
"Desired": 60,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
},
"Humidity": {
"Desired": 75,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
}
},
"Finish": {
"Cycle Time Toggle": 24,
"Cycle Time": 10,
"Temperature": {
"Desired": 58,
"Variance": 2,
"Run Time": 3,
"Idle Time": 5
},
"Humidity": {
"Desired": 60,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
}
}
},
{
"Name": "Saucisson Sec", ...
}
]Once we create the database and the tables, the next step inserts not the database all of the individual, by hour "steps" that the lifecycle of the recipe will keep track of over time. We refer to these individual steps as CHECKPOINTS and the software keeps track of the place (the row in the database) that the recipe is at based on elapsed time since the recipe was started.
There is a json configuration file named currentrecipe.json located at the root folder. This file's purpose is to indicate the name of the active database, the date and time that the recipe was started and the current checkpoint of the recipe. The checkpoint is correlated to the number of elapased hour between the current date and time and the Started date and time.
For example...
{
"Database": "active_recipe.db",
"Started": "2022-03-01 09:28:24.387745",
"Current Checkpoint": 144
}The tracking table represents the lifecycle of the recipe. When the database is created, the tracking table is populated with rows that represents data for every hour of the recipe.
Click here for Recipe Managment Details
Let's break down the content in the rows that get added. Examiing the Incubation entry for the Salumi Toscano, the following will be added...
- Cycle Time Toggle - The 1 represents measurement in Hours (if the value is 24, that represents a DAY)
- Cycle Time - Length of time is 12 hours
- Temperature - Desired chamber temperature is 85 degrees Fahrenheit
- Temperature Variance - We can tolerate a 3 degrees above or below the desired 85 degrees Fahrenheit
- Temperature Run Time - If the chamber temperature is at or above 88 degrees or at or below 82 degress Fahrenheit, then turn on the Chiller Relay to lower the temperature or turn on the Heater Relay to increase the temperature.
- Humidity - Desired chamber Humidity is 90 percent relative humidity
- Humidity Variance - We can tolerate a 3 percent aboove of below of relative humidity to the desired 90 percent relative humidity
- Humidity Run Time - If the chamber humidity is at or above 93 percent relative humidity or at or below 88 percent relative humidity, then turn on the DeHumidifier Relay to lower the humidity or turn on the Humidifier Relay to increase the humidity.
- Humidity Idle Time - If the time elapased since DeHumidifier Relay was turned on to lower the relative humidity or the Humidifier Relay was turned on to increase the relative humidity. The Idle time will pause for the indicated number of minutes before restting and engaging humidity control.
The json snippet below shows the actual configuration section in the recipes.json file that was explained in the above section.
"Incubate": {
"Cycle Time Toggle": 1,
"Cycle Time": 12,
"Temperature": {
"Desired": 85,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
},
"Humidity": {
"Desired": 90,
"Variance": 3,
"Run Time": 3,
"Idle Time": 5
}This data is added to the database for the Incubation, Curing and Finishing section of the chosen recipe.
The audit table captures the events that occur in the software. For example when the database is created, temperature changes that trigger a relay and so on. This table is used for auditing and troubleshooting issues that may arise. It is historical and sequential.
The relay table is used to persist the state of a relay. For example, when the Temperature exceeds the desired + variance values, the relay for the Chiller will be engaged. The Relay table tracks starting time of the relay, measures the run time and idle time values and turns off the relay and resets the values for the next time.
