Fix in error handling MQTT
This commit is contained in:
parent
b4432f3ac3
commit
3faba543bf
1 changed files with 6 additions and 6 deletions
|
@ -24,7 +24,7 @@ const (
|
||||||
clientID = "rfmGate"
|
clientID = "rfmGate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var f = func(client *MQTT.Client, msg MQTT.Message) {
|
var defautlPubHandler = func(client *MQTT.Client, msg MQTT.Message) {
|
||||||
fmt.Printf("TOPIC: %s\n", msg.Topic())
|
fmt.Printf("TOPIC: %s\n", msg.Topic())
|
||||||
fmt.Printf("MSG: %s\n", msg.Payload())
|
fmt.Printf("MSG: %s\n", msg.Payload())
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,11 @@ func actorHandler(tx chan *rfm69.Data) func(client *MQTT.Client, msg MQTT.Messag
|
||||||
func main() {
|
func main() {
|
||||||
log.Print("Start")
|
log.Print("Start")
|
||||||
opts := MQTT.NewClientOptions().AddBroker(mqttBroker).SetClientID(clientID)
|
opts := MQTT.NewClientOptions().AddBroker(mqttBroker).SetClientID(clientID)
|
||||||
opts.SetDefaultPublishHandler(f)
|
opts.SetDefaultPublishHandler(defautlPubHandler)
|
||||||
opts.SetCleanSession(true)
|
opts.SetCleanSession(true)
|
||||||
c := MQTT.NewClient(opts)
|
c := MQTT.NewClient(opts)
|
||||||
token := c.Connect()
|
token := c.Connect()
|
||||||
if !token.Wait() {
|
if token.Wait() && token.Error() != nil {
|
||||||
log.Fatal(token.Error())
|
log.Fatal(token.Error())
|
||||||
}
|
}
|
||||||
rfm, err := rfm69.NewDevice(nodeID, networkID, isRfm69Hw)
|
rfm, err := rfm69.NewDevice(nodeID, networkID, isRfm69Hw)
|
||||||
|
@ -83,9 +83,9 @@ func main() {
|
||||||
sigint := make(chan os.Signal, 1)
|
sigint := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigint, os.Interrupt, os.Kill)
|
signal.Notify(sigint, os.Interrupt, os.Kill)
|
||||||
|
|
||||||
subToken := c.Subscribe("/actor/#", 0, actorHandler(tx))
|
token = c.Subscribe("/actor/#", 0, actorHandler(tx))
|
||||||
if !subToken.Wait() {
|
if token.Wait() && token.Error() != nil {
|
||||||
log.Fatal(subToken.Error())
|
log.Fatal(token.Error())
|
||||||
}
|
}
|
||||||
defer c.Unsubscribe("/actor/#")
|
defer c.Unsubscribe("/actor/#")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue