pub struct Wiring {
pub site: String,
pub profile: String,
pub sensor: SensorWiring,
pub output: Option<OutputWiring>,
pub link: LinkWiring,
pub battery: Option<BatteryWiring>,
}Expand description
One site’s wiring: the part, the output, the link, and the battery a profile runs with.
{
"$schema": "https://pamoja.molex.cloud/schema/wiring-1.json",
"site": "coop-2",
"profile": "brooder-heater.json",
"sensor": { "part": "bme280", "bus": "/dev/i2c-1", "address": "0x76" },
"output": { "gpio": "/dev/gpiochip0", "line": 17, "active_low": true },
"link": { "mqtt": "192.168.1.10" }
}Like a profile it is refused, with the field it was probably meant to be, when it holds a field its format does not have.
Fields§
§site: StringThe site’s name, which the node’s logs and its MQTT client id carry.
profile: StringThe profile to run, as a path relative to the wiring file.
sensor: SensorWiringThe part that takes the readings.
output: Option<OutputWiring>The output the profile drives, if it drives one.
link: LinkWiringThe link the readings are published over.
battery: Option<BatteryWiring>The battery the node runs from, if it runs from one.
Implementations§
Source§impl Wiring
impl Wiring
Sourcepub const SCHEMA: &'static str = "https://pamoja.molex.cloud/schema/wiring-1.json"
pub const SCHEMA: &'static str = "https://pamoja.molex.cloud/schema/wiring-1.json"
The address of the published JSON Schema for the wiring file format this build writes.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Checks the wiring for what a runner could not open.
§Returns
Nothing when every part of the wiring can be opened.
§Errors
Returns Error::Codec naming the first problem: an
empty site or profile path; an I2C part with no bus, a DS18B20 with no serial, a
replay with no readings, an address past 0x7f or on a part that answers at only one,
or a calibration that is not a finite number; a GPIO output with no chip; an MQTT link
with no host, port 0, or a password without a username; or a battery on a part that
is not a power monitor, or whose full voltage is not above its empty one.
Sourcepub fn fits(&self, profile: &Profile) -> Result<Plan>
pub fn fits(&self, profile: &Profile) -> Result<Plan>
Checks that this wiring can run a profile, and says how its reading is taken.
§Arguments
profile- the profile to run.
§Returns
The plan for the reading: the part’s quantity and how it reaches the profile’s unit.
§Errors
Returns Error::Codec when the profile does not say
what it reads, the part does not measure it, the part’s unit does not convert to the
profile’s, the profile’s control kind is one only a program of its own can decide,
a profile that switches an output has none wired, or one that switches nothing has
one wired that would never move.
§Examples
use pamoja_profile::wiring::Wiring;
use pamoja_profile::Profile;
let wiring = Wiring::from_json(r#"{
"site": "coop-2",
"profile": "brooder-heater.json",
"sensor": { "part": "bme280", "bus": "/dev/i2c-1" },
"output": { "gpio": "/dev/gpiochip0", "line": 17, "active_low": true },
"link": { "mqtt": "192.168.1.10" }
}"#)?;
let fridge = Profile::vaccine_fridge_monitor();
let plan = wiring.fits(&fridge)?;
assert_eq!((plan.quantity.as_str(), plan.from.as_str()), ("temperature", "celsius"));
// A soil probe's profile cannot run on a thermometer.
let refused = wiring.fits(&Profile::irrigation_node()).unwrap_err().to_string();
assert!(refused.contains("a bme280 measures temperature, relative_humidity, or pressure"));Source§impl Wiring
impl Wiring
Sourcepub fn from_json(text: &str) -> Result<Self>
pub fn from_json(text: &str) -> Result<Self>
Loads a wiring file.
§Arguments
text- the file’s contents.
§Returns
The wiring.
§Errors
Returns Error::Codec if the text is not a wiring file,
is written in a format this build does not read, carries a field the format does not
have, with the one it was probably meant to be, or describes wiring
check refuses.