Skip to content

About

Pico-based temperature sensor network employing gossip and CRDTs

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

275 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sensor Network

KRL rulesets for a LoRaWAN sensor network on Manifold and the Pico Engine. Sensor communities and devices are Manifold picos — this repo adds sensor-specific behavior on top of Manifold's thing/community platform rather than managing its own pico hierarchy.

Supported hardware today is Dragino LoRaWAN sensors (LHT65, LSE01, LSN50, WL03A-LB, and related types). Each sensor type has a router ruleset in this repo that decodes payloads and raises sensor domain events.

Prerequisite: a bootstrapped Manifold installation (manifold-api — tag registry, owner pico, Manifold pico with io.picolabs.manifold_pico, notifications, and base io.picolabs.thing / io.picolabs.community rulesets).

Integration tests: t/README.md. Discovery annotations: docs/DISCOVERY.md.

How this repo uses Manifold

Sensor-network rulesets delegate most pico lifecycle work to Manifold and focus on sensor-specific setup and event handling.

Manifold service Used for
Community creation (manifold new_community) Creates the community child pico, installs io.picolabs.community, and establishes the Manifold↔community subscription
Thing creation (manifold create_thing) Creates bare sensor thing picos with io.picolabs.thing; community receives a community thing_created callback to finish setup
Subscriptions Community↔thing membership; thing events forwarded via community thing_event_occurred
Notifications (manifold add_notification, change_notification_setting) Threshold alerts from a community are routed to Manifold's notification platform (inbox, SMS, Prowl, etc.) instead of calling external services directly
Wrangler Child picos, channels, ruleset install requests

Events and queries for sensor bootstrap and community management go through the Manifold app channel (not the UI channel — the UI channel's event policy blocks the sensor domain).

Sensor network on Manifold: communities (e.g. Garden) and sensor things (e.g. Shed Temperature) subscribed to the Manifold pico

Solid lines are parent/child relationships; dashed lines are subscriptions. Sensor communities and things are Manifold picos — this repo adds sensor-specific rulesets on top.

Bootstrap

1. Install sensor network bootstrap on the Manifold pico

After Manifold itself is bootstrapped, install io.picolabs.sensor.network_bootstrap on the Manifold pico. This ruleset:

  • Handles sensor create_community and delegates to Manifold's generic community machinery
  • Installs io.picolabs.sensor.community on each new community child
  • Records communities in ent:sensor_communities (query via getSensorCommunities())
  • Enables notification channels for each community (default: Manifold inbox only)
  • Extends the Manifold app channel policy so sensor events and getSensorCommunities queries work on the same ECI as getThings / getCommunities (required after Manifold 1.8 app-channel narrowing)

2. Create a sensor community

Raise sensor create_community on the Manifold pico's app channel:

POST /sky/event/{manifold_app_eci}/eid/sensor/create_community
attrs: { "name": "My Sensors", "description": "..." }

Optional: "notify_channels": "Manifold,SMS,Prowl" to opt the community into additional notification channels.

What happens (three steps inside network_bootstrap):

  1. Delegate to Manifold — network_bootstrap raises manifold new_community with a correlation id (rcn) and sensor_bootstrap: true. Manifold creates the child pico, installs io.picolabs.community, and subscribes it as a Manifold community.

  2. Install sensor.community — On wrangler child_initialized for that community, network_bootstrap installs io.picolabs.sensor.community on the child and records it in ent:sensor_communities.

  3. Provision notifications — Raises manifold change_notification_setting for each requested channel so threshold alerts from this community can reach the owner.

The community pico exposes a sensor channel (for sensor initiation and related events) and a manifold_callback channel (for Manifold's thing-creation callback).

3. Add a sensor (thing)

Raise sensor initiation on the community's sensor channel:

POST /sky/event/{community_sensor_eci}/eid/sensor/initiation
attrs: { "name": "Garden LHT65", "type": "lht65" }

What happens (delegation pattern in sensor.community):

  1. Delegate to Manifold — The community sends manifold create_thing to its parent (Manifold pico) with { name, callback_eci, rcn } and stashes sensor type / ruleset list under rcn.

  2. Manifold creates the thing — Manifold creates a child pico, installs io.picolabs.thing, subscribes it, and calls back on the community's manifold_callback channel with community thing_created.

  3. Finish sensor setup — The community raises community add_thing (joins the thing to the community) and installs sensor rulesets on the thing:

    • Always: io.picolabs.sensor.thresholds, io.picolabs.iotplotter, io.picolabs.dragino
    • Per type: e.g. io.picolabs.lht65.router for type: "lht65"

Sensor readings and threshold violations flow back through the community subscription as community thing_event_occurred events, are re-raised into the sensor domain, and can trigger manifold add_notification on the Manifold pico.

Rulesets

Ruleset Installed on Purpose
io.picolabs.sensor.network_bootstrap Manifold pico Community creation orchestration, getSensorCommunities()
io.picolabs.sensor.community Community picos Sensor channel, thing delegation, readings, threshold → notifications
io.picolabs.sensor.thresholds Thing picos Threshold monitoring
io.picolabs.dragino Thing picos Shared Dragino helpers
io.picolabs.iotplotter Thing picos Plotting / visualization hooks
io.picolabs.lht65.router LHT65 things Decode LHT65 payloads
io.picolabs.lse01.router LSE01 things Decode LSE01 payloads
io.picolabs.lsn50.router LSN50 things Decode LSN50 payloads
io.picolabs.wl03a_lb.router WL03A-LB things Decode WL03A-LB payloads
io.picolabs.sensor.temperatures_view A pico created for the display XMLUI page of one community's lastTemperatures

To add a sensor type, register it in rids_to_install inside io.picolabs.sensor.community.krl and add a router ruleset to this repo.

Temperature view

Install io.picolabs.xmlui and io.picolabs.sensor.temperatures_view on a pico you create for the page. On that pico raise config new_relationship with webvh set to the community's did:webvh, then approve the invite on the community. The install creates an app channel that allows that event. Query viewUrl on that pico for the page URL. The page queries this pico; this pico calls the community's lastTemperatures.

On a mesh that requires a bearer, tag that app channel oauth-webhook, mint an access token, and paste it under Settings on the page. Settings also chooses PST, MST, CST, or EST, and a theme (Default, Dark, Green, or Gray, each in light or dark). The page keeps these in the browser tab, sends the token on the temperature query, and shows each reading time in the chosen standard-time zone. Refresh loads the latest readings without reloading the page. The page also polls every five minutes (poll_seconds). The defaults are MST and the Default theme.

The view is built from components: TemperatureSettings and TemperatureTable in this ruleset, and PicoTheme, PicoSettings, PicoThemeField, and PicoAccessTokenField from io.picolabs.xmlui. It needs pico-engine 1.9.4 or later (@component support); flush io.picolabs.xmlui on the view pico after upgrading the engine.

Dependencies

  • manifold-api — Manifold platform rulesets (manifold_pico, thing, community, notifications, bootstrap). Required at runtime; the integration test harness mounts both repos into one pico-engine container.
  • Pico Engine modules — io.picolabs.wrangler, io.picolabs.subscription (provided by the engine).

Integration tests

From the repo root:

npm install
npm test

See t/README.md for the full harness (parse gate, Docker, Manifold bootstrap, sensor scenarios, cleanup).

Home Assistant companion

This repo includes an optional Home Assistant companion integration under custom_components/pico_mesh_sensor_network/. It extends the Manifold hub integration (pico_mesh) with sensor entities for router rulesets in this repo (LHT65 today; LSE01, LSN50, etc. later).

Install

  1. Install and configure Manifold (pico_mesh) from manifold-home-assistant — OAuth, mesh connection, thing/community devices.
  2. Add Manifold Sensor Network from this repo (HACS custom repository or copy custom_components/pico_mesh_sensor_network/ into your HA config/custom_components/ directory).
  3. In HA: Settings → Devices & services → Add integration → Manifold Sensor Network — link it to your Manifold hub entry.

Sensor entities attach to existing Manifold thing devices (same device cards as SafeAndMine). Readings are polled from each thing's router ruleset (e.g. io.picolabs.lht65.router → temperature, humidity, last reading).

Layout

sensor-network/
  io.picolabs.*.krl              ← engine rulesets
  custom_components/
    pico_mesh_sensor_network/    ← HA companion (depends on pico_mesh)
  hacs.json

Third-party Manifold communities can follow the same pattern: KRL in the repo root, custom_components/pico_mesh_<name>/ beside it, "dependencies": ["pico_mesh"] in manifest.json, and a stable import surface from custom_components.pico_mesh.hub.

Docker dev stack

If you use the manifold-home-assistant Docker stack, mount this companion alongside the hub:

volumes:
  - ../manifold-home-assistant/custom_components/pico_mesh:/config/custom_components/pico_mesh:ro
  - ../sensor-network/custom_components/pico_mesh_sensor_network:/config/custom_components/pico_mesh_sensor_network:ro

Restart Home Assistant after adding the mount, then add both integrations in HA.

About

Pico-based temperature sensor network employing gossip and CRDTs

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages