This is a script for ICGW (IoT Connect Gateway) MQTT Protocol Conversion which currently support the following actions:
- Batch update SIMs with adding
azureDeviceId
andgcpDeviceId
to current SIM records. - Add devices to Azure IoT and GCP IoT services.
- Add authentications to ICGW.
For Azure, you only need to provide the proper connectionString
in the yaml file.
How to identify the connectionString
:
- Login to Azure Portal.
- Go to
IoT Hub
and select the hub you want to create/update. - Click
Shared access policies
underSecurity settings
, then choose the shared access policies that with permissionRegistry Write
. You can properly useiothubowner
created by default. - Click the policy selected in step 3, then click the copy icon under
Primary connection string
. This is theconnectionString
.
Normally, you will need a service account (in JSON format) with permission that can create or update the IoT devices.
Once you create the service account, download the JSON key file and set the path of it with environment variable GOOGLE_APPLICATION_CREDENTIALS
in your computer. The script will directly search for it.
You can also provide the path directly by setting serviceAccount
in the GCP yaml file. You can refer to the Yaml file section for details.
You need to setup the SDP authentication details with environment variables. Please create a .env
file with the following content:
SDP_API_HOST=<SDP HOST>
SDP_API_TENANT_ID=<YOUR SDP TENANT ID>
SDP_API_KEY=<YOUR API KEY>
SDP_API_SECRET=<YOUR API SECRET>
Install necessary python packages by the following commands:
pip install requirements.txt
This will update multiple SIMs with the Azure Device ID and GCP Device ID through SDP API.
Run the following command to batch update SIMs by yaml files.
python main.py update-sims <PATH OF YAML FILES>
You can set the value to empty string and the tools will set the value to be null
in this case.
This will add devices to specific cloud service. If same device ID is found in the cloud service, the setting will be updated and overwritten with the YAML one.
Run the following command to add Devices by yaml files.
python main.py add-devices <PATH OF YAML FILES>
This will add one or more authentications through SDP API. Their authentications will be always created as new one with yaml files.
Run the following command to add Authentications by yaml files.
python main.py add-authentications <PATH OF YAML FILES>
The format of yaml should follow the format below.
If same options are specified both in top
and devices
level, the devices
will be used.
gcpSettings:
serviceAccount: <SERVICE ACCOUNT JSON FILE>
projectId: <PROJECT-ID>
region: <REGION>
registryId: <REGISTRY-ID>
options: // Default options
- name: format
value: RSA_PEM
- name: public_key
value: certs/gcp_public.pem
devices:
- imsi: <IMSI 1>
deviceId: <DEVICE ID 1 (GCP DEVICE ID)>
- imsi: <IMSI 2>
deviceId: <DEVICE ID 2 (GCP DEVICE ID)>
options: // Device Specific Options
- name: format
value: ES256_X509_PEM
- name: public_key
value: certs/gcp_public.pem
authentications:
- name: <NAME>
algorithm: <ALGORITHM>
privateKey: <PRIVATE KEY FILE>
deviceId: <DEVICE ID>
description: <DESCRIPTION>
service_account
is optional. Script will search for environment variableGOOGLE_APPLICATION_CREDENTIALS
for service account json file if this is not specified.projectId
,region
,registryId
anddevices
are required.- Multiple credentials is not supported. Devices will only create or update with exactly 1 credential.
- For
options
:format
can beRSA_PEM
,RSA_X509_PEM
,ES256_PEM
,ES256_X509_PEM
or nothing (Empty String or not set).- If
format
is nothing (Empty String or not set), no credentials for the device. - If
format
is set,public_key
is required and the value should be the path of the key.
- For
authentications
:name
,algorithm
,privateKey
,deviceId
are required.algorithm
can beRS256
orES256
.privateKey
can be file path.deviceId
is arbitrary value. ThisdeviceId
does not have to match deviceId under the devices option.description
is optional.
azureSettings:
connectionString: <AZURE CONNECTION STRING>
options: // Default options
- name: type
value: SAS
- name: primary_key
value: old-value
- name: secondary_key
value: old-value
- name: primary_thumbprint
value: old-value
- name: secondary_thumbprint
value: old-value
- name: status
value: disabled
devices:
- imsi: <IMSI 1>
deviceId: <DEVICE ID 1 (AZURE DEVICE ID)>
options: // Device Specific Options
- name: primary_key
value: new-value
- name: secondary_key
value: new-value
- name: status
value: enabled
- imsi: <IMSI 2>
deviceId: <DEVICE ID 2 (AZURE DEVICE ID)>
options:
- name: type
value: X509
- name: primary_thumbprint
value: new-value
- name: secondary_thumbprint
value: new-value
authentications:
- name: <NAME>
sharedAccessKey: <SHARED ACCESS KEY>
deviceId: <DEVICE ID>
description: "HOGE"
connectionString
anddevices
are required.- For
options
:type
is required for all devices. It should be eitherSAS
(SAS authentication),X509
(X509 authentication) orCA
(certificate authority).primary_key
andsecondary_key
are required iftype
isSAS
.primary_thumbprint
andsecondary_thumbprint
are required iftype
isX509
.status
is optional, can be eitherenabled
ordisabled
. If no valid value is specified,enabled
will be set.
- For
authentications
:name
,sharedAccessKey
,deviceId
are required.deviceId
is arbitrary value. ThisdeviceId
does not have to match deviceId under the devices option.description
is optional.