Skip to main content

Module station

Module station 

Source
Expand description

The LoRa Basics Station protocol, both sides.

The packet forwarder protocol in udp is a gateway shouting datagrams at a server that may or may not be listening. Basics Station replaces it with a conversation: the gateway asks a discovery endpoint where its network server is, opens a websocket there, says what it is, and is told how to configure its radios. After that the two exchange JSON messages, each naming its kind in a msgtype field.

This module builds and reads those messages from either side, the way udp does. It opens no sockets: a station reaches its server through whatever the caller provides, and the station-client feature adds a live one.

  • Discovery and Router are the request and answer on /router-info, which hands back the websocket address to connect to, or says why it will not.
  • Message is every message the websocket carries afterwards: what the station reports about itself, the configuration it is given, the join requests and frames it heard, the downlinks it is asked to transmit and what became of them, and the clock the two keep between them.

Identifiers cross as Eui, and are written in the ID6 form the protocol prefers, which folds a run of zero groups the way an IPv6 address does.

§Examples

A station asks where its network server is, and reads the answer.

use pamoja_gateway::station::{Discovery, Router};
use pamoja_gateway::udp::Eui;

// The station names itself in the ID6 form, four groups with leading zeros dropped.
let gateway = Eui::from_hex("b827ebfffe010203").expect("sixteen hex digits");
let asking = Discovery::new(gateway);
assert_eq!(asking.to_json(), r#"{"router":"b827:ebff:fe01:203"}"#);

// The server answers with the websocket to open.
let answer = Router::from_json(
    br#"{"router":"b827:ebff:fe01:203","muxs":"::1","uri":"ws://lns.example.invalid:3001/router"}"#,
)
.expect("the answer is well formed");
assert_eq!(answer.uri.as_deref(), Some("ws://lns.example.invalid:3001/router"));
assert!(answer.error.is_none());

Structs§

Broadcast
One frame of a Message::Schedule, transmitted to a group rather than a device.
Discovery
What a station asks the discovery endpoint, naming itself.
Levels
The levels a packet was heard at, which every uplink carries.
Router
What the discovery endpoint answers: where to connect, or why not.
Xtime
A station clock value taken apart: the radio it was read on, the run of the station it belongs to, and the microseconds that run had counted.

Enums§

Message
Every message the websocket carries once the session is open.

Constants§

DISCOVERY_PATH
The path a station appends to its configured address to find its network server.
PROTOCOL_VERSION
The protocol version a station reports, which is 2 for the protocol described here.

Functions§

eui_of
Reads an identifier written in ID6, the dashed EUI form, or as a decimal number.
id6
Writes an identifier in the ID6 form the protocol prefers.