mqtt stuff
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2024-01-14 13:33:45 +01:00
parent 7fab124dd0
commit 9624d5d53d

View File

@ -2,13 +2,10 @@ package main
import ( import (
"log" "log"
"os"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
MQTT "github.com/eclipse/paho.mqtt.golang"
"github.com/google/uuid"
"net/http" "net/http"
"locsrv/database" "locsrv/database"
"locsrv/mqtt"
) )
/* /*
@ -39,19 +36,7 @@ func main() {
ch := make(chan locativeEvent) ch := make(chan locativeEvent)
dbh := database.New() dbh := database.New()
mqtt := mqtt.New()
mqttOpts := MQTT.NewClientOptions().
AddBroker(os.Getenv("MQTT_BROKER")).
SetClientID(fmt.Sprintf("locsrv-%s", uuid.New())).
SetConnectRetry(true)
mqttClient := MQTT.NewClient(mqttOpts)
if token := mqttClient.Connect(); token.Wait() && token.Error() != nil {
log.Fatalf("Unable to connect to broker, error %v", token.Error())
}
mqttTopic := os.Getenv("MQTT_TOPIC")
if mqttTopic != "" {
log.Fatalf("No topic set")
}
go func() { go func() {
for { for {
@ -63,6 +48,7 @@ func main() {
log.Printf("Person unknown: %v", err) log.Printf("Person unknown: %v", err)
} }
log.Printf("Trigger: %s, Device: %s, Location: %s, Person: %s, Latitude: %s, Longitude: %s", event.Trigger, event.Device, event.Location, event.Person, event.Latitude, event.Longitude) log.Printf("Trigger: %s, Device: %s, Location: %s, Person: %s, Latitude: %s, Longitude: %s", event.Trigger, event.Device, event.Location, event.Person, event.Latitude, event.Longitude)
mqtt.Publish("bla")
} }
} }
}() }()