-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (31 loc) · 1.11 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
package main
import (
"net/http"
utils "github.com/kasperskaarhoj/toweltornado/utils"
log "github.com/s00500/env_logger"
)
//go:generate sh injectGitVars.sh
func main() {
tt := &TowelTornado{}
frontEndPort := 8031 // Web Frontend Port
// Create frontend server:
frontendServer := &http.Server{}
wsserver := &wsServer{}
go func() {
frontendServer = wsserver.createServer(frontEndPort, tt)
if frontendServer != nil {
IP, _ := utils.FetchOutboundIP()
log.Infof("Frontend is available on http://%s:%d\n", IP, frontEndPort)
frontendServer.ListenAndServe()
}
}()
// Array of anemometers and scanning for them, adding them when found and setting up readings posted into the channel:
Anemometers := AnemometerArray{}
anemometerChannel := make(chan Anemometer, 100)
go Anemometers.Scan(anemometerChannel)
// Reading the channel:
for data := range anemometerChannel {
wsserver.BroadcastMessage(&wsToClient{DeviceNumber: data.DeviceNumber, WindSpeed: &data.WindSpeed})
//log.Printf("#%d: Wind: %.2f. Temp: %.2f. Humidity: %.2f\n", data.DeviceNumber, data.WindSpeed, data.Temperature, data.Humidity)
}
}