-
Notifications
You must be signed in to change notification settings - Fork 1
/
printevents.go
53 lines (40 loc) · 1.36 KB
/
printevents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/crenz/locationengine"
log "github.com/Sirupsen/logrus"
"github.com/mattn/go-colorable"
)
const API_KEY = "your_api_key"
const PLACE = "your_place_uuid"
func telemetryCallback(receiver string, item[] locationengine.Item) {
log.Infof("[Telemetry] %s: %+v\n", receiver, item)
}
func eventCallback(evt locationengine.Event, receiver string, item locationengine.Item) {
log.Infof("[Event %i] %s: %+v\n", evt, receiver, item)
}
func init() {
// Set to log.DebugLevel to see each individual MQTT message received
log.SetLevel(log.InfoLevel)
log.SetOutput(colorable.NewColorableStdout())
}
func main() {
log.Infoln("Connecting to Kontakt.io broker")
l := locationengine.New()
l.RegisterEventCallback(locationengine.EvtItemAppeared, eventCallback)
l.RegisterEventCallback(locationengine.EvtItemDisappeared, eventCallback)
l.RegisterEventCallback(locationengine.EvtItemProximityChange, eventCallback)
l.RegisterEventCallback(locationengine.EvtItemRSSIChange, eventCallback)
if connected, _ := l.Connect(API_KEY); !connected {
log.Fatalln("Failed to connect!")
}
log.Infoln("Connected successfully")
if err := l.Subscribe([]string{PLACE}); err != nil {
log.Fatalln("Failed to subscribe!")
}
log.Infoln("Subscribed successfully")
defer l.Disconnect()
log.Infoln("Listening for incoming messages")
for {
l.ReceiveMessage()
}
}