npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-azure-iot-central

v1.5.4

Published

Receive Json from previous node, send it to IoT Central provisioned device (Scope ID, Device ID, SAS Key). Supports mqtt, amqp, http. Supports commands, reported and desired properties.

Downloads

12

Readme

Node-RED Azure IoT Central connector

This connector allows you easily connect your node red project to Azure IoT Central, providing the Scope ID, Device ID and Primary Key created in Azure IoT Central portal for a specific Device unsing SAS or X509 certificates. See here for more details.

This connector supports MQTT, AMQP, HTTP as transport.

You can send telemetry from your device to the cloud as json playload.You can look at the Raw data view to have a first look at the data received by IoT Central.

Commands

Commands from IoT Central (up to 5 ) to the device. For this scenario you have to use the method name used in IoT Central, when you have defined or imported the model. You fill the properties tab of the connector with the same command name, then define a Javascript function with the same name in your Node Red flow, as in following pictures.

Here is the 'echo' command:

step0

Here the Javascript node in the flow:

step1

The Javascript function must be registered at the flow context and invoked before calling the connector. In the sample a simple inject is used to register the function, but you can do in other ways.

step2

Here a template of Javascript code:

// This script create a command with the same name 'echo' 
// used in Azure IoT Central model of the device.
if(flow.get('echo')){
    return;   
}

function onEcho(request, response) {
  node.log('Received synchronous call to echo');
  node.log ("Method name: " + request.methodName );
  node.log ("Value: " + request.payload);
  
  data = "you said:" + String(request.payload);

  response.send(200, data , (err) => {
    if (err) {
      node.log('Unable to send method response: ' + err.toString());
    }
    else {
            node.log('Response to method \'' + request.methodName + '\' sent successfully... ' + data);
        }
  });
}

flow.set('echo',onEcho);

Reported and Desired properties

The connector support desired properties (Cloud (W) -> device(R)) and reported properties (Device(W) -> Cloud (R)).

To react to a desired properties you have to register a Javascript function at the flow level and invoke it before using the connector, this because the connector expected that function already registered.

Here we are registering the Javscript function using a simple inject node, but you can use other ways.

step3

step4

This is a sample Javascript code used for the brightness properties, the value of the property is stored using the flow context.

Important: the name of the handler of the desired property must be in the format as propertyname-handler as in the code below.

// This is a property set in IoT Central.
// It's a desired property for the device twin.
function brightness(newValue)
{
    node.log("received desired prop from cloud:" + newValue);
    flow.set('brightness', newValue);
}

flow.set('brightness-handler',brightness);

If you want to send a reported property create a json object that contain "reported.properties" field as follow.

{
    "reported.properties": {
        "status": true,
        "nonexists": true,
        "climate": {
            "minTemperature": "68",
            "maxTemperature": "76"
        }
    }
}

Install

npm install node-red-contrib-azure-iot-central

Authenticating using SAS

To use SAS simply go the IoT Central and get the connection details (Id scope, device id and primary key) as below:

step5

Now paste those values in the properties pane of the IoT Central Node:

step6

Authenticating using X.509 certificates

This connector support the use of X.509 certificates. To use those, you first have to add CA Root Certificcate to Azure IoT Central. Please go here for more details. For a full sample on how to generate a sample CA Root Certificate, Leaf Certificate and a device certificate, you can visit this link where you can also find a sample python code to test it. Once you have configurated the IoT Cental and have the subject-cert.pem (your device certificate) and the subject-private-key.pem (private key), you can reference them in propoterty pane:

step6

Credits

This connector has been written starting using this sample code.