Skip to content

Commit

Permalink
functions for readings and battery health
Browse files Browse the repository at this point in the history
  • Loading branch information
b1conrad committed Jul 10, 2017
1 parent 5822fb6 commit fba30ae
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion krl/wovyn_router.krl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ruleset wovyn_router {
meta {
shares __testing, lastHeartbeat, lastHumidity, lastTemperature, lastPressure
shares __testing, lastHeartbeat, lastHumidity, lastTemperature, lastPressure, reading, battery
}
global {
__testing = { "queries": [ { "name": "__testing" } ],
Expand Down Expand Up @@ -35,6 +35,21 @@ ruleset wovyn_router {
ent:lastPressure
}

reading = function(path) {
steps = path.split(re#/#);
mments = ent:lastHeartbeat.genericThing.data{steps[0]};
mment = mments.filter(function(v){v.name == steps[1]})[0];
ans = steps[1] + ": " + mment{steps[2]} + " " + mment.units;
device = ent:lastHeartbeat.property.name;
{"text":ans,"username":device}
}

battery = function() {
pct = ent:lastHeartbeat.genericThing.healthPercent;
vlt = ent:lastHeartbeat.specificThing.battery.currentVoltage;
device = ent:lastHeartbeat.property.name;
{"text":"battery: " + pct + "% " + vlt + "v","username":device}
}
}

// mostly for debugging; see all data from last heartbeat
Expand Down

1 comment on commit fba30ae

@b1conrad
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new function reading requires an argument named path which is three slash-separated values:

  1. the key within heartbeat genericThing.data
  2. the value of name for the object selected
  3. the key within the named object of the measurement desired

possible values of the path argument for our Wovyn devices;

  • gas/co2/concentration
  • humidity/ambient humidity/humidity
  • pressure/ambient pressure/pressure
  • temperature/ambient temperature/temperatureF (or ...C)
  • temperature/probe temperature/temperatureF (or ...C)

Please sign in to comment.