refact(controller): mqtt client
This commit is contained in:
parent
4a5a72c1cc
commit
fb25839045
|
|
@ -2,6 +2,13 @@ package mqtt
|
|||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/eclipse/paho.golang/autopaho"
|
||||
"github.com/eclipse/paho.golang/paho"
|
||||
"github.com/leandrofars/oktopus/internal/db"
|
||||
|
|
@ -9,12 +16,6 @@ import (
|
|||
"github.com/leandrofars/oktopus/internal/usp_record"
|
||||
"github.com/leandrofars/oktopus/internal/utils"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Mqtt struct {
|
||||
|
|
@ -59,7 +60,7 @@ func (m *Mqtt) Connect() {
|
|||
ConnectRetryDelay: 5 * time.Second,
|
||||
ConnectTimeout: 5 * time.Second,
|
||||
OnConnectionUp: func(cm *autopaho.ConnectionManager, connAck *paho.Connack) {
|
||||
log.Printf("Connected to broker--> %s:%s", m.Addr, m.Port)
|
||||
log.Printf("Connected to MQTT broker--> %s:%s", m.Addr, m.Port)
|
||||
m.Subscribe()
|
||||
},
|
||||
OnConnectError: func(err error) {
|
||||
|
|
@ -146,9 +147,9 @@ func (m *Mqtt) buildClientConfig(status, controller, apiMsg chan *paho.Publish)
|
|||
Router: singleHandler,
|
||||
OnServerDisconnect: func(d *paho.Disconnect) {
|
||||
if d.Properties != nil {
|
||||
log.Printf("Requested disconnect: %s\n", clientConfig.ClientID, d.Properties.ReasonString)
|
||||
log.Printf("Requested disconnect: %s\n , properties reason: %s\n", clientConfig.ClientID, d.Properties.ReasonString)
|
||||
} else {
|
||||
log.Printf("Requested disconnect; reason code: %d\n", clientConfig.ClientID, d.ReasonCode)
|
||||
log.Printf("Requested disconnect; %s reason code: %d\n", clientConfig.ClientID, d.ReasonCode)
|
||||
}
|
||||
},
|
||||
OnClientError: func(err error) {
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
package mqtt
|
||||
|
||||
//
|
||||
//import (
|
||||
// usp_msg "github.com/leandrofars/oktopus/internal/usp_message"
|
||||
// "github.com/leandrofars/oktopus/internal/usp_record"
|
||||
// "google.golang.org/protobuf/proto"
|
||||
// "log"
|
||||
//)
|
||||
//
|
||||
//func SendGetMsg(sn string) {
|
||||
// payload := usp_msg.Msg{
|
||||
// Header: &usp_msg.Header{
|
||||
// MsgId: "uniqueIdentifierForThismessage",
|
||||
// MsgType: usp_msg.Header_GET,
|
||||
// },
|
||||
// Body: &usp_msg.Body{
|
||||
// MsgBody: &usp_msg.Body_Request{
|
||||
// Request: &usp_msg.Request{
|
||||
// ReqType: &usp_msg.Request_Get{
|
||||
// Get: &usp_msg.Get{
|
||||
// ParamPaths: []string{
|
||||
// "Device.DeviceInfo.Manufacturer",
|
||||
// "Device.DeviceInfo.ModelName",
|
||||
// "Device.DeviceInfo.SoftwareVersion",
|
||||
// },
|
||||
// MaxDepth: 1,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// teste, _ := proto.Marshal(&payload)
|
||||
// record := usp_record.Record{
|
||||
// Version: "0.1",
|
||||
// ToId: sn,
|
||||
// FromId: "leleco",
|
||||
// PayloadSecurity: usp_record.Record_PLAINTEXT,
|
||||
// RecordType: &usp_record.Record_NoSessionContext{
|
||||
// NoSessionContext: &usp_record.NoSessionContextRecord{
|
||||
// Payload: teste,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// tr369Message, err := proto.Marshal(&record)
|
||||
// if err != nil {
|
||||
// log.Fatalln("Failed to encode address book:", err)
|
||||
// }
|
||||
// m.Publish(tr369Message, "oktopus/v1/agent/"+deviceMac, "oktopus/v1/controller/"+deviceMac)
|
||||
//}
|
||||
Loading…
Reference in New Issue
Block a user