Skip to content

fix(edge-client): subscribe control/set topics for every PLC, not just the first - #2

Merged
ashaffah merged 1 commit into
mainfrom
fix/subscribe-every-plc
Jul 22, 2026
Merged

fix(edge-client): subscribe control/set topics for every PLC, not just the first#2
ashaffah merged 1 commit into
mainfrom
fix/subscribe-every-plc

Conversation

@ashaffah

Copy link
Copy Markdown
Owner

Problem

With two PLCs on one edge-client, only the first PLC was controllable. Commands to the second PLC were published fine but never acted on.

build_subscribe_patterns skipped every DeviceType::Master, assuming they were already covered by the machine patterns ({base}/{machine}/control/#). But those only cover the primary PLC (machine_id = first PLC). Additional PLCs' control/# and set/# topics were never subscribed, so their messages never reached the dispatcher.

Fix

Skip only the first PLC (matching primary_plc_registered in from_settings). Additional PLCs now get their own patterns, just like slaves.

  • Refactor build_subscribe_patterns to a pure fn (base, machine, mapping) so it can be unit-tested without env.
  • Add a real regression test with two PLCs asserting the second PLC is subscribed — the existing subscribe-patterns test never actually called the function, which is how this shipped.

Test

cargo build, cargo clippy --all-targets, cargo test — all clean (122 tests).

…t the first

With two PLCs on one edge-client, only the first PLC was controllable.
build_subscribe_patterns skipped every DeviceType::Master assuming they were
covered by the machine patterns, but those only cover the primary PLC
(machine_id = first PLC). Additional PLCs' control/set topics were never
subscribed, so their commands never arrived.

Skip only the first PLC (matching primary_plc_registered in from_settings);
additional PLCs now get their own patterns like slaves do. Make the function a
pure fn (base, machine, mapping) and add a real regression test — the existing
subscribe-patterns test never called the function, which is how this shipped.
Copilot AI review requested due to automatic review settings July 22, 2026 01:48
@ashaffah
ashaffah merged commit 7ba4917 into main Jul 22, 2026
2 checks passed
@ashaffah
ashaffah deleted the fix/subscribe-every-plc branch July 22, 2026 01:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes multi-PLC control by ensuring the control subscriber subscribes to control/# and set/# topics for every PLC (not just the primary/first one), preventing commands for additional PLCs from being dropped before dispatch.

Changes:

  • Refactored build_subscribe_patterns to a pure function taking (base, machine, mapping) instead of &Settings.
  • Updated subscription pattern generation to skip only the primary PLC (first DeviceType::Master) and include additional PLCs.
  • Added a regression unit test covering the “second PLC not subscribed” scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/control_subscriber.rs
Comment on lines +184 to +188
for device in &mapping.devices {
use crate::shared::DeviceType;
if device.device_type == DeviceType::Master {
continue; // PLC already covered by machine patterns above
if device.device_type == DeviceType::Master && !primary_plc_skipped {
primary_plc_skipped = true;
continue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants