-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (42 loc) · 999 Bytes
/
main.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 (
"log"
"os"
"os/signal"
"github.com/pgaxatte/go-rflink/rflink"
)
var VERSION = "0.0.1"
func main() {
log.Printf("Starting go-rflink v%s", VERSION)
// Set up channel on which to send signal notifications.
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill)
// Parse options
opts := rflink.GetOptions()
log.Printf("Options: %+v", opts)
// Setup the MQTT publisher
p, err := rflink.NewPublisher(opts)
if err != nil {
log.Fatal(err)
}
defer p.Terminate()
log.Print("MQTT publisher created")
// Setup the sensor reader
sr, err := rflink.NewSensorReader(opts)
if err != nil {
log.Fatal(err)
}
defer sr.Close()
log.Print("Sensor reader created")
// Start reading/publishing loop
p.SensorInput = sr
go p.ReadAndPublish()
// Wait for interruption
<-sigc
log.Print("Interruption signal received")
// Disconnect the Network Connection.
if err := p.Disconnect(); err != nil {
log.Fatal(err)
}
log.Print("The End.")
}