-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
67 lines (52 loc) · 1.24 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
package main
import (
"time"
"tinygo.org/x/drivers/lora"
"tinygo.org/x/drivers/lora/lorawan"
"tinygo.org/x/drivers/lora/lorawan/region"
)
func main() {
time.Sleep(5 * time.Second)
println("*** TinyGlobo 1 starting... ***")
// setup LoRa radio
var err error
radio, err = setupLora()
if err != nil {
failMessage(err)
}
// Connect LoRaWAN to use the LoRa Radio device.
lorawan.UseRadio(radio)
// use EU868 DR2 spreading factor for high-altitude
settings := region.EU868()
settings.UplinkChannel().SpreadingFactor = lora.SpreadingFactor10
lorawan.UseRegionSettings(settings)
// Try to connect to the LoRaWAN network
if err := lorawanJoin(); err != nil {
failMessage(err)
}
go startGPS()
startBattery()
startSensors()
for {
println("Sleeping for", uplinkDelaySeconds, "seconds")
time.Sleep(time.Second * uplinkDelaySeconds)
readBattery()
readSensors()
payload, err := createPayload()
if err != nil {
println("Payload error:", err)
continue
}
if err := lorawan.SendUplink(payload, session); err != nil {
println("Uplink error:", err)
continue
}
println("Uplink complete, msglen=", len(payload))
}
}
func failMessage(err error) {
for {
println("FATAL:", err)
time.Sleep(time.Second)
}
}