I have a device currently already provisioned and connected to an Azure IotHub (lets say it is iothub A). Now I want to disconnect it from iothub A and connect to iothub B. I have looked at the iotedge system
commands, it does not seem to have an disconnect option. the closest one is iotedge deprovision
but it does not seem to clean out existing iothub connection.
The work around I am doing now is deleting the local iotedge setting file in aziot folder and run iotedge config mp --connection-string xxxx
for the new connection. Wonder if there is a better way to clear out current connection?
Below are Steps to Deprovision the IoT Edge Device from the Current IoT Hub:
Navigate to the IoT Hub in the Azure portal where the IoT Edge device is currently connected. Go to Devices under IoT Devices. Locate the IoT Edge device and either Disable the device to temporarily revoke its access or Delete the device to permanently remove it from the hub.
Navigate to the Device Provisioning Service (DPS) instance linked to the IoT Hub. Go to Manage Enrollments and check if the device has an Individual Enrollment. If so, disable or delete the entry. Also, check if the device is part of an Enrollment Group.
Create a disabled individual enrollment for the device or remove the device from the enrollment group by deleting its registration record.
Navigate to the Registration Status tab for the enrollment or group. If needed, manually delete the registration record for the device using the Delete option or programmatic APIs.
Refer this MSDOC to deprovision devices that were provisioned with Azure IoT Hub Device Provisioning Service
Refer this MSDOC to Disenroll or revoke device from Azure IoT Hub Device Provisioning Service
There are two main ways to reconnect the device: manual provisioning or DPS-based provisioning.
One way
is to Manual Provisioning with Connection String by retrieving the device connection string from IoTHub B.
Navigate to IoTHub B > IoT Devices > Add Device (or use an existing device entry). Copy the connection string and Configure the IoT Edge runtime to use the new connection string:
sudo iotedge config mp --connection-string "HostName=<IoTHubB_Name>.azure-devices.net;DeviceId=<DeviceID>;SharedAccessKey=<Key>" --force
Restart the IoT Edge service:
sudo systemctl restart iotedge
The Other way is to use DPS-Based Automatic Provisioning
Open the /etc/aziot/config.toml
file and update the provisioning section as follows:
[provisioning]
source = "dps"
global_endpoint = "https://global.azure-devices-provisioning.net"
id_scope = "<DPS ID Scope>"
registration_id = "<Device Registration ID>"
symmetric_key = "<Device Primary Key>"
Use the sample device_config.toml
from this GitHub link.
Then Run the following command to apply the updated IoT Edge configuration stored in the /etc/aziot/config.toml
file:
sudo iotedge config apply -c '/etc/aziot/config.toml'
Save the changes and restart the IoT Edge service:
sudo systemctl restart iotedge
Check the IoT Edge service status:
sudo systemctl status iotedge
List the IoT Edge modules running on the device:
sudo iotedge list
Output:
sudo iotedge logs edgeAgent
For more details refer this MSDOC to Configure Azure IoT Edge device settings with dps