2022-10-12 11:55:36 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.hpds.cc/pavement/hpds_node"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
sf := hpds_node.NewStreamFunction(
|
2023-03-24 08:49:01 +08:00
|
|
|
"hpds-ap",
|
|
|
|
hpds_node.WithMqAddr("localhost:27188"),
|
2022-10-12 11:55:36 +08:00
|
|
|
hpds_node.WithObserveDataTags(0x33),
|
|
|
|
hpds_node.WithCredential("token:z2"),
|
|
|
|
)
|
2023-03-24 08:49:01 +08:00
|
|
|
defer func(sf hpds_node.StreamFunction) {
|
|
|
|
_ = sf.Close()
|
|
|
|
}(sf)
|
2022-10-12 11:55:36 +08:00
|
|
|
|
|
|
|
// set handler
|
2023-03-24 08:49:01 +08:00
|
|
|
err := sf.SetHandler(handler)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("[sf] handler err=%v", err)
|
|
|
|
}
|
2022-10-12 11:55:36 +08:00
|
|
|
// start
|
2023-03-24 08:49:01 +08:00
|
|
|
err = sf.Connect()
|
2022-10-12 11:55:36 +08:00
|
|
|
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
|
|
|
|
}
|