NCD Sensors OTA Firmware Update with Node-RED

Table of Contents

Introduction

In this article, we aim to demonstrate how to enhance the firmware upload process to an NCD Sensor using Node-RED with OTA (Over-the-Air) functionality. This means updating the firmware without needing physical access to the sensor. This procedure can be useful in scenarios where you need to update your device’s firmware. As you will see, the process is quite straightforward: simply import a flow into your Node-RED workspace, access the corresponding FIRMWARE.ncd file—whether local or directly from the repository—select the device, and wait for the firmware upload process to complete.

Requirements

To carry out this procedure, you likely already have an NCD Sensor that you wish to update or reload with firmware. To perform the firmware upload, an Enterprise IIoT Gateway or Industrial Wireless Modem in either Ethernet or USB version is required. It is also highly probable that you already possess one of these devices.

If you do not have one of these devices, you can find them listed below:

Enterprise IIoT Gateway
Enterprise IIoT Gateway
Enterprise IIoT Gateway Lite
Wireless Ethernet Modem
Wireless USB Modem

If you are still unsure whether your application requires a Gateway or a Modem, you can find a comprehensive guide on the differences between these two devices below:

To carry out this procedure, it is essential to have an instance of Node-RED installed and running, as well as our Enterprise NCD library. Our Enterprise IIoT Gateway and Enterprise IIoT Gateway Lite come with a pre-installed and ready-to-run instance of Node-RED, along with the library and a basic flow available. If you are using an Industrial Wireless Modem, you will need to manually install Node-RED on a PC to which the modem is connected. Here you can find a guide on how to install Node-RED and the NCD Enterprise library on a Windows PC:

Node-RED Explained in Brief

Nodered Logo

Node-RED is a visual programming tool that provides a browser-based editor for creating applications by connecting predefined functions (nodes). Despite its technical nature, Node-RED offers a user-friendly interface. As an open-source project under the OpenJS Foundation, it is free to use with no subscription fees. You can install and run Node-RED locally on your PC, or, in the case of our Enterprise IIoT Gateway, it comes pre-installed and operates as a service. Node-RED, in conjunction with our Enterprise NCD library, forms a powerful tool for acquiring, managing, configuring, and uploading firmware through an intuitive interface. This combination offers a streamlined approach to optimizing the setup, configuration, and management of NCD sensor data.

NCD Enterprise Library

This library facilitates communication with and configuration of the NCD Wireless Sensor Line. It can be employed in conjunction with Node-RED to communicate and manage a Wireless Sensor Network using the Node-RED flow-based development tool on any platform. Additionally, as demonstrated, the library acts as an interface for uploading Firmware Updates to NCD Sensors. As mentioned earlier, this library is pre-installed on the Enterprise IIoT Gateway and is ready for immediate deployment.

Firmware.ncd File

You need to have the “FIRMWARE.ncd” file corresponding to the version and SKU model of your NCD sensor device. This procedure allows you to upload the firmware either from a local file or by pointing to a GitHub repository in the cloud to access the “.ncd” file directly from the flow in Node-RED. Below is the GitHub repository where you can find the available “FIRMWARE.ncd” files:

Option 1) GitHub URL FIRMWARE.ncd

The first option is to access the ‘FIRMWARE.ncd’ file directly from the Node-RED flow via the GitHub repository in the cloud. This requires internet access from the Enterprise IIoT Gateway or from the PC if using an Industrial Wireless Modem. This approach involves specifying the URL to which the flow should point in order to locate the ‘FIRMWARE.ncd’ file. You can obtain this URL by navigating to the GitHub repository, locating the ‘FIRMWARE.ncd’ file specific to your device (NCD Sensor).

Afterward, you should right-click on the ‘Raw’ button and select the ‘Copy Link’ option. Once this is done, you will have the remote path for the ‘FIRMWARE.ncd’ file, which you will need to specify in the Node-RED flow as we will discuss later. You can use a text editor to save this link.

NCD Firmware update get raw url

Option 2) Download FIRMWARE.ncd

The second available option is to download the corresponding file to have it locally. To do this, you should access the repository using the link provided, and then navigate through the folders to locate the firmware specific to your device.

NCD Firmware GitHub Repository

Once you have located the appropriate file, you should click on it as shown in the following image:

NCD Firmware GitHub Repository

Finally, to begin downloading the file locally from the GitHub repository, you should click on the ‘Download raw file’ button, as shown in the following image:

NCD Firmware GitHub Repository

You will be able to view the downloaded file; you should note the download path. This will be necessary later to specify to the Node-RED flow where to find the ‘FIRMWARE.ncd’ file. The path corresponds to the location or directory where the file is stored on your operating system, and may look something like: ‘C:\Users\Username\Downloads\V4_PR55-88.ncd.’

NCD Firmware GitHub Repository

Over-the-air Firmware Update Overview

Now that we have the path to our ‘FIRMWARE.ncd’ file, either locally or remotely, you only need to import the flow that allows us to access the file and initiate the firmware upload, which we will cover in the following steps.

The following is a graphical description of the firmware upload process. We can see that the flow within Node-RED accesses a ‘FIRMWARE.ncd’ file located either at a local path or a remote URL. Once the file is accessed, we specify the MAC address of the field device for which we want to perform the firmware upload. After this, we pass this value to the flow, which then waits for a FLY message from the corresponding sensor. Upon receiving the FLY message, the firmware upload begins automatically.

NCD Firmware update Node-RED Overview

Firmware Update Node-RED Flow

The next step is to import the flow responsible for the firmware upload. To do this, you need to copy the following flow in JSON format:

				
					[{"id":"22f1bf4f8036848c","type":"ncd-gateway-node","z":"659f98d7808980b1","name":"","connection":"3a158777559a1790","unknown_devices":0,"outputs":1,"x":730,"y":420,"wires":[["f1045e7e40a84964"]]},{"id":"f1045e7e40a84964","type":"debug","z":"659f98d7808980b1","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":420,"wires":[]},{"id":"a45e8334a1d7b8c2","type":"group","z":"659f98d7808980b1","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["4bdf8dadf4d716e2","79929f5de4ecbf56","e88be0604430370d","7afb268b9de278c3"],"x":14,"y":19,"w":952,"h":122},{"id":"4bdf8dadf4d716e2","type":"inject","z":"659f98d7808980b1","g":"a45e8334a1d7b8c2","name":"add_firmware_file from Local","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"add_firmware_file","x":180,"y":100,"wires":[["e88be0604430370d"]]},{"id":"79929f5de4ecbf56","type":"debug","z":"659f98d7808980b1","g":"a45e8334a1d7b8c2","name":"from Local","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":100,"wires":[]},{"id":"e88be0604430370d","type":"file in","z":"659f98d7808980b1","g":"a45e8334a1d7b8c2","name":"Read file from local storage","filename":"","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":460,"y":100,"wires":[["79929f5de4ecbf56","22f1bf4f8036848c"]]},{"id":"7afb268b9de278c3","type":"comment","z":"659f98d7808980b1","g":"a45e8334a1d7b8c2","name":"Pull from local machine","info":"","x":380,"y":60,"wires":[]},{"id":"8b83f6b4e7e27547","type":"group","z":"659f98d7808980b1","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["870a66c17edfbbe7","00c23d4cb97fd007","d82ae7adf18ec788","31af8e4cb0af01b5"],"x":14,"y":159,"w":952,"h":122},{"id":"870a66c17edfbbe7","type":"debug","z":"659f98d7808980b1","g":"8b83f6b4e7e27547","name":"from Github","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":240,"wires":[]},{"id":"00c23d4cb97fd007","type":"inject","z":"659f98d7808980b1","g":"8b83f6b4e7e27547","name":"add_firmware_file from github","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"add_firmware_file","x":180,"y":240,"wires":[["d82ae7adf18ec788"]]},{"id":"d82ae7adf18ec788","type":"http request","z":"659f98d7808980b1","g":"8b83f6b4e7e27547","name":"HTTP GET from Github","method":"GET","ret":"bin","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":450,"y":240,"wires":[["870a66c17edfbbe7","22f1bf4f8036848c"]]},{"id":"31af8e4cb0af01b5","type":"comment","z":"659f98d7808980b1","g":"8b83f6b4e7e27547","name":"Pull file from GitHub","info":"","x":370,"y":200,"wires":[]},{"id":"5f6e9623db5303ea","type":"group","z":"659f98d7808980b1","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["774b49db49c6a58f","9df27dc1f3814dbc"],"x":14,"y":339,"w":432,"h":122},{"id":"774b49db49c6a58f","type":"inject","z":"659f98d7808980b1","g":"5f6e9623db5303ea","name":"Inject MAC of sensor to update","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ota_firmware_update_single","payload":"00:13:a2:00:42:53:64:53","payloadType":"str","x":190,"y":420,"wires":[["22f1bf4f8036848c"]]},{"id":"9df27dc1f3814dbc","type":"comment","z":"659f98d7808980b1","g":"5f6e9623db5303ea","name":"Inject single MAC/Serial address for device to update","info":"","x":230,"y":380,"wires":[]},{"id":"3a158777559a1790","type":"ncd-gateway-config","name":"","comm_type":"serial","ip_address":"","tcp_port":"2101","port":"/dev/ttymxc2","baudRate":"115200","pan_id":"7FFF","rssi":false}]
				
			

Import Flow

Next, navigate to the main menu of Node-RED and select the ‘Import’ option, as shown in the following image:

Node-RED Import menu

This action will open a window with a text input field. You should paste the flow you copied in the previous step into this text box, as shown in the following image:

Node RED pasting json code

Once you have pasted the flow into the text box, click the ‘IMPORT’ button to complete the flow import process:

Import nodes in current workspace Node-RED

You will see that the flow has been imported successfully. The next step is to locate the flow within your workspace:

NCD Firmware Update Import Node-RED Flow

This Flow is designed to work with the ‘Serial Device’ properties for the Enterprise IIoT Gateway by default. By accessing the properties of the ‘Wireless Gateway’ node, you will observe that the ‘Serial Device’ property is configured with the port ‘/dev/ttymxc2 (115200)‘.

Enterprise IIoT Gateway

If you are using an Enterprise IIoT Gateway to perform firmware update, you will not need to modify this property.

NCD Wireless Gateway Enterprise Port

Wireless USB Modem

For a USB modem on Windows, it might be something like ‘COM4’. An example is shown in the following image:

NCD Wireless Gateway COM port

The next step is to specify the local or remote (GitHub) path of the ‘FIRMWARE.ncd’ file that you want to upload to the NCD sensor. This flow allows you to choose between these two options. If you are using a remote path (GitHub URL) (RECOMMENDED), you should double-click the ‘HTTP GET from Github’ node to access its properties. Then, paste the remote URL into the ‘URL’ property:

If you are using a file that has been downloaded and is stored locally, double-click the ‘Read file from local Storage’ node to access its properties. Then, copy and paste the local path where the ‘FIRMWARE.ncd’ file is located into the ‘Filename’ property:

NCD Firmware Update Local Path

Once this is done, the next step is to identify the MAC address of the device to which you wish to upload the firmware. You can obtain this address from the ‘sensor_data’ message of the relevant sensor. Then, access the properties of the ‘Inject MAC of sensor to update’ node by double-clicking on it. Within the properties, paste or enter the MAC address of the target NCD sensor, which is the device that will receive the firmware upload:

Once this is done, click the ‘DEPLOY‘ button to save and apply the changes made to the flow:

NCD Firmware update node-red Flow

Enable Flow process

To begin the firmware upload procedure with the parameters previously set, the first step is to activate the corresponding ‘Inject’ node.

In this case, you should activate the ‘Inject: add_firmware_file from github’ node. Similarly, upon performing this action, you will see two messages in the debug tab: one containing a buffer of the ‘FIRMWARE.ncd’ file and another from the Wireless Gateway node, indicating the status of the file and confirming that it is ready to be sent to the sensor.

The procedure is very similar if you wish to access the ‘FIRMWARE.ncd’ file from the local path.

The first message is a status update, indicating whether the flow successfully accessed the ‘FIRMWARE.ncd’ file.

NCD Firmware Update Results

The second message comes from the Wireless Gateway node and indicates whether the ‘FIRMWARE.ncd’ file provided was read correctly.

NCD Firmware Update Results

The final step is to activate the ‘Inject MAC of sensor to update’ node, as shown in the following image:

NCD Firmware Update inject MAC

Now, the flow will wait for the target NCD sensor to send a FLY message. Once this message is received, the Wireless Gateway node will begin the firmware upload process to the target sensor. An example of the FLY message in the debug tab is shown in the following image:

machine uptime monitoring sensor FLY

As soon as the firmware upload process begins, you will automatically see incoming ACK messages in the debug window, indicating that the upload is in progress.

Upon completion of the firmware upload process, you will see a message labeled ‘update_stats’:

Finally, after the sensor restarts with the newly loaded firmware, you should see a message indicating the updated firmware version. In this case, it should show a change from an initial version 3 to version 4:

NCD Firmware update v4 machine uptime monitoring sensor

Summary

This article outlined the step-by-step process and necessary requirements for performing a firmware upload or update to an NCD sensor using Node-RED and our dedicated NCD library.

Thank you, NCD Team.

Share this on:
Facebook
X
LinkedIn
Email
You Might Also Like: