|
| 1 | +--- |
| 2 | +title: Migrate devices from Azure IoT Central to Azure IoT Hub | Microsoft Docs |
| 3 | +description: Describes how to use the migration tool to migrate devices that currently connect to an Azure IoT Central application to an Azure IoT hub. |
| 4 | +author: dominicbetts |
| 5 | +ms.author: dobett |
| 6 | +ms.date: 07/26/2022 |
| 7 | +ms.topic: how-to |
| 8 | +ms.service: iot-central |
| 9 | +--- |
| 10 | +# Migrate devices to Azure IoT Hub |
| 11 | + |
| 12 | +If you decide to migrate from an IoT Central-based solution to an IoT Hub-based solution, you need to change the configuration of all the devices currently connected to your application. The **IoTC Migrator** tool automates this device migration process. |
| 13 | + |
| 14 | +The migrator tool: |
| 15 | + |
| 16 | +- Creates device registrations in your IoT hub for the devices that currently connect to your IoT Central application. |
| 17 | +- Uses a command to send the *ID scope* of the Device Provisioning Service (DPS) instance associated with your IoT hub to your devices. |
| 18 | + |
| 19 | +The tool requires your connected devices to implement a **DeviceMove** command that's defined in the device template in your IoT Central application. The command payload is the ID scope of the target DPS instance. When a device receives this command, it should: |
| 20 | + |
| 21 | +- Stop sending telemetry and disconnect from the IoT Central application. |
| 22 | +- Provision itself with DPS by using the new ID scope in the command payload. |
| 23 | +- Use the provisioning result to connect to the destination IoT hub and start sending telemetry again. |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +You need the following prerequisites to complete the device migration steps: |
| 28 | + |
| 29 | +- The source IoT Central application where your devices currently connect. |
| 30 | +- The destination IoT hub where you want to move the devices to. This [IoT hub must be linked to a DPS instance](../../iot-dps/concepts-service.md#linked-iot-hubs). |
| 31 | +- The devices that you want to migrate must implement the **DeviceMove** command. The command payload contains the *ID scope* of the destination DPS instance. |
| 32 | +- [node.js and npm](https://nodejs.org/download/) installed on the local machine where you run the migrator tool. |
| 33 | + |
| 34 | +## Setup |
| 35 | + |
| 36 | +Complete the following setup tasks to prepare for the migration: |
| 37 | + |
| 38 | +### Azure Active Directory application |
| 39 | + |
| 40 | +The migrator tool requires an Azure Active Directory application registration to enable it to authenticate with your Azure subscription: |
| 41 | + |
| 42 | +1. Navigate to [Azure portal > Azure Active Directory > App registrations](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps). |
| 43 | + |
| 44 | +1. Select **New Registration**. |
| 45 | + |
| 46 | +1. Enter a name such as "IoTC Migrator app". |
| 47 | + |
| 48 | +1. Select **Accounts in this organizational directory only (iot-partners only - Single tenant)**. |
| 49 | + |
| 50 | +1. Select **Single page application (SPA)**. |
| 51 | + |
| 52 | +1. Enter `http://localhost:3000` as the redirect URI. |
| 53 | + |
| 54 | +1. Select **Register**. |
| 55 | + |
| 56 | +1. Make a note of the **Application (client) ID** and **Directory (tenant) ID** values. You use these values later to configure the migrator app: |
| 57 | + |
| 58 | + :::image type="content" source="media/howto-migrate-to-iot-hub/azure-active-directry-app.png" alt-text="Screenshot that shows the Azure Active Directory application in the Azure portal."::: |
| 59 | + |
| 60 | +### Add the device keys to DPS |
| 61 | + |
| 62 | +Add the shared access signature keys or X.509 certificates from your IoT Central application to your DPS allocation group. |
| 63 | + |
| 64 | +If your devices use shared access signatures to authenticate to your IoT Central application: |
| 65 | + |
| 66 | +- In your IoT Central application, navigate to **Permissions > Device connection groups**. |
| 67 | +- Select the enrollment group your devices use. |
| 68 | +- Make a note of the primary and secondary keys. |
| 69 | +- In the Azure portal, navigate to your DPS instance. |
| 70 | +- Select **Manage enrollments**. |
| 71 | +- Create a new enrollment and set the attestation type to **Symmetric Key**, unselect **Auto-generate keys**, and then add the primary and secondary keys you made a note of. |
| 72 | +- Select **Save**. |
| 73 | + |
| 74 | +If your devices use X.509 certificates to authenticate to your IoT Central application: |
| 75 | + |
| 76 | +- In the Azure portal, navigate to your DPS instance. |
| 77 | +- Select **Certificates** and then select **Add**. |
| 78 | +- Upload and verify the root or intermediate X.509 certificates you use in your IoT Central application. |
| 79 | +- Select **Manage enrollments**. |
| 80 | +- Create a new enrollment and set the attestation type to **Certificate**, then select the primary and secondary certificates you uploaded. |
| 81 | +- Select **Save**. |
| 82 | + |
| 83 | +### Download and configure the migrator tool |
| 84 | + |
| 85 | +Download or clone a copy of the migrator tool to your local machine: |
| 86 | + |
| 87 | +```cmd/bash |
| 88 | +git clone https://github.com/Azure/iotc-migrator.git |
| 89 | +``` |
| 90 | + |
| 91 | +Open the *config.ts* file in a text editor. Update the `AADClientID` and `AADDIrectoryID` with the values from the Azure Active Directory application registration you created previously. Update the `applicationHost` to match the URL of your IoT Central application. Then save the changes: |
| 92 | + |
| 93 | +```typescript |
| 94 | +{ |
| 95 | + AADLoginServer: 'https://login.microsoftonline.com', |
| 96 | + AADClientID: '<your-AAD-Application-(client)-ID>', |
| 97 | + AADDirectoryID: '<your-AAD-Directory-(tenant)-ID>', |
| 98 | + AADRedirectURI: 'http://localhost:3000', |
| 99 | + applicationHost: '<your-iot-central-app>.azureiotcentral.com' |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +> [!TIP] |
| 104 | +> Make sure the `AADRedirectURI` matches the redirect URI you used in your Azure Active Directory application registration. |
| 105 | +
|
| 106 | +In your command-line environment, navigate to the root of the `iotc-migrator` repository. Then run the following commands to install the required node.js packages and then run the tool: |
| 107 | + |
| 108 | +```cmd/bash |
| 109 | +npm install |
| 110 | +npm start |
| 111 | +``` |
| 112 | + |
| 113 | +After the migrator app starts, navigate to [http://localhost:3000](http://localhost:3000) to view the tool. |
| 114 | + |
| 115 | +## Migrate devices |
| 116 | + |
| 117 | +Use the tool to migrate your devices in batches. Enter the migration details on the **New migration** page: |
| 118 | + |
| 119 | +1. Enter a name for the migration. |
| 120 | +1. Select a device group from your IoT Central application. |
| 121 | +1. Select a device template that includes the **DeviceMove** command definition. |
| 122 | +1. Select **Move to your own Azure IoT Hub**. |
| 123 | +1. Select the DPS instance linked to your target IoT hub. |
| 124 | +1. Select **Migrate**. |
| 125 | + |
| 126 | +:::image type="content" source="media/howto-migrate-to-iot-hub/migrator-tool.png" alt-text="Screenshot of migration tool."::: |
| 127 | + |
| 128 | +The tool now registers all the connected devices that matched the target device filter in the destination IoT hub. The tool then creates a job in your IoT Central application to call the **DeviceMove** method on all those devices. The command payload contains the ID scope of the destination DPS instance. |
| 129 | + |
| 130 | +## Verify migration |
| 131 | + |
| 132 | +The **Migration status** page in the tool shows you when the migration is complete: |
| 133 | + |
| 134 | +:::image type="content" source="media/howto-migrate-to-iot-hub/migration-complete.png" alt-text="Screenshot showing completed migration status in tool."::: |
| 135 | + |
| 136 | +Select a job on this page to view the [job status](howto-manage-devices-in-bulk.md#view-job-status) in your IoT Central application. Use this page to view the status of the individual devices in the job: |
| 137 | + |
| 138 | +:::image type="content" source="media/howto-migrate-to-iot-hub/job-status.png" alt-text="Screenshot showing completed migration status for IoT Central job."::: |
| 139 | + |
| 140 | +Devices that migrated successfully: |
| 141 | + |
| 142 | +- Show as **Disconnected** on the devices page in your IoT Central application. |
| 143 | +- Show as registered and provisioned in your IoT hub: |
| 144 | + |
| 145 | + :::image type="content" source="media/howto-migrate-to-iot-hub/destination-devices.png" alt-text="Screenshot of IoT Hub in the Azure portal that shows the provisioned devices."::: |
| 146 | + |
| 147 | +- Are now sending telemetry to your IoT hub |
| 148 | + |
| 149 | + :::image type="content" source="media/howto-migrate-to-iot-hub/destination-metrics.png" alt-text="Screenshot of IoT Hub in the Azure portal that shows telemetry metrics for the migrated devices."::: |
| 150 | + |
| 151 | +## Next steps |
| 152 | + |
| 153 | +Now that know how to migrate devices from an IoT Central application to an IoT hub, a suggested next step is to learn how to [Monitor Azure IoT Hub](../../iot-hub/monitor-iot-hub.md). |
0 commit comments