Check this out... ESP-NOW (communication protocol)

Careful Dave - that rabbit burrow is getting pretty deep !!

Craig

Just been informed the PiHut now has stock of these devices for £4.80 inc VAT + delivery.

ESP-NOW Node Setup and System Status update

I currently have six ESP-NOW nodes (using ESP32-C3-Super-Mini with IPEX socket for an external antenna) in operation: four Sensor nodes, one Relay node, and a Base station.

My latest dashboard is built around an Agent-to-Agent (A2A) concept, which made it straightforward to duplicate sections of the flow as I added each new node.

Yesterday afternoon, I took voltage readings for each node — measuring Vin (approximately 5V) and Vreg (targeting 3.3V). From there, I moved on to calibrating the scaling factors for both values across all nodes from my office setup.

This wasn’t entirely new ground. I carried out a similar exercise previously when Paul @zenofmud and I were working with our Single Sensor Nodes (SSN) over a shared MQTT broker on my Oracle VM. At that time, we effectively had a three-way setup: Paul in Boston, my son-in-law’s growing frame in his garden (managed by my grandson), and my own nodes here.

On a technical note, the system is proving to be very robust. I’ve tested nodes across various locations — house, garage, garden, and greenhouse — powering them via a power bank and confirming reliable communication. This includes both the relay and base stations. As expected, this reliability comes from using the Wi-Fi 2.4GHz link layer directly, rather than establishing full Wi-Fi network connections.

The only real downside has been the time investment — I’d estimate this has taken around a month of focused effort to reach this stage.



The PCB's layout would accommodate either an ESP32-C3-S-M or ESP32-S2-Mini.



Here's part of my testbench I use to 'exercise' and 'adjust' the settings of the nodes...

Well, all I can say after seeing the work that has gone in, the detail and care over calibration. Why the Sticky Tape Label?? I feel quality could be greatly improved here!!:rofl: :rofl: :joy:

Some technical points...

  • I used Micro-Python for all the coding

  • I ended-up using the ESP32-C3-Super-Mini with an IPEX socket for an ext antenna
    The one I use is by DIY-Malls and has the coupling capacitor fitted for an ext antenna

  • I wrote code to handle 'chunking' of the msg.payload in the UpLink
    Note: There is a 250-byte limit on the size of the payload without 'chunking'

  • On the ESP32-C3-S-M tx_power needs to be lowered to 15 (due to power regulation)
    e.g. wlan.config(tx_power=15) [Actually set via my config.json file]

EDIT: Due to time and cost constraints, I used handwritten sticky labels to identify each node.

See, more relevant detail. When is the Label Printer arriving, or will you make your own Label Printer?:squinting_face_with_tongue:

David, you are a real hero! Amazing all the pretty designs you have presented to us!! My own creations normally look like a bird's nest

Remote Downlink Management – Working Implementation

I can report that I’ve successfully implemented two new commands to remotely manage downlinks in my network.

:wrench: New Commands

  • SET-DOWNLINK
    • Inserts a new downlink if the node_id does not already exist
    • Overwrites the existing entry if it does exist
  • DEL-DOWNLINK
    • Deletes a downlink if it exists
    • Silently ignores the request if it does not

:test_tube: Test Scenario

To properly validate this, I started from scratch with a new node:

  • Fresh ESP32-C3 Super Mini (DIY-Malls, with IPEX)
  • Flashed with MicroPython
  • Installed a Sensor Station build (NOW-01-S)
  • Updated node_idNOW-02-S in config.json
  • Powered up and verified connection to the NOW network

In Node-RED, I could immediately see NOW-02-S reporting every 60 seconds — expected behaviour, as the Sensor Station already had the Relay Station MAC address configured.


:rocket: Dynamic Network Update

Here’s where it gets interesting:

  1. Base Station update
  • Added NOW-02-S
  • Defined routing via the Relay Station downlink
  1. Relay Station update
  • Added NOW-02-S
  • Provided its actual MAC address
  1. After each change, issued a SAVE-CONFIG command
    → Persisted live downlinks back to config.json

:white_check_mark: Result

Apart from a couple of minor scripting errors (quickly fixed), everything worked as intended.

This proves that:

  • Downlinks can be updated remotely
  • Nodes can be added or removed dynamically
  • Changes can be persisted reliably

:package: Example Commands

SET-DOWNLINK

msg.payload = {
  "src_id": "node-red",
  "dst_id": dst_id,
  "dir":    "down",
  "cmd":    "SET-DOWNLINK",
  "downlink": {
    "node_id": "NOW-02-S",
    "mac":     "90:70:69:C1:E9:14",
    "role":    "SENSOR"
  }
}

DEL-DOWNLINK

msg.payload = {
  "src_id": "node-red",
  "dst_id": dst_id,
  "dir": "down",
  "cmd": "DEL-DOWNLINK",
  "downlink": {
    "node_id": "NOW-08-S"
  }
}

When I get some spare time I suppose I'll have to gather together all my pieces of paper and create some proper documentation so other people could try out this project (ha, ha).

OMG - I've just asked ChatGPT to describe what it thinks of my efforts...

I’d describe your ESP-NOW setup as a remotely managed, multi-hop mesh-style network with central orchestration—but with a few nuances that make it more interesting than a typical “mesh” label suggests.


:brain: High-level description

Your network is essentially a:

Hierarchical ESP-NOW network with dynamic routing and remote configuration control via Node-RED


:magnifying_glass_tilted_left: What makes it distinctive

1. Not a pure mesh (and that’s a good thing)
Traditional mesh networks (like Zigbee) rely on distributed routing decisions.
Your system is different:

  • The Base Station acts as a central controller
  • Routing is explicitly defined via downlinks
  • Nodes don’t “discover” routes — they’re told what to do

:backhand_index_pointing_right: This makes it more deterministic and easier to debug.


2. Multi-hop capability via relay nodes

  • Sensor nodes don’t need direct access to the Base Station
  • Traffic can be routed via Relay Stations
  • You’ve effectively created ESP-NOW multi-hop, which isn’t native

:backhand_index_pointing_right: That’s a big step beyond typical ESP-NOW use.


3. Software-defined network topology

This is where your system really stands out:

  • Downlinks can be:
    • Added (SET-DOWNLINK)
    • Removed (DEL-DOWNLINK)
    • Persisted (SAVE-CONFIG)
  • All done remotely, without reflashing devices

:backhand_index_pointing_right: You’ve built a control plane on top of ESP-NOW.


4. Central orchestration via Node-RED

Using Node-RED as the control interface means:

  • You have a visual network controller
  • You can automate provisioning, updates, and monitoring
  • Messages act like network management commands

:backhand_index_pointing_right: This is very similar in concept to SDN (Software-Defined Networking).

Was AI consulted for this project?

I've written quite a few Python scripts in the past for sensor nodes that @zenofmud and myself had created prior to the advent of AI, so I took a lot of that material and adapted it. One area where I did use AI was getting the WiFi connection sequence sorted out for the Base Station. This station has to make a Wifi connection to the link-layer as well joining one of my AP points on my home WiFi network. I used AI to resolve the sequencing issue as I was banging 'head-against-brick-wall'. I found that unless you specify exactly what you are doing and the conditions under which you are doing it - the AI will give a different answer (doesn't necessarily remember the stage you were at). This is a bit frustrating as you get led up the wrong path and waste time.

I'm asking out of curiosity, I also had my own LoRa project with Attiny1614. I said, I'm going to try how ESP32 saves data relative to Attiny's EEPROM... That's how it started, and ended with +2000 lines of code :joy:
I was quite surprised how it all works. What are some good AIs for coding in your experience?

I use Micro-Python for the scripts inside my ESP32-C3 and S2 devices and found Claude is brilliant for Python. Next point of call is ChatGPT. Only issue is I run out of usage with Claude quickly - suppose I should stump-up some cash and get a subscription.

The ESP32-S2-Mini and C3-Super-Mini have 4MB of flash and 2MB of PSRAM as well as EEPROM.

I've been looking into bolting an 512Mb serial EEPROM like the 24LC512 onto my ESP32s. It has an I2C interface so should be dead easy to store my ESP-NOW config files in there.

Claude is ok, I also use Gemini in parallel, mostly for verification and analysis.
Try Z.ai, it's wicked "thinking" for coding, while Gemini handles logic in Node-RED (functions) extremely well.

I’ve had a very frustrating morning with MicroPython…

Last week I received a batch of PCBs for my ESP-NOW network. These boards are designed to interface with my infrared detectors and dummy cameras. I quickly adapted one of my existing ESP-NOW scripts to support the IR side, and added a small feature to send an IR_TEST message to a node so I could simulate an intruder trigger.

The hardware side behaved nicely too — the board includes a 3V3→12V buck-boost converter, and I added a simple voltage divider into an ADC channel so I can monitor the supply voltage remotely.

Got everything working… yippee! :grinning_face_with_smiling_eyes:

Feeling confident, I updated main.py so the script would auto-run on power-up.

That worked as well… double yippee! :grinning_face_with_smiling_eyes:

Then reality kicked in…

I realised I’d forgotten to include a way to adjust the ADC scaling factor dynamically.

No problem, I thought — I’ll just stop the script and tweak it.

Except… I couldn’t stop it. At all.

I tried everything I could think of — no way to halt or interrupt the running script. And of course, I hadn’t taken a backup because I’d only made “a small change”.

At that point I was stuck. The only option left was to reflash a fresh ESP32-S2-Mini and try to reconstruct all the little improvements I’d made.

Lesson learned the hard way.

Second time around, once I got things working again, I immediately backed everything up.

Here’s a photo of the new board:

Seems you got 'edgy' with the PSU PCB. Does save some space on the PCB, as long as it fits in the box!

I changed the orientation of the pins on the SMPS on Sunday - it now fits flat to the board.

I suppose overall the volume will be less for the box...