This sample demonstrates how to use file transfer capabilities with an IoT Central app. Azure IoT Central takes advantage of the file upload feature of IoT Hub. For file download, this sample shows a common approach for the "firmware update" scenario.
For a full description of the IoT Central File Upload feature see the documentation online.
- Node.js (12+)
- Azure IoT Central application
git clone https://github.com/lucadruda/iotc-sample-file-transfer
cd iotc-sample-file
npm install # this will also build code
Build can also be triggered with
npm run build
Follow the instructions to create an IoT Central application.
Create a file named "env.json" in the root folder with this format:
{
"deviceId": "<Id of device>",
"scopeId": "<Scope Id>",
"groupKey": "<Application SAS Key>",
"deviceKey": "<Device SAS Key>",
"modelId": "<Device Template Id>"
}
Either use one of "groupKey" and "deviceKey". When "deviceKey" is specified, client will connect to the registered device in IoT Central application. If only "gropKey" is specified client will provision a new device with the id in "deviceId" and assign it to the device template identified by "modelId" above.
From root folder run:
npm run start
This repository contains an "uploads" folder that contains some sample images to upload from device. File are named based on device capability model (Upload.json) parameters. Select a file to upload and hit "Run".
When a firmware update request is received, the new firmware gets downloaded into the "downloads" folder and device restarts. The current firmware version gets saved in the "store.txt" file and sent to IoT Central when device starts or reboots.
Current device firmware along with file upload history can be seen in a dashboard like the below one.