🤖

NodeRed

2 notes  •  IoT & AI

Install Node-RED with MQTT and Modbus on Ubuntu

Node-RED is a flow-based programming tool for IoT and automation. This guide installs Node-RED on Ubuntu with an Apache reverse proxy, Let's Encrypt SSL, the Mosquitto MQTT broker, and the Modbus TCP node.

Prerequisites

  • Ubuntu server with root access
  • A domain name pointed to the server

Steps

# Install base packages
apt install curl git zip software-properties-common apache2

# Install Node.js 18
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
apt-get install -y nodejs

# Install Node-RED globally
npm install -g --unsafe-perm node-red

# Install and configure Certbot
snap install core
snap install certbot --classic
certbot --apache

# Configure Node-RED settings
cd ~/.node-red/
nano settings.js

# Link Let's Encrypt certs for Node-RED HTTPS
ln -s /etc/letsencrypt/archive/yourdomain.com/cert1.pem cert.pem
ln -s /etc/letsencrypt/archive/yourdomain.com/privkey1.pem privkey.pem

# Generate a hashed admin password
node-red admin hash-pw

# Install build tools and Modbus TCP node
apt install g++
npm install node-red-contrib-modbustcp

Install Mosquitto MQTT Broker

apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
apt install mosquitto libmosquitto-dev mosquitto-clients
service mosquitto status

Verify

# Start Node-RED
node-red

# Test MQTT pub/sub
mosquitto_pub -t test/topic -m 'hello'
mosquitto_sub -t test/topic

Notes

  • Run Node-RED as a systemd service for production: node-red admin hash-pw to generate the password hash, then set it in settings.js under adminAuth.
  • By default Node-RED listens on port 1880 — proxy it through Apache or Nginx for HTTPS.

Cross-Compile ARM Binaries with crosstool-NG and QEMU

crosstool-NG builds custom cross-compiler toolchains for embedded ARM targets. QEMU can then run the resulting ARM binaries on an x86 host without real hardware.

Prerequisites

  • Ubuntu with build tools installed
  • Sufficient disk space (~10 GB for toolchain build)

Build the Cross-Compiler

# Install build dependencies
apt install build-essential git autoconf bison flex texinfo help2man \
  gawk libtool-bin libncurses5-dev

# Clone and bootstrap crosstool-NG
mkdir toolchain && cd toolchain
git clone https://github.com/crosstool-ng/crosstool-ng.git
cd crosstool-ng
./bootstrap
./configure --enable-local
make

# Run as a non-root user
# List available sample configs
./ct-ng list-samples

# Select an ARM target
./ct-ng arm-cortexa9_neon-linux-gnueabihf

# (Optional) Customize the config
./ct-ng menuconfig

# Build the toolchain
./ct-ng build

Compile and Run an ARM Binary with QEMU

# Add the toolchain to PATH
export PATH=$PATH:$HOME/x-tools/arm-myarm-linux-uclibcgnueabihf/bin

# Cross-compile a hello world
arm-linux-gcc helloworld.c -o helloworld_arm

# Run under QEMU with the correct sysroot
qemu-arm -L ~/x-tools/arm-myarm-linux-uclibcgnueabihf/\
arm-myarm-linux-uclibcgnueabihf/sysroot ./helloworld_arm

Cleanup

# Remove source code and build artifacts (keeps the toolchain)
./ct-ng clean

Notes

  • The toolchain build takes 30–60 minutes depending on hardware.
  • Do not run ct-ng build as root — crosstool-NG explicitly checks for this.
  • For QEMU system emulation (full VM), use qemu-system-arm instead of qemu-arm (user-mode emulation).