XBOS Docs
Search…
Temperature Sensor
Interface: i.xbos.temperature_sensor
Description: XBOS temperature sensor
PONUM: 2.1.2.0

Properties

Name
Type
Description
Units
Required
temperature
double
Current temperature reading
Fahrenheit
true
time
integer
nanoseconds since the Unix epoch
ns
false

Signals

    info:
      temperature
      time

Slots

Interfacing in Go

1
package main
2
3
import (
4
"fmt"
5
bw2 "gopkg.in/immesys/bw2bind.v5"
6
)
7
8
func main() {
9
client := bw2.ConnectOrExit("")
10
client.OverrideAutoChainTo(true)
11
client.SetEntityFromEnvironOrExit()
12
13
base_uri := "Temperature Sensor uri goes here ending in i.xbos.temperature_sensor"
14
15
// subscribe
16
type signal struct {
17
Temperature float64 `msgpack:"temperature"`
18
Time int64 `msgpack:"time"`
19
}
20
c, err := client.Subscribe(&bw2.SubscribeParams{
21
URI: base_uri + "/signal/info",
22
})
23
if err != nil {
24
panic(err)
25
}
26
27
for msg := range c {
28
var current_state signal
29
po := msg.GetOnePODF("2.1.2.0/32")
30
err := po.(bw2.MsgPackPayloadObject).ValueInto(&current_state)
31
if err != nil {
32
fmt.Println(err)
33
} else {
34
fmt.Println(current_state)
35
}
36
}
37
}
Copied!

Interfacing in Python

1
import time
2
import msgpack
3
4
from bw2python.bwtypes import PayloadObject
5
from bw2python.client import Client
6
7
bw_client = Client()
8
bw_client.setEntityFromEnviron()
9
bw_client.overrideAutoChainTo(True)
10
11
def onMessage(bw_message):
12
for po in bw_message.payload_objects:
13
if po.type_dotted == (2,1,2,0):
14
print msgpack.unpackb(po.content)
15
16
bw_client.subscribe("Temperature Sensor uri ending in i.xbos.temperature_sensor/signal/info", onMessage)
17
18
print "Subscribing. Ctrl-C to quit."
19
while True:
20
time.sleep(10000)
Copied!
Last modified 1yr ago