Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

Latest commit

 

History

History
64 lines (49 loc) · 2.09 KB

Readme.md

File metadata and controls

64 lines (49 loc) · 2.09 KB

build status

Azure IoT Firmware Updater

Helps simplify the work needed to control the process flow for updating firmware in node.js when using Azure IoT Hub

npm install az-firmware-updater

Getting started

You will need an existing Azure IoT Hub.

To use the firmware updater on your client device (see samples for a complete solution):

const Protocol = require('azure-iot-device-mqtt').Mqtt;
const Client = require('azure-iot-device').Client;
const FirmwareUpdater = require('az-firmware-updater');

const client = Client.fromConnectionString('your-connection-string', Protocol);

client.open(function (err) {
    if (err) {
        console.log(`client error: ${err}`);
    } else {
        console.log('client connected.');

        const options = {
            applyImage: function (imageName) {
                return new Promise(function (fulfill, reject) {

                    // put your custom apply logic here.
                    setTimeout(function () {
                        console.log(`Applied the image: ${imageName}`);
                        fulfill();
                    }, 4000);
                });
            }
        }
        const firmwareUpdater = new FirmwareUpdater(client, options);
        
        client.onDeviceMethod('firmwareUpdate', function (request, response) {
            response.send(200, 'Firmware update started.');

            firmwareUpdater.initiateFirmwareUpdateFlow(request.payload.firmwareUrl, function (err) {
                if (err) {
                    console.log("firmware update failed");
                } else {
                    console.log("Completed firmwareUpdate flow");
                }
            });
        });
    }
});

Options

There are many options you can overload. Docs coming soon.

Getting Public Key for Cert Pinning

echo -n | openssl s_client -connect <your-url>:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.pem
openssl x509 -noout -in cert.pem -fingerprint