Skip to content

Serial bus No. 3: Configure peers over Serial Bus#189

Merged
JensOgorek merged 16 commits intomainfrom
serial_bus_configure
Mar 14, 2026
Merged

Serial bus No. 3: Configure peers over Serial Bus#189
JensOgorek merged 16 commits intomainfrom
serial_bus_configure

Conversation

@JensOgorek
Copy link
Contributor

@JensOgorek JensOgorek commented Jan 28, 2026

Motivation

When configuring ESP32 nodes over the serial bus, there was no easy way to send a complete .liz script to a remote node. Additionally, if a broken script was deployed to a bus node (or a script without SerialBus configuration), the node would become unreachable and require physical USB access to fix.

Implementation

Remote configuration via serial bus (configure.py)

  • Added --serial-bus NODE_ID argument
  • Wraps each command in bus.send(NODE_ID, '...') to forward to remote node
  • Waits for reboot and verifies checksum via bus echo relay

String quoting in expression output (expression.cpp)

  • Strings containing " are now output with single quotes instead of double quotes
  • This allows commands like core.output("core.millis module1.property1") to be sent via bus.send(node, '...') without breaking the quoting

Automatic bus backup (main/utils/bus_backup.cpp)

  • When a SerialBus is created, its config (pins, baud, uart, node_id) is saved to NVS
  • On boot, if the startup script fails to create a SerialBus but backup config exists:
    • Removes all existing Serial modules
    • Creates a fresh Serial and SerialBus from the saved backup config
    • This keeps the node reachable over the bus even with a broken startup script
  • Added core.forget_serial_bus() to clear the saved config from NVS

Design Decisions

  • expression.cpp — no handling for strings with both " and ': not needed since the quoting is only used by configure.py in a controlled context.
  • serial_bus.hserial and node_id moved to public: fine since both are const, simple and safe.
  • restore_if_needed() removes all Serial modules (not just the bus one): acceptable trade-off since keeping the node reachable is the priority.

Progress

  • The implementation is complete.
  • Tested on hardware.
  • Documentation has been added.

@JensOgorek JensOgorek self-assigned this Jan 28, 2026
@JensOgorek JensOgorek added the enhancement New feature or request label Jan 28, 2026
@JensOgorek JensOgorek changed the title add bus_backup & configuration for serial_bus peers Serial bus No. 3: Configure peers over Serial Bus Jan 28, 2026
@JensOgorek JensOgorek added this to the 0.10.1 milestone Jan 28, 2026
@JensOgorek
Copy link
Contributor Author

Tested with

Working bus peer id1 script
rdyp = Output(15)
en3 = Output(12)

serial = Serial(26, 27, 115200, 1)
bus = SerialBus(serial,1)

testi = Input(32)

core.output("core.millis")
core.mute()

rdyp.on()
en3.on() 
unreachable bus peer id1 script
rdyp = Output(15)
en3 = Output(12)

testi = Input(32)

// these create serial on different pins and no bus is created.
serial_bad = Serial(25,26,115200,1) 
serial_bad2 = Serial(27,14,115200,2)

core.output("core.millis")
core.mute()

rdyp.on()
en3.on() 

After the first script was configured first, the backup was created. On the second script, lizard removed both serial modules and created a fresh serial with bus from the backup, so the esp32 on the bus was still reachable.

@JensOgorek JensOgorek marked this pull request as ready for review February 18, 2026 16:04
Copy link
Collaborator

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (manually) reviewed the PR and added some comments. Let's address them first before checking the final result one last time.

@falkoschindler
Copy link
Collaborator

Apart from improving print_to_buffer, can you look into the conflicts with main? Thanks!

@JensOgorek JensOgorek merged commit 22b089b into main Mar 14, 2026
@JensOgorek JensOgorek deleted the serial_bus_configure branch March 14, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants