Skip to content

Add LoRa gateway example for a Shelly with no network - #236

Merged
orlin369 merged 2 commits into
ALLTERCO:mainfrom
drHouse-gif:feature/lora-gateway
Nov 11, 2026
Merged

orlin369 merged 2 commits into
ALLTERCO:mainfrom
drHouse-gif:feature/lora-gateway

Conversation

@drHouse-gif

Copy link
Copy Markdown
Contributor

Adds lora/lora-gateway/ - one script with two roles, for a pair of devices
where only one of them is on the network.

What it does

The node role runs on a device with its WiFi station switched off, so LoRa is
its only link. It reports switch:0 and its metering, and executes commands
coming back.

The gateway role runs on a device that keeps its network. It creates ten
virtual components and keeps them in step with the node, and turns an outside
write to the output component into a LoRa command. Since they are ordinary
virtual components, anything that already reads the gateway sees the remote
device through them with no extra work.

Why another LoRa example

The existing examples in lora/ are one-way and fire-and-forget: send a
command, or send one value. lnm/switch-state-follower.shelly.js does follow a
remote device's state, but over IP - which is exactly the transport a
network-less device does not have.

This one keeps a whole device mirrored and, more importantly, does not drop a
command silently. A SheLr frame carries no acknowledgement and the radio is
half duplex, so a command sent while the node happens to be transmitting is
lost. The node's own state report is treated as the acknowledgement: an
unconfirmed command is resent up to three times, and if it never lands the
node's real state is written back rather than leaving a value on display that
never happened. While a command is in flight, incoming reports are deliberately
not mirrored onto the output component - they still carry the old value and
would bounce the switch back.

Two firmware details worth having written down

Values go to the components through Virtual.getHandle(key).setValue(value),
not Shelly.call. A script may only have five Shelly.call requests in flight
at once; the sixth throws Too many calls in progress, and an uncaught error
stops the script. An earlier version issued eight Number.Set calls per report,
died half way through, and left the last three components frozen with nothing
reported anywhere. The ten Virtual.Add calls that create the components are
chained one per callback for the same reason.

A handle write comes back stamped delta.source sys, while a write from
outside arrives as rpc. That is how the gateway tells its own mirror updates
apart from a real command, without a suppression flag or the race that comes
with one.

Getting the node back

C|w| re-enables the node's WiFi station over LoRa and reboots it - a partial
Wifi.SetConfig merges, so the stored SSID and password survive. Measured at
about 9 seconds from command to back on the network. The device's own access
point is the manual fallback; Gen4 firmware will not enable an AP without a
password, which the README covers.

Air time

A report frame is about 317 ms at SF9, and 868.1 MHz sits in an EU868 1% duty
cycle sub-band - 36 s of transmission per hour. The default 120 s heartbeat
spends about 9.5 s of that, 0.26%. A 60 s heartbeat would spend 19 s, over half
the budget, leaving little for commands and retries, so the README says to lower
the spreading factor if you want a faster heartbeat.

Testing

On two Shelly 1 PM Gen4 (S4SW-001P16EU), device firmware 2.0.0, add-on
firmware 2.0.1, add-on hardware 1.4.0/2520, at RSSI -25 dBm / SNR 11:

  • all ten virtual components created from nothing on first start; a restart
    binds to the existing ones and does not duplicate them
  • 12 of 12 commands confirmed with the node off the network - median 2.5 s,
    worst 6.4 s after one retry
  • frame loss on an idle link 0 in 20; with both ends talking, the occasional
    command does need the retry, which is what the retry loop is for
  • C|w| recovered the node from having no network at all

Notes

  • No manifest or changelog entry in this PR, per the note in AGENTS.md that
    sync-manifest-md.py synchronises the manifest after merge. Happy to add
    both if you would rather have them in here.
  • lora/README.md lists the subfolders but is already missing
    lora-wired-dw-state/, so I left it alone rather than half-fix it here.

- One script, two roles: a gateway that keeps its network and a node
  whose WiFi station is switched off, so LoRa is its only link
- Gateway mirrors the node's switch and metering into ten virtual
  components it creates itself, and turns an outside write to the output
  component into a LoRa command
- Commands are confirmed against the node's own report and resent up to
  three times, since a SheLr frame has no acknowledgement and the radio
  is half duplex; if a command never lands the node's real state is
  written back instead of leaving a stale value on display
- Values are written through Virtual.getHandle().setValue(), not
  Shelly.call, which caps at five requests in flight
- C|w| brings the node's WiFi back over LoRa, with the device's own
  access point as the manual fallback
- Default 120 s heartbeat keeps the link at 0.26% of the EU868 1% duty
  cycle; README carries the air time numbers
- Tested on two Shelly 1 PM Gen4, firmware 2.0.0, add-on firmware 2.0.1
The integrity check in CI requires every @status production file to have
a manifest entry. Written by hand rather than with sync-manifest-md.py:
its extractor matches @description with a pattern that stops at the first
newline, so a wrapped description comes out truncated, and running it
also reflows the tags arrays of all 246 existing entries.
@orlin369
orlin369 merged commit 49d86cf into ALLTERCO:main Nov 11, 2026
2 checks passed
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