tls still not working

This commit is contained in:
2023-11-25 16:18:22 +01:00
parent b0faf7378c
commit c0939d7b28

10
main.go
View File

@ -8,6 +8,7 @@ import "strings"
// import "time"
import MQTT "github.com/eclipse/paho.mqtt.golang"
import "github.com/google/uuid"
import "crypto/tls"
type Message struct {
@ -93,6 +94,15 @@ func startMqttClient() MQTT.Client {
opts.SetPassword(password)
}
enableTls := os.Getenv("MQTT_ENABLE_TLS")
if enableTls == "true" {
log.Println("Enableing TLS connection")
tlsConfig := &tls.Config {
InsecureSkipVerify: true,
}
opts.SetTLSConfig(tlsConfig)
}
log.Println("Trying to connect to broker")
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {