-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (59 loc) · 1.63 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"log"
"runtime"
"time"
"github.com/alexhowarth/go-ferment-monitor/consumer"
"github.com/alexhowarth/go-ferment-monitor/models"
"github.com/alexhowarth/go-ferment-monitor/producer"
"github.com/alexhowarth/go-ferment-monitor/server"
"github.com/alexhowarth/go-tilt"
)
func main() {
models.Init()
p := producer.NewPublisher()
// use channels to restart? reconfigure etc?
mqttModel := &models.MQTTModel{}
conf, err := mqttModel.GetMQTTConfig()
if err != nil {
log.Printf("Error loading config - Please configure by going to http://localhost:5000: %+v", err)
}
log.Printf("Config: %+v", conf)
if conf.Enabled {
if c, ok := consumer.ConsumerTypesMap["mqtt"]; ok {
log.Printf("Adding consumer: MQTT\n")
c.Configure(conf)
p.AddConsumer(c)
}
}
p.StartConsumers()
tiltChan := make(chan tilt.Tilt)
tiltConf := tilt.Config{Channel: tiltChan}
go func() {
tiltModel := &models.TiltModel{}
for {
select {
case t := <-tiltChan:
log.Printf("Producing to tiltChan %v", t)
p.Channel <- consumer.Message{Tilt: t}
conf := models.TiltConf{Colour: t.Colour()}
tiltModel.CreateTilt(conf) // this needs to be first or create so that we can pass name and og to p.Channel <- above
case <-time.After(time.Millisecond):
}
}
}()
t := tiltConf.NewScanner()
scan := 120 * time.Second
sleep := 120 * time.Second
// TODO maybe we just populate a 'found' table here
go func() {
for {
log.Printf("Goroutines: %v", runtime.NumGoroutine())
log.Printf("Scanning for %v", scan)
t.Scan(scan)
log.Printf("Sleeping for %v", sleep)
time.Sleep(sleep)
}
}()
server.Init()
}