|
@@ -1,7 +1,6 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
- "crypto/tls"
|
|
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -402,25 +401,24 @@ func (d *Device) doMQTTAccess() error {
|
|
|
|
|
|
//create a ClientOptions struct setting the broker address, clientid, turn
|
|
//create a ClientOptions struct setting the broker address, clientid, turn
|
|
//off trace output and set the default message handler
|
|
//off trace output and set the default message handler
|
|
- opts := MQTT.NewClientOptions().AddBroker("ssl://" + d.access)
|
|
|
|
|
|
+ opts := MQTT.NewClientOptions().AddBroker("tcp://" + d.access)
|
|
clientid := fmt.Sprintf("%x", d.id)
|
|
clientid := fmt.Sprintf("%x", d.id)
|
|
opts.SetClientID(clientid)
|
|
opts.SetClientID(clientid)
|
|
opts.SetUsername(clientid) // clientid as username
|
|
opts.SetUsername(clientid) // clientid as username
|
|
opts.SetPassword(hex.EncodeToString(d.token))
|
|
opts.SetPassword(hex.EncodeToString(d.token))
|
|
opts.SetKeepAlive(30 * time.Second)
|
|
opts.SetKeepAlive(30 * time.Second)
|
|
- // process key files
|
|
|
|
- cert, err := tls.LoadX509KeyPair(*confCAFile, *confKeyFile)
|
|
|
|
- if err != nil {
|
|
|
|
- panic(err)
|
|
|
|
- }
|
|
|
|
- opts.SetTLSConfig(&tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true})
|
|
|
|
|
|
+ //// process key files
|
|
|
|
+ //cert, err := tls.LoadX509KeyPair(*confCAFile, *confKeyFile)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // panic(err)
|
|
|
|
+ //}
|
|
|
|
+ //opts.SetTLSConfig(&tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true})
|
|
opts.SetDefaultPublishHandler(d.messageHandler)
|
|
opts.SetDefaultPublishHandler(d.messageHandler)
|
|
|
|
|
|
//create and start a client using the above ClientOptions
|
|
//create and start a client using the above ClientOptions
|
|
c := MQTT.NewClient(opts)
|
|
c := MQTT.NewClient(opts)
|
|
go func() {
|
|
go func() {
|
|
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
|
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
|
- fmt.Println(err.Error())
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}()
|