Showing posts with label IoT. Show all posts
Showing posts with label IoT. Show all posts

Saturday, January 31, 2026

CAN Bus Multi-Sensor Node with ESP32 and KiCad PCB

Ambient Light + Air Quality + More — a reliable, low-cost sensor network for home, lab, and in-vehicle prototypes, built around CAN with OTA updates and multi-node management.

Last updated: February 11, 2026

Why CAN for sensors?

CAN was designed for noisy, distributed environments and it shines when you want dependable, multi-drop communication over long cables. That makes it a strong backbone not only for vehicles, but also for home automation and lab setups where Wi-Fi can be unreliable or too power-hungry.

This project builds a CAN-based sensor node and a companion display client that together provide:

  • Ambient light, temperature, humidity, pressure, IAQ, CO₂eq, VOC
  • Multi-node addressing (up to 16 nodes on the same bus)
  • Batch operations: --all and --nodes=0,1,2 targeting for discovery, monitoring, OTA, reboot, and more
  • A/B OTA firmware updates over CAN (~3.5 KB/s) with partition verification
  • Live dashboard monitor (updates in-place) and physical node identification (LED blink)
  • Device management and automated sanity testing with a CLI tool

System overview

The system has three pieces:

  1. Sensor nodes — ESP32-C3 + ALS + BME680/BME688 + CAN transceiver
  2. Monitor/display node — ESP32-C3 + OLED + CAN transceiver
  3. Host tool — can-sensor-tool for monitoring, management, and OTA (Linux / SocketCAN)

All nodes communicate at 500 kbps over a standard CAN bus.

CAN-based sensor setup diagram

System overview: sensor nodes + monitor node + CAN-USB adapter + RJ-11 junction board.

Hardware design

Core components

  • ESP32-C3 SuperMini (~$2 board)
  • SN65HVD230 CAN transceiver (3.3 V native — no level-shifting needed)
  • ALS sensor: VEML7700 or OPT3001 (board footprint supports either; mount only one)
  • BME680/BME688 for temperature, humidity, pressure, and IAQ data
  • On-board buck converter: 6–30 V input (12 V typical), generates stable 5 V / 3.3 V locally

Power-over-CAN using 6P4C (RJ-11)
The system uses a two-pair telephone cable: one pair for CAN-H / CAN-L, one pair for power. Simple, low-cost, and practical. Tested reliably to 15 m with standard RJ-11 cables.

RJ-11 junction board

RJ-11 junction board — low-cost two-pair power + CAN distribution. This is a ready-made off-the-shelf board available from common electronics marketplaces.

Sensor board

Sensor board photo

Sensor board: ESP32-C3, ALS footprint, BME680, SN65HVD230 transceiver, buck converter, and RJ-11 connector.

Sensor board 3D render

3D render of the sensor board PCB.

Sensor board sub-modules

Sensor board sub-modules: base PCB with ESP32-C3 SuperMini, SN65HVD230 CAN transceiver, BME680 environmental sensor, VEML7700/OPT3001 ALS, buck converter, and RJ-11 connector.

Monitor board

Monitor board with OLED showing live data

Monitor board with OLED display showing live values: 22 lux, 25.9 °C, 32 % RH, 989 hPa, IAQ 51 (Good).

Monitor board 3D render

3D render of the monitor board PCB.

Monitor board sub-modules

Monitor board sub-modules: base PCB with ESP32-C3 SuperMini, SN65HVD230 CAN transceiver, SSD1306 OLED display, buck converter, and RJ-11 connector.

Sensor auto-detection (one firmware, many boards)

The sensor firmware auto-detects what's connected at boot:

  • ALS: VEML7700 (0–120 K lux) or OPT3001 (0–83 K lux)
  • Environmental: BME680 or BME688

A single firmware image works across all hardware variants — no build-time configuration needed.

CAN architecture (high-level)

Each node gets 32 CAN message IDs (0x20 spacing):

  • 0x100–0x10F: sensor data for Node 0 (ALS at +0x00, ENV at +0x01, AIQ at +0x02, …)
  • 0x110–0x11F: control/management for Node 0 (stop, start, reboot, OTA, discovery, …)

The same layout repeats at +0x20 per node, supporting up to 16 nodes on a single bus. Reserved offsets are available for future sensor types (gas selectivity, mm-wave presence, etc.).

Full frame layouts and byte-level formats are documented in the repo README.

Real measurements (sample log)

The default can-sensor-tool monitor shows a live dashboard that updates in-place — no scrolling. With --all, it displays all discovered nodes side by side. Add --verbose for a scrolling log useful for debugging:

$ can-sensor-tool --all monitor --verbose
[Node 0] ALS (OPT3001): 79 lux, seq=13, config=201, status=OK
[Node 0] ENV: 24.83°C, 38% RH, 991.2 hPa, status=OK
[Node 0] AIQ: IAQ=50 (Good), accuracy=0, CO2=500 ppm, VOC=0 ppm, status=OK
[Node 1] ALS (OPT3001): 192 lux, seq=20, config=203, status=OK
[Node 1] ENV: 25.09°C, 36% RH, 991.2 hPa, status=OK
[Node 1] AIQ: IAQ=50 (Good), accuracy=0, CO2=500 ppm, VOC=0 ppm, status=OK
[Node 2] ALS (OPT3001): 0 lux, seq=24, config=200, status=OK
[Node 2] ENV: 25.15°C, 35% RH, 991.2 hPa, status=OK

Over this run, three nodes on the same bus report concurrently — light levels range from 0 (near-dark) to ~192 lux while temperature stays around 25 °C. IAQ reported "Good" with CO₂eq at 500 ppm throughout.

Automated sanity testing

The can-sensor-tool includes a sanity-test command that exercises the full node lifecycle in one shot — discovery, start/stop, interval accuracy, reboot, node-ID change, factory reset, OTA update, and final re-discovery:

$ can-sensor-tool sanity-test ./build/esp32-can-sensor.bin

[1/9] Discovery...         PASS: Node 0 responds to PING
[2/9] Device Info...       PASS: FW v1.0.1, sensors=0x13, ALS=OPT3001, partition=ota_1 (valid)
[3/9] Start/Stop...        PASS: Received 3 ALS msgs in 3s, 0 after STOP
[4/9] Monitor Interval...  PASS: Average interval: 977 ms (target: 1000 ms)
[5/9] Reboot...            PASS: Node rebooted and recovered in 2005 ms
[6/9] Set Node ID...       PASS: Successfully changed 0->1->0
[7/9] Factory Reset...     PASS: Factory reset completed in 2204 ms
[8/9] OTA Update...        PASS: OTA OK, node booted v1.0.1 on ota_0 (3.2 KB/s, 106369 ms)
[9/9] Final Discovery...   PASS: Node 0 still responds after all tests

Results: 9/9 passed, 0 failed

This makes it practical to validate firmware changes end-to-end before deploying to multiple nodes.

Device management + OTA over CAN

The can-sensor-tool handles discovery, monitoring, and A/B OTA firmware updates over the CAN bus. With --all or --nodes=0,1,2, most commands target multiple nodes in one invocation.

Multi-node operations

  • can-sensor-tool --all info — query all nodes on the bus
  • can-sensor-tool --all monitor — live dashboard with all nodes updating in-place
  • can-sensor-tool --nodes=0,2 reboot — reboot specific nodes
  • can-sensor-tool --all identify — blink the onboard LED on every node for 5 seconds (useful for figuring out which board is which in a multi-node setup)

A/B OTA with partition verification

Each OTA update writes to the inactive partition slot, reboots into it, and keeps the previous slot as a rollback target. If the new firmware fails to validate on first boot, the bootloader automatically reverts after 3 attempts.

The tool now verifies the update end-to-end: it queries the active partition before the update, waits for the node to reboot, then confirms the node booted from the alternate partition. Batch updates (--all update) run sequentially — each node must come back online before the next update starts, preventing CAN bus disruption from rebooting nodes.

$ can-sensor-tool --all update ./build/esp32-can-sensor.bin
Discovering nodes on can0...
Found 3 node(s): 0 1 2

--- OTA Update: Node 0 (1/3) ---
Current partition: ota_1
Uploading: [==============================] 100% (334704/334704) 3.6 KB/s
Waiting for node 0 to reboot...
Node 0 back online (3.6s)
Partition switched: ota_1 -> ota_0 (v1.0.2)

--- OTA Update: Node 1 (2/3) ---
Current partition: ota_1
Uploading: [==============================] 100% (334704/334704) 3.6 KB/s
Waiting for node 1 to reboot...
Node 1 back online (3.6s)
Partition switched: ota_1 -> ota_0 (v1.0.2)

--- OTA Update: Node 2 (3/3) ---
Current partition: ota_0
Uploading: [==============================] 100% (334704/334704) 3.5 KB/s
Waiting for node 2 to reboot...
Node 2 back online (3.5s)
Partition switched: ota_0 -> ota_1 (v1.0.2)

--- OTA Update Summary ---
  Node 0: OK (ota_1 -> ota_0 (v1.0.2))
  Node 1: OK (ota_1 -> ota_0 (v1.0.2))
  Node 2: OK (ota_0 -> ota_1 (v1.0.2))
  Total: 3/3 succeeded

In testing, OTA reaches ~3.5–3.6 KB/s. A ~335 KB firmware image completes in ~93 seconds per node. All three nodes updated and verified in under 5 minutes total.

Use cases

Home & Lab

  • Multi-room light + environment monitoring
  • Low-cost wiring with RJ-11 and a junction board
  • Central monitoring on OLED or a PC via SocketCAN

In-vehicle prototype (POC)

  • Rugged wiring and noise-tolerant communication
  • Deterministic update rates across multiple nodes
  • OTA updates without pulling nodes from the vehicle

In-vehicle smart ambient sensing

  • Monitor cabin temperature, humidity, IAQ, CO₂eq, VOC, and BME688-based gas signals for passenger comfort and safety
  • Feed IVI/ADAS systems with real-time ambient conditions for alerts or policy decisions
  • Use ambient light data to adjust in-vehicle displays — HDR10+ Adaptive and Dolby Vision perform real-time dynamic tone-mapping that requires a continuous ambient light input to optimize frame rendering on the display (the HDR10+ Automotive spec mandates this ambient light feed)
  • Add human presence detection (planned) to enable occupancy-aware safety and convenience features

Enterprise / larger infrastructure

  • CAN as a reliable wired sensor backbone
  • Up to 16 nodes per bus today; extendable with multiple bus segments

Current limitations and roadmap

Current

  • No formal environmental or long-term reliability testing yet
  • Human presence detection (mmWave) not implemented

Planned

  • Add mmWave human presence sensor
  • Expand other sensor types using reserved CAN offsets

BSEC licensing note

BME680/BME688 air-quality outputs use Bosch Sensortec's BSEC 2.x library, which is proprietary and not included in this repo. To enable it, download the BSEC zip from Bosch, accept their license, and pass it to build.sh (see BME680_SETUP.md in the repo).

Build and flash (sensor board)

  1. Install ESP-IDF and download the Bosch BSEC library (e.g. bsec2-6-1-0_generic_release_22102024.zip).
  2. Connect the ESP32-C3 board to your PC via USB.
  3. Clone the sensor firmware repo and build:
git clone https://github.com/hackboxguy/Esp32-CAN-ALS.git
cd Esp32-CAN-ALS
./build.sh --target=esp32c3 --idfpath=$HOME/esp/esp-idf/ \
           --version=1.0.1 \
           --bsecpath=/path/to/bsec2-6-1-0_generic_release_22102024.zip
./build.sh --flash

Build and flash (monitor board)

  1. Install ESP-IDF.
  2. Connect the ESP32-C3 board to your PC via USB.
  3. Clone the display client repo and build:
git clone https://github.com/hackboxguy/Esp32-CAN-Disp-Client.git
cd Esp32-CAN-Disp-Client
idf.py set-target esp32c3
idf.py build flash

SOURCE CODE

github.com/hackboxguy/Esp32-CAN-ALS — sensor node firmware + can-sensor-tool

github.com/hackboxguy/Esp32-CAN-Disp-Client — OLED monitor client firmware

KICAD PCB FILES

CAN-Sensor-Board.zip — sensor board KiCad project + gerbers

CAN-Monitor-Board.zip — monitor board KiCad project + gerbers

Tuesday, April 16, 2024

Getting Started with AWS IoT on OpenWrt Routers

While the internet is flooded with hello-world examples and simulations demonstrating the connection and message exchange between AWS-IoT Devices and AWS-IoT-Core using various programming languages like Python, C, C++, and Java, some of us beginners, students, or enthusiasts find true satisfaction in delving into the world of connected devices through hands-on interactions with physical components. The real excitement lies in experiencing the tangible effects firsthand, rather than merely observing basic hello-world messages on a computer screen.

Demo Video

How It Works

In this video, I introduce an engaging approach for exploring AWS-IoT connectivity and its real-world implications using affordable and readily available hardware components sourced from online stores. For this demonstration, I use an affordable (~$30) GL.iNet pocket router as an IoT End-Node.

This router runs on a custom-built OpenWRT Linux image and hosts an AWS IoT device agent service based on the aws-iot-device-sdk-cpp-v2. The WebUI of this custom Linux image allows you to easily configure and provision AWS IoT-specific settings such as:

  • Device certificates and private keys
  • AWS IoT Endpoints
  • Publish/subscribe topic trigger events
  • Custom scripts to control hardware accessories (switches, relays, LEDs, sensors)

Sunday, October 09, 2022

$30 Pocket Router as an AWS IoT Edge Device

How to flash a ~$30 GL.iNet MT300N-V2 pocket router with a custom OpenWrt image that includes the AWS IoT Device SDK and an aws-iot-pubsub-demo application — turning it into an AWS IoT Edge device that can feed local sensor data to the cloud.

GL.iNet MT300N-V2 pocket router as AWS IoT Edge device

GL.iNet MT300N-V2 pocket router — ready to become an AWS IoT Edge device.

Quick overview

Three steps to turn your pocket router into an AWS IoT Edge device:

  1. Flash the OEM firmware with the custom gl-mt300nv2-awsiot-demo.bin
  2. Upload your AWS-generated device certificate and private key via the web UI
  3. Reboot and watch Hello World messages published to your AWS IoT Core

Flashing the firmware

Step 1 — Connect your PC to the pocket router via Ethernet and power it on. Wait for the LED to stop blinking.

Setup diagram — PC connected to pocket router

Setup: PC connected to the pocket router via Ethernet cable.

Step 2 — Open http://192.168.8.1/cgi-bin/luci/admin/system/flashops in your browser (or follow GL.iNet's onboarding process).

Step 3 — Find the firmware upgrade menu and flash with gl-mt300nv2-awsiot-demo.bin.

Important: Disable "Keep settings" — you want to start with default settings.

Step 4 — Wait about 2 minutes until the LEDs stop blinking.

Step 5 — Disconnect and reconnect the Ethernet cable on your PC so it gets a new IP in the 192.168.20.x range.

Step 6 — Navigate to http://192.168.20.1 — you should see the new web UI:

Custom firmware web UI

Custom firmware web UI after successful flash.

AWS IoT configuration

Step 7 — Upload your device certificate and private key files through the web UI:

Certificate and key upload page

Upload your AWS-generated device certificate and private key.

Step 8 — Go to AWS-IoT → Service Settings, enter your endpoint, and click Save & Apply.

Before clicking Save & Apply, ensure your security policies on console.aws.amazon.com are set up correctly (see Step 10 below).

AWS IoT service settings page

Service Settings — enter your AWS IoT endpoint here.

Step 9 — Check the Service Log. If everything is configured correctly, you should see a "connection success" message:

Service log showing connection success

Service Log — "connection success" confirms the router is connected to AWS IoT Core.

Step 10 — On console.aws.amazon.com, ensure your security policies are set correctly:

AWS IoT security policies

AWS IoT security policies — required permissions for the device.

Testing publish and subscribe

Step 11 — On console.aws.amazon.com, subscribe to topic test/topic to see Hello World messages published from your pocket router. By default, the demo publishes 10 messages at 5-second intervals. To publish continuously, increase the Publish Count in the Service Settings page.

AWS IoT Core showing Hello World messages

AWS IoT Core — Hello World messages arriving from the pocket router.

Step 12 — To test the subscribe action, publish a JSON message to topic test/topic_led from the AWS console to control the router's LED:

{"powerstate" : "on"}
{"powerstate" : "off"}
Publishing LED control messages from AWS console

Publishing LED control commands from the AWS IoT console.

Other use cases

The pocket router can act as a gateway between AWS IoT Core and local Wi-Fi or USB-connected devices:

Use case diagram — pocket router as IoT gateway

Possible use cases — the pocket router bridges local devices to AWS IoT Core.

SOURCE CODE

github.com/hackboxguy/openwrt-wrapper — build instructions and sources

gl-mt300nv2-awsiot-demo.bin — pre-built firmware image

Thursday, January 03, 2019

Wi-Fi LED Fairy Light Controller with ESP8266

A DIY Wi-Fi-controlled 5 V switcher for USB LED fairy lights, built around an ESP-12F module running Tasmota firmware. Powered by a battery bank, it lets you toggle garden lights remotely from your phone — no 230 V wiring outdoors and no freezing walks to the power outlet.

LED fairy lights in the garden
LED fairy lights switched on at night

The lights

"USB Fairy Lights" or "USB String Lights" — 10 m / 100 LEDs, available from China for under ~$3. They are 5 V USB-powered and weather-proof (except the USB connector).

USB LED string light product photo
Close-up of the LED string circuit

The 100-LED circuit with 5.1 Ohm series resistor — consumes ~1.8 W at 5 V.

Close-up of a single LED

Close-up of a single LED — brightness difference between first and last LED is barely noticeable from a distance.

The ESP-12F 5 V switcher

An ESP-12F module with a MOSFET switches the USB 5 V supply to the LED string. Running Tasmota firmware, it connects to your Wi-Fi network and can be controlled from a phone or any MQTT/HTTP client.

ESP-12F switcher board — front
ESP-12F switcher board — rear
Complete setup — battery bank, ESP switcher, and LED string

Complete setup — battery bank, ESP-12F switcher, and LED fairy lights.

With Tasmota's default configuration (no deep sleep), the battery bank needs recharging every few days. A larger battery and ESP8266 deep sleep could extend runtime to weeks.

Assembly

Before starting, ensure the ESP-12F module is pre-programmed with Tasmota (or any OTA-capable firmware). See ESP-12F programming guide for first-time flashing.

Items needed:

Parts laid out for the build

Step 1:

Assembly step 1

Step 2:

Assembly step 2

Step 3:

Assembly step 3

Step 4:

Assembly step 4

Step 5:

Assembly step 5

Step 6:

Assembly step 6

Step 7:

Assembly step 7

Step 8:

Assembly step 8

Step 9:

Assembly step 9

Final assembly:

Completed switcher assembly
Switcher connected to battery bank and LED string

Completed setup — ESP-12F switcher between battery bank and LED fairy lights.

Tuesday, January 01, 2019

$20 Pocket Router as Domoticz Smart Home Gateway

A custom OpenWrt firmware (autom8box) that packs router + Domoticz server + MQTT broker into an all-in-one home automation gateway running on a ~$20 off-the-shelf GL-MT300N-V2 pocket router.

Domoticz home automation gateway setup diagram

System overview: GL-MT300N-V2 running autom8box firmware as Wi-Fi AP, MQTT broker, and Domoticz server.

The problem

Wi-Fi based home automation products are cheaper than Zigbee or Z-Wave, but they typically require internet connectivity. Letting cloud servers control your home devices is not ideal — internet should be optional, not mandatory.

Thanks to the open-source community (Tasmota, ESPurna, etc.) for helping jailbreak devices like Sonoff, Blitzwolf, and Teckin. But jailbreaking solves only part of the problem — you still need a home automation gateway: Wi-Fi access point + MQTT broker + automation server (Domoticz, OpenHAB, etc.).

What autom8box provides

  • Wi-Fi access point — dedicated network for your IoT devices
  • DHCP and DNS server — automatic network configuration
  • MQTT broker (Mosquitto) — message bus for IoT devices
  • Domoticz — home automation dashboard and rules engine
GL-MT300N-V2 pocket router

GL-MT300N-V2 (~$20) — compact pocket router running the autom8box firmware.

Limitations: Limited Wi-Fi range and a reduced set of Domoticz plugins due to the 16 MB flash limit. But it's a good starting point for low-budget home automation.

Flashing steps

Step 1 — Download autom8box-mt300nv2.bin.

Step 2 — Power on the GL-MT300N-V2 and wait for its SSID to appear (shown as GL-MT300N-V2-xxx).

GL-MT300N-V2 SSID visible in Wi-Fi list

OEM SSID appearing in the Wi-Fi list.

Step 3 — Connect to the SSID. When prompted for a password, enter goodlife (printed on the device's back sticker).

Wi-Fi password prompt

Enter the default Wi-Fi password.

Step 4 — Once connected, you should see the confirmation message:

Wi-Fi connected confirmation

Successfully connected to the router.

Step 5 — Open a browser and navigate to:
http://192.168.8.1/cgi-bin/luci/admin/system/flashops

LuCI login page

LuCI login — leave the password box empty and click "Login".

Step 6 — In the firmware update section, uncheck "Keep settings", choose autom8box-mt300nv2.bin, then click "Flash Image".

Firmware upload page

Firmware upload — uncheck "Keep settings" and select the autom8box binary.

File selected for flashing

File selected — ready to flash.

Step 7 — Click "Proceed" to confirm:

Flash confirmation dialog

Confirm flashing — click "Proceed".

Step 8 — Wait about 2 minutes for the flash to complete:

Flashing in progress

Firmware flashing in progress — wait for the device to reboot.

Step 9 — After reboot, a new SSID autom8box will appear. Connect with password goodlife.

autom8box SSID in Wi-Fi list

The new autom8box SSID is now visible.

Step 10 — Open http://192.168.8.1:8080 in your browser — Domoticz is ready:

Domoticz dashboard running on autom8box

Domoticz home automation dashboard — running entirely on the pocket router.

Post-setup security

SSH credentials: user root, password goodlife

Change root password:

passwd root

Change Wi-Fi password:

uci set wireless.default_radio0.key=my-new-password
uci commit wireless
wifi

Change SSID:

uci set wireless.default_radio0.ssid=my-new-ssid
uci commit wireless
wifi

Important: autom8box does not auto-save the Domoticz database. After configuring your devices, SSH in and run reboot — during reboot the database is saved from RAM to the persistent partition. A hard power cut without rebooting may lose your configuration.

SOURCE CODE

github.com/hackboxguy/lede-a5v11 — build instructions and sources

autom8box-mt300nv2.bin — pre-built firmware image