pub struct Fleet { /* private fields */ }Expand description
A real fleet a project fills and the dashboard renders. Clone to share one between the serving layer and the sampling loop.
Implementations§
Source§impl Fleet
impl Fleet
Sourcepub fn builder() -> FleetBuilder
pub fn builder() -> FleetBuilder
Sourcepub fn from_state(state: State) -> Self
pub fn from_state(state: State) -> Self
Sourcepub fn allow_sensors(&self, keys: impl IntoIterator<Item = impl Into<String>>)
pub fn allow_sensors(&self, keys: impl IntoIterator<Item = impl Into<String>>)
Restricts which sensor types a client may add, so a real device only accepts the sensors it can bind a driver to.
Without this, an AddSensor from the dashboard is always accepted (which suits the
hardware-free demo). With it, a client AddSensor whose element key is not listed is
rejected with CommandError::UnknownSensor, and the dashboard reports that the
device does not support that sensor. Discovery through add_sensor
is the device’s own and stays unrestricted. Set this after building or restoring the
fleet; the keys are the element keys a deployment supports, the same ones its
presentation declares.
§Arguments
keys- the sensor element keys a client may add, such as"soil_moisture".
Sourcepub fn report_reading(&self, group: &str, sensor: &str, reading: Reading)
pub fn report_reading(&self, group: &str, sensor: &str, reading: Reading)
Pushes a fresh reading for a sensor, appending it to the sensor’s history.
§Arguments
group- the sensor’s group id.sensor- the sensor id.reading- the new reading (the caller sets its status and band).
Sourcepub fn report_event(&self, group: &str, sensor: &str, event: EventRecord)
pub fn report_event(&self, group: &str, sensor: &str, event: EventRecord)
Records a recent event for a sensor, newest first.
§Arguments
group- the sensor’s group id.sensor- the sensor id.event- the event to record.
Sourcepub fn report_link(&self, group: &str, link: Link)
pub fn report_link(&self, group: &str, link: Link)
Updates a group’s link status (kind, signal strength, online).
§Arguments
group- the group id.link- the new link status.
Sourcepub fn report_power(
&self,
group: &str,
sensor: &str,
mode: Mode,
battery: Option<f32>,
)
pub fn report_power( &self, group: &str, sensor: &str, mode: Mode, battery: Option<f32>, )
Updates a sensor’s power mode and battery state of charge.
§Arguments
group- the sensor’s group id.sensor- the sensor id.mode- the work cadence the sensor’s node is running at.battery- the state of charge in[0.0, 1.0], orNoneif it has no battery.
Sourcepub fn take_commands(&self) -> Vec<Command>
pub fn take_commands(&self) -> Vec<Command>
Drains the control commands queued since the last call, for the project to apply to real hardware and persist, then reflect back through the report methods.
§Returns
The commands accepted since the last drain, in order.
Sourcepub fn add_group(&self, org: &str, group: Group)
pub fn add_group(&self, org: &str, group: Group)
Adds a group to an organization at runtime, so a gateway can surface a node the moment it is discovered (a LoRa join, a new mesh neighbour). A no-op if the org is unknown.
§Arguments
org- the organization id to add the group to.group- the group to add.
Sourcepub fn add_sensor(&self, group: &str, sensor: Sensor)
pub fn add_sensor(&self, group: &str, sensor: Sensor)
Adds a sensor to a group at runtime, for a newly discovered sensor. A no-op if the group is unknown.
§Arguments
group- the group id to add the sensor to.sensor- the sensor to add.
Sourcepub fn remove_group(&self, id: &str)
pub fn remove_group(&self, id: &str)
Removes a group by id at runtime, for a node that has gone away.
§Arguments
id- the group id to remove.
Sourcepub fn remove_sensor(&self, target: &str)
pub fn remove_sensor(&self, target: &str)
Removes a sensor by its "groupId/sensorId" path at runtime.
§Arguments
target- the"groupId/sensorId"path to remove.