-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
58 lines (45 loc) · 1.3 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
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
//Read configuration file
Config = ReadConfig()
//parse machines to []Rig struct
miningRigs := make([]Rig, 0)
for _, m := range Config.Miners {
log.Notice("minerConfig:", m)
miningRigs = append(miningRigs, Rig{m.Name, gpio.NewRelayDriver(r, m.Pin), m.IP, m.Info})
}
log.Notice("Configured rigs: ", len(miningRigs))
//Logging machines in two outputs - console & external file
if Config.Log {
go LogMachines()
}
if Config.TgBotActivate {
go TelegramBot(miningRigs)
}
//Gobot work func
work := func() {
log.Notice("HELLO! I WILL KEEP YOUR MINING RIGS ONLINE!")
//Check machines on startup without waiting the timer. Use with caution. After a power failure, RPI could be ready faster than your machines and start restarting them without need.
if Config.StartupCheck {
CheckMachines(miningRigs)
}
timer := time.Duration(Config.WaitSeconds) * time.Second
log.Notice("Starting timer: ", timer)
//Check the machines periodically
gobot.Every(timer, func() {
CheckMachines(miningRigs)
})
}
robot := gobot.NewRobot("auto-hard-reset", r, work)
for _, rig := range miningRigs {
robot.AddDevice(rig.pin)
}
robot.Start()
}