Skip to main content

JavaScript

Secondary Develop Elastel Gateways by JavaScript

Elastel gateways are built on an Open Linux system embedded computer, allowing users to create and run JavaScript applications by installing the Node.js runtime environment.

Typical use cases include:

  • High-performance data processing and device control
  • Serial, network, and protocol communication (e.g., Modbus RTU/TCP, MQTT, TCP/UDP)
  • Real-time control and edge logic processing
  • Integration with low-level device drivers or GPIO access

1. Node.js Installation

Due to different models using various types of ARM processors, corresponding Node.js version packages need to be downloaded.

ProductARM Processor
EG500/EG410/ElastBox400/EG324LARM64
EG324/EC212/EC211ARM32

1.1. Node.js Download and Configuration

  1. Node.js Download

    Open the official download page: https://nodejs.org/download/release/. We will use version v23.9.0 as an example (since v24 no longer supports 32-bit ARM).

  • For EG500/EG410/ElastBox400/EG324L (64-bit systems), download node-v23.9.0-linux-arm64.tar.gz.

  • For EG324 (32-bit systems), download node-v23.9.0-linux-armv7l.tar.gz.

    note

    EC212 and EC211 do not support Node.js due to limited storage.

    nodejs_download

  1. Decompress and Set Environment Variables on the Embedded Computer

    Decompress the downloaded file on the Elastel embedded computer.
    Here, we assume the decompression directory is /usr/local. Taking an EG500 64-bit system as an example, set the system environment variables:

    export PATH=/usr/local/node-v23.9.0-linux-arm64/bin:$PATH

    Then use node -v to check the Node.js version number. node_v

    Note: Higher versions of Node.js may require higher versions of the libc library. If the current hardware does not support it, switch to a lower Node.js version or update the file system.


2. Programming Example: LED Control (ledtest)

The following program controls the system LED blinking via /dev/led:

const fs = require('fs');

const deviceFilePath = '/dev/led';

let writeState = 0;

function writeToDevice() {
writeState = writeState === 0 ? 1 : 0;
const dataToWrite = writeState.toString();

fs.writeFile(deviceFilePath, dataToWrite, (err) => {
if (err) {
if (err.code === 'ENOENT') {
console.error(`Error: Device file ${deviceFilePath} not found. Please ensure the device is connected and the driver is loaded.`);
} else if (err.code === 'EACCES') {
console.error(`Error: Access to ${deviceFilePath} denied. Please ensure you have appropriate permissions (e.g., run as root).`);
} else {
console.error('Error writing to device file:', err);
}
}

setTimeout(writeToDevice, 500);
});
}

writeToDevice();

2.1. Running the Program (On the Embedded Computer)

  1. Create JavaScript Source File

    On the embedded computer, create a ledtest.js file and copy the code above into it, or by uploading the ledtest.js source file from your PC to a directory on the embedded computer (e.g., /home/admin/) via SFTP.

  2. Run the Program

    node ledtest.js

The SYS LED will blink every 0.5 seconds. The program runs until you stop it manually (e.g., Ctrl+C).


  • Use built-in interfaces (e.g., serial ports, GPIO, LED) for development.
  • Configure /etc/init.d/rcS for startup services or use crontab for scheduled runs.

4. Appendix Tables

EG324 Peripheral ResourceDevice Interface Name
COM1/dev/ttyAMA0
COM2/dev/ttyAMA1
COM3/dev/ttyAMA2
COM4/dev/ttyAMA3
SYS LED Indicator/dev/led
SYS2 LED Indicator/dev/led2
Buzzer/dev/buzzer
Ethernet Port 1eth0
Ethernet Port 2eth1
Note

For other models, please contact Elastel support or refer to models hardware manuals for Peripheral Interface tables.

  • Official Website: https://www.elastel.com
  • Support Email: support@elastel.com