40 lines
701 B
Go
40 lines
701 B
Go
package main
|
|
|
|
import (
|
|
"git.hpds.cc/pavement/hpds_node"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
sf := hpds_node.NewStreamFunction(
|
|
"hpds-ap",
|
|
hpds_node.WithMqAddr("localhost:27188"),
|
|
hpds_node.WithObserveDataTags(0x33),
|
|
hpds_node.WithCredential("token:z2"),
|
|
)
|
|
defer func(sf hpds_node.StreamFunction) {
|
|
_ = sf.Close()
|
|
}(sf)
|
|
|
|
// set handler
|
|
err := sf.SetHandler(handler)
|
|
if err != nil {
|
|
log.Fatalf("[sf] handler err=%v", err)
|
|
}
|
|
// start
|
|
err = sf.Connect()
|
|
if err != nil {
|
|
log.Fatalf("[sf] connect err=%v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
select {}
|
|
}
|
|
|
|
func handler(data []byte) (byte, []byte) {
|
|
val := string(data)
|
|
log.Printf(">> [streamFunction] got tag=0x33, data=%s", val)
|
|
return 0x0, nil
|
|
}
|