Slight improvements

This commit is contained in:
2024-07-23 15:37:55 +02:00
parent 17029a0a14
commit c0023195c5
3 changed files with 41 additions and 19 deletions

View File

@@ -75,11 +75,18 @@ func subscribe(client mqtt.Client, topic string, handler mqtt.MessageHandler) {
}
}
func onConnect(client mqtt.Client) {
log.Print("Subscribing to command topics")
subscribe(client, "spider/command/ping", onPing)
subscribe(client, "spider/command/set_camera_xy", onSetCameraXY)
}
func main() {
opts := mqtt.NewClientOptions()
opts.AddBroker(broker)
opts.SetClientID("spider-host-client")
opts.SetResumeSubs(true)
opts.SetOnConnectHandler(onConnect)
client := mqtt.NewClient(opts)
token := client.Connect()
@@ -88,10 +95,6 @@ func main() {
log.Fatalf("Error connecting to MQTT broker: %v\n", token.Error())
}
log.Print("Subscribing to command topics")
subscribe(client, "spider/command/ping", onPing)
subscribe(client, "spider/command/set_camera_xy", onSetCameraXY)
InitBattery()
InitServo()

View File

@@ -52,6 +52,7 @@ func InitServo() {
}
// Halt the controllers to stop any current movement
ServosOff()
log.Print("Started servos")
}
func ServosOff() {