mitkox / iotc-sample-file-transfer

A simple file transfer example with Azure IoT Central

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Azure IoT Central file transfer device sample

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.

Prerequisites

  • Node.js (12+)
  • Azure IoT Central application

Getting started

Clone repository and build

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

Prepare IoT Central application

Follow the instructions to create an IoT Central application.

Setup device credentials

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.

Run sample

From root folder run:

npm run start

File transfers

Requesting file upload

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".

fig.1

Simulate firmware update

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.

fig.2

Current device firmware along with file upload history can be seen in a dashboard like the below one.

fig.3

About

A simple file transfer example with Azure IoT Central


Languages

Language:TypeScript 100.0%