• Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us
  • Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us

Client Libraries & SDKs

home/Documentation/Client Libraries & SDKs
  • Device SDK Reference
    • Overview
    • Device Authentication Options
    • Data Flow
    • Public Methods
      • Device Connection
      • Send Telemetry
      • Get Attributes
      • Send acknowledgment
      • Update Twin
    • SDKs (Message version 1.0)
      • DOT NET (C#)
      • Node.js
      • Java
      • Python
      • iOS
      • Android
      • Embedded
      • C language
      • Build Your Own SDK
      • Node-RED
        • IoTConnect Node-red 1.0.9
        • IoTConnect Node-red 1.0.8
      • Node-RED Subflow
        • Single Device
        • Multiple Device
    • SDKs (Message version 2.1)
      • Python
      • DOT NET (C#)
      • C language
        • IoTConnect Generic C SDK
          • Linux Build Instructions
          • Windows Build Instructions
      • Python 1.1
    • Code Samples
      • Node.js
        • TPM 3.1
        • Standard SDK 3.0
        • Standard
        • TPM
        • Standard SDK 3.0.1
        • Standard 2.0
      • Java
        • Standard
        • Standard 2.0
        • Standard 3.0
      • Python
        • Standard 2.0
        • TPM 2.1
        • Standard 3.0.1
        • Standard
        • TPM
          • TPM 3.0.1
        • TPM 3.0
        • Standard 3.0.2
        • Standard 3.0.3
        • Standard 3.0.4
        • Python SDK
      • iOS
        • ios1.0.1
      • C Language
        • nRF9160 DK
        • STM32L4
        • ESP32
        • Standard 3.0
        • Standard 2.0
        • Standard 3.1
      • Android
        • Standard 3.0
        • Standard 2.0.6
        • Standard 2.0.0
      • DOT NET (C#)
        • Standard
        • Standard 2.0
        • Standard 3.0
    • Device Message 1.0
      • D2C (Device to Cloud)
        • IoTConnect SDK
        • Custom SDK
      • C2D (Cloud to Device)
        • IoTConnect SDK
        • Custom SDK
      • Troubleshooting & Response codes
      • Know Your Essentials
    • Device Message 2.1
    • AWS Device Message 2.1
    • SDK Deep-diving
Download PDF

Single Device

Card Image

IoTConnect Node-red Subflow

Version 1.1.0

Release On 01/23

Publish dataReceive command

Description

The Node-red includes documentation and a usage guide for the user to connect the device to the IoTConnect.

Prerequisite tools:

  1. Node version: 18.4.4
  2. NodeRed version: v2.2.2

Step 1: Install required packages:

Go to the node-red folder and run below two npm commands

npm install axios

npm install async-mqtt

Step 2: Setup environment variables

Before starting you need to setup IoTConnect variables like environment, cpid & uniqueid, and add module in global context.

Step 2.1: Setup IoTConnect sub flow environment variables

Open settings.js file form your Node-RED user directory add below lines before module.exports =

process.env.iotc_cpid = “”;

process.env.iotc_env = “”;

process.env.iotc_uniqueId = “”

WARNING: If above settings are missing or blank then IoTConnect MQTT Sub flow will not start and give exception

step 2.2: Add modules in global context

Search for function functionGlobalContext and add two lines

axiosModule:require(‘axios’),

asyncmqtt:require(‘async-mqtt’)

step 3: Import sub-flow into your node-red

WARNING: Do not make any changes to this flow.

step 4: Create your flow or add sub flow in your existing flow [below is snap of new flow]

Sub flow have one input and 3 output.

Output #1: Gives telemetry log

Output #2: Gives cloud to device commands

Output #3: Gives error

How it works?

  • Connection will get created on first inject
  • On first inject it will ask for IoTConnect identity and if device is okay then it will connect and send data. if device is not okay then it will add data into memory queue.
  • Below state will add data in memory queue
    • Device initialization failed due to device not found, device not registered/acquired, device is inactive & cpid not found
  • On reconnect it will send data form memory queue first
  • If connection got lost after successful connection it will start adding data into queue
  • If connection is lost during publishing data; it will wait for some second to restore connection if not, then it will drop data.
  • On connection break, it will check internet connectivity every 10 sec – if restored data will be sent form queue
  • On 10 consecutive failed attempts of initialization, it will wait for 10 sec – data will be added to memory queue
  • Telemetry output will display data which has been sent
  • Error output will show error occurred during operation
  • Command output will give two commands
    • cmdType: 0x01 (Simple command)
{
"cmdType": "0x01",
"data": {
        "cpid": "",
        "guid": "",
        "uniqueId": "",
        "command": "",
        "ack": false,
        "ackId": "",
        "cmdType": "0x01"
}
}
    • cmdType: 0x02 (OTA Command)
{
"cmdType": "0x02",
"data": {
        "cpid": "",
        "guid": "",
        "uniqueId": "",
        "command": "ota",
        "ack": false,
        "ackId": "",
        "cmdType": "0x02",
        "ver": {
            "sw": "",
            "hw": ""
        },
        "urls": [{
                "url": "",
                "tag": ""
            }
        ]
}
}

 

 

Powered by Softweb – An Avnet Company.

Copyright ©2022 Avnet, Inc. All rights reserved.

Human Rights Privacy Terms of Use