Repository navigation
Add LoRa gateway example for a Shelly with no network - #236
Merged
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
lora/lora-gateway/- one script with two roles, for a pair of deviceswhere only one of them is on the network.
What it does
The
noderole runs on a device with its WiFi station switched off, so LoRa isits only link. It reports
switch:0and its metering, and executes commandscoming back.
The
gatewayrole runs on a device that keeps its network. It creates tenvirtual 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 acommand, or send one value.
lnm/switch-state-follower.shelly.jsdoes follow aremote 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 fiveShelly.callrequests in flightat once; the sixth throws
Too many calls in progress, and an uncaught errorstops the script. An earlier version issued eight
Number.Setcalls per report,died half way through, and left the last three components frozen with nothing
reported anywhere. The ten
Virtual.Addcalls that create the components arechained one per callback for the same reason.
A handle write comes back stamped
delta.sourcesys, while a write fromoutside arrives as
rpc. That is how the gateway tells its own mirror updatesapart 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 partialWifi.SetConfigmerges, so the stored SSID and password survive. Measured atabout 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-onfirmware 2.0.1, add-on hardware 1.4.0/2520, at RSSI -25 dBm / SNR 11:
binds to the existing ones and does not duplicate them
worst 6.4 s after one retry
command does need the retry, which is what the retry loop is for
C|w|recovered the node from having no network at allNotes
sync-manifest-md.pysynchronises the manifest after merge. Happy to addboth if you would rather have them in here.
lora/README.mdlists the subfolders but is already missinglora-wired-dw-state/, so I left it alone rather than half-fix it here.