Simulating IoT Virtual Devices with Node-RED and Backing Up Node Flows to GitHub

Simulating IoT Virtual Devices with Node-RED and Backing Up Node Flows to GitHub

Simulating IoT Virtual Devices with Node-RED

Node-RED is a visual programming tool that allows you to wire together devices, APIs, and online services in a flow-based manner. When it comes to simulating devices for Azure IoT Hub using Node-RED, here's how you can approach it: 

  1. Azure IoT Hub Setup: First, you need to set up an Azure IoT Hub in your Azure portal. This hub will serve as the central messaging hub for your simulated devices. 
  2. Node-RED Installation: Install Node-RED either locally on your machine or on a server that can access Azure IoT Hub. 
  3. MQTT node or Azure IoT Hub Nodes for Node-RED: Node-RED has nodes available that can interact directly with Azure IoT Hub. You can use the available node (MQTT) or install Azure IoT Hub Node using the Node-RED palette manager. 
  4. Simulating Devices: Use Node-RED to create flows that simulate the behavior of your IoT devices. For example, you can use inject nodes to generate simulated sensor data (temperature, humidity, etc.). 
  5. Sending Data to Azure IoT Hub: Use MQTT Node or Azure IoT Hub nodes within Node-RED to send this simulated data to Azure IoT Hub. These nodes typically require you to configure connection parameters such as the IoT Hub name, device ID, and shared access key. 
  6. Processing Data: Once data is sent to Azure IoT Hub, you can process it further using Azure services like Azure Stream Analytics, Azure Functions, or Azure Event Grid. 
  7. Monitoring and Analytics: Utilize Azure IoT Hub’s built-in monitoring capabilities to monitor the incoming data and the status of your devices. You can also integrate with Azure services like Azure Monitor for more detailed analytics and visualization. 
  8. Scaling and Deployment: Node-RED flows can be exported and imported, making it easier to replicate your device simulation setup across multiple instances or environments. 

Article content
Node-RED to Azure IoT Hub

Messages Received Azure IoT Hub from Node-Red

Article content
Azure IoT Hub Device Monitoring using Azure IoT Explorer tool

References:

Node-Red to Azure IoT Hub using MQTT out node

Node-Red to Azure IoT Hub using node-red-contrib-azure-iot-hub

Backing Up Node Flows to GitHub to version control 

  • Integrating Node-RED with GitHub can be quite useful for managing your Node-RED flows, especially if you want to version control your flows, collaborate with others, or simply keep backups. 

  • Using Node-RED you can create projects for the node flows and can easily integrate this with your GitHub account. By default, Node-RED project option is disable, you need to make it enable by making some changes in setting.js file as below (you will find this file in node red installed directory) 
  • {  projects: {  enabled: true  }  } 

  • Then you will find Create Project option in Node-RED GUI as below: 

Once you click on Project -> Now it will ask you for project name and details fill all the info correctly and your project will be created: 

Once your project is ready: 

As per below image test1 is the project name, click on three dots beside it, you can see below screen 

Article content
Project GitHub Configuration

Click on settings tab: 

Article content
Project GitHub Configuration

By assuming you have your GitHub account repository, copy the GitHub repository URL and paste it in the Git Remotes by clicking add remote button 

Article content
Project GitHub Configuration

When prompted, you will need to provide your username and a personal access token (PAT) for GitHub instead of your regular password to grant access.

Follow these steps to create a PAT: PAT_github.

Afterward, you will be able to push and retrieve your changes in Node-RED from GitHub.

By utilizing Node-RED’s visual programming interface and Azure IoT Hub’s robust messaging capabilities, you can effectively simulate and manage IoT device data flows. This enables rapid development and testing of IoT solutions before deploying them at scale, making it particularly useful for prototyping, development, and initial testing phases of IoT projects.

Important Note: If you are installing Node-RED in Azure Container Instance, the Project Feature will not function correctly unless you mount an Azure file share in the Azure Container Instance. By default, Azure Container Instances are stateless. If the container is restarted, crashes, or stops, all of its state is lost. To persist state beyond the lifetime of the container, you must mount a volume from an external store. Without mounting Azure files, the container will not persist its flow states, resulting in the loss of changes with every restart. With file share mounting, all flows and changes made earlier can be persisted through the storage account.

Reference: Mount an Azure file share in the Azure Container

Dm me if interested in Tata Consultancy Services.

Like
Reply

Have you ever tried Node-Red code in RPI HMI?

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore content categories