dt1t and counter and refactoring using embedded interfaces
This commit is contained in:
@ -7,6 +7,7 @@ import MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||
import "github.com/google/uuid"
|
||||
import "crypto/tls"
|
||||
import "udi/config"
|
||||
import "udi/counter"
|
||||
|
||||
type Message struct {
|
||||
Topic string
|
||||
@ -26,10 +27,12 @@ func onMessageReceived(client MQTT.Client, message MQTT.Message) {
|
||||
}
|
||||
select {
|
||||
case InputChannel <- m:
|
||||
counter.S("Received")
|
||||
{}
|
||||
//log.Println("Message sent to channel")
|
||||
default:
|
||||
log.Println("Channel full, message lost")
|
||||
counter.F("Received")
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +57,7 @@ func onConnect(client MQTT.Client) {
|
||||
if token := client.Subscribe(topic, 0, onMessageReceived); token.Wait() && token.Error() != nil {
|
||||
log.Fatalf("Unable to subscribe to topic %s, error %s", topic, token.Error())
|
||||
}
|
||||
log.Printf("Successfully subscribed to topic %s", topic)
|
||||
log.Printf("Topic %s subscribed", topic)
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,19 +104,19 @@ func StartMqttClient() {
|
||||
|
||||
enableTls := config.Config.Mqtt.TlsEnable
|
||||
if enableTls == "true" {
|
||||
log.Println("Enabling TLS connection")
|
||||
//log.Println("Enabling TLS connection")
|
||||
tlsConfig := &tls.Config {
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
opts.SetTLSConfig(tlsConfig)
|
||||
}
|
||||
|
||||
log.Println("Trying to connect to broker")
|
||||
log.Println("Broker connecting")
|
||||
mqttClient = MQTT.NewClient(opts)
|
||||
if token := mqttClient.Connect(); token.Wait() && token.Error() != nil {
|
||||
log.Fatalf("Unable to connect to broker %s, error %s", broker, token.Error())
|
||||
}
|
||||
log.Printf("Successfully connected to broker %s", broker)
|
||||
//log.Printf("Successfully connected to broker %s", broker)
|
||||
|
||||
go outputDispatcher(mqttClient)
|
||||
|
||||
|
Reference in New Issue
Block a user