Node.js
Caution
- This Router App has been tested on a router with firmware version 6.3.10. After updating the router firmware to a higher version, check whether a newer version of the Router App has also been released and update it accordingly for compatibility.
- This Router App is only compatible with v3 and v4 platform routers.
Node.js Router App
Introduction
The Node.js node is a proprietary server-side JavaScript runtime environment available for Advantech cellular routers. This node is used by Advantech modules written in JavaScript, but can be used by any other third-party JavaScript application for router administration and maintenance.
This Router App contains the following nodes in addition to the built-in nodes:
- node-authenticate-pam — asynchronous PAM authentication for Node.js
- router node — a proprietary node for Advantech's cellular routers, described in detail in the Router Node section
Building the Custom Nodes
An official way to build and install a node is using the npm command. However, there are some limitations as Advantech routers are embedded devices without a full Linux OS and with specialized hardware. You can install the npm Router App to the router and use it in the common way, or prepare nodes with the npm tool on your PC and then copy them to the router. Note that you cannot install all nodes available in the npm repository.
For more details, see: https://icr.advantech.com/products/software/router-apps#node-red — refer to the Building the Custom Nodes section in the Node-RED Application Note.
Router Node
Tips
This section is dedicated especially to programmers.
The router node (named router) provides access to router-specific functions and hardware. You can load the Node.js node in your code by using require("router"), for example:
var r = require("router");Tips
The variable r from this example is used to access all the properties in the following sections.
Simple Example of Router Node Use
The figure below shows an example of loading the Node.js node.

Node Properties
productName
Read-only string variable containing the router's product name. Example of usage:
console.log(r.productName);Output: SPECTRE-v3T-LTE
productModel
Read-only string variable containing the router's model indication. Example of usage:
console.log(r.productModel);Output: ICR-3201W
productRevision
Read-only string variable containing the router's product revision number. Example of usage:
console.log(r.productRevision);Output: 1.0
platformCode
Read-only string variable containing the router's platform code. Supported by routers of v3 and v4 production platforms. Example of usage:
console.log(r.platformCode);Output: V3
serialNumber
Read-only string variable containing the router's serial number. Example of usage:
console.log(r.serialNumber);Output: ACZ1100000322054
firmwareVersion
Read-only string variable containing the router's firmware version. Example of usage:
console.log(r.firmwareVersion);Output: 6.2.1 (2019-10-16)
RTCBatteryOK
Read-only boolean variable containing the router's RTC battery state. true means OK, false means bad. Example of usage:
console.log(r.RTCBatteryOK);Output: true
powerSupply
Read-only decimal number variable containing the router's power supply voltage. Example of usage:
console.log(r.powerSupply + " V");Output: 11.701 V
temperature
Read-only integer number variable containing the router's internal temperature in Celsius degrees. Example of usage:
console.log(r.temperature + " °C");Output: 39 °C
usrLED
Write-only boolean variable for controlling the router's USR LED. Example of usage:
r.usrLED = true;Sets the USR LED to ON (lit).
bIn
Read-only array with values on the router's binary inputs. The array has items corresponding to the number of binary inputs. For example, if the router has BIN0 and BIN1, the array has valid indexes 0 and 1. Array items can have values 0 or 1. Example of usage:
console.log("The secondary binary input: " + r.bIn[1]);Output: The secondary binary input: 0
bOut
Array for the router's binary outputs. Similar to bIn, but values can also be written — writing a value changes the output state. Example of usage:
console.log(r.bOut[0]);Output: 1
r.bOut[0] = 0;Sets the first binary output to 0.
XBus
Object for working with XBus. XBus is a proprietary bus for communication between processes. For example, you can subscribe to information about which network interface goes up/down, or receive SMS from an mwan daemon. You can also send/subscribe your own topics between your applications.
XBus.publish(topic, payload, store=false)
Sends a message with a topic string and payload string to XBus. Example of usage:
r.xBus.publish("watchdog/proc/myapp", "Timeout: 300");Sends a watchdog request to the system to watch the myapp application. The application must send this message regularly within the period defined in the previous message (300 s in this example). Timeout 0 stops watching.
XBus.subscribe(topic, callback)
Subscribes to receive messages with the given topic. Example of usage:
xbus.subscribe("status/mobile/mwan0", (msg) => {console.log(msg.payload);});Asynchronous output:
Registration: Home Network
Technology: LTE
Signal-Strength: -88 dBm
Signal-Quality: -8 dBXBus.unsubscribe(topic)
Unsubscribes from a topic. Example of usage:
r.XBus.unsubscribe(id);Stops receiving network registration information from the previous example.
XBus.list()
Lists stored messages. Example of usage:
r.XBus.list();Output:
[ 'iface/ipv4/mwan0/config',
'iface/ipv4/mwan0/running',
'iface/ipv4/mwan1/config',
'iface/ipv4/mwan1/running',
'status/mobile/mwan0',
'status/mobile/mwan1',
'watchdog/proc/bard',
'watchdog/proc/bard6',
'watchdog/proc/mwan1d',
'watchdog/proc/mwan2d',
'watchdog/proc/mwanxd' ]XBus.read(topic)
Reads a stored message from XBus. Example of usage:
r.XBus.read("iface/ipv4/mwan0/config");Output:
Up: 1
Iface: usb0
Address: 10.184.131.221
Gateway: 192.168.253.254
DNS1: 217.77.165.211
DNS2: 217.77.165.81configuration
Object containing the router configuration. A configuration item can be read by getting an object property and written by setting an object property. The object keys are the same as configuration keys in the settings files. The firmware configurations are placed in the /etc/settings.* files. Router App configurations are placed in the /opt/*/etc/settings files. The Router Report (Web UI: Status / System Log / Save Report) contains a full list of the current configuration and may be the easiest way to find the requested configuration key.
If a given key does not exist, a read value is undefined and a written value causes an exception (in strict mode). It is not possible to add a new non-existing configuration item, only to modify an existing one. All configuration values are treated as strings — if a different type is needed, you must convert it. The node does not perform any value validation; you are responsible for sending the correct values.
Example — reading a configuration value:
console.log("Current router AP SSID is " + r.configuration["WIFI_AP_SSID"]);For WIFI_AP_SSID=ROUTER_AP in /etc/settings.wifi_ap (or the SSID field in the WiFi — Access Point 1 form), output will be:
Current router AP SSID is ROUTER_APExample — setting a configuration value:
r.configuration["ETH_IPADDR"] = "192.168.99.1"Changes the IP address on the eth0 interface.
Note: A new configuration is only written. To apply it to the running environment, the router or the related service must be restarted. For the example above, the following shell command can be used:
/etc/init.d/eth restart