lijian 1 سال پیش
والد
کامیت
5c48dc5975
3فایلهای تغییر یافته به همراه8 افزوده شده و 7 حذف شده
  1. 3 3
      pkg/mqtt/connection.go
  2. 2 1
      services/mqttaccess/access.go
  3. 3 3
      services/mqttaccess/mqtt_provider.go

+ 3 - 3
pkg/mqtt/connection.go

@@ -117,7 +117,7 @@ func (c *Connection) ValidateToken(token []byte) error {
 	return nil
 }
 
-// Close close
+// Close connection
 func (c *Connection) Close() {
 	c.mLock.Lock()
 	defer c.mLock.Unlock()
@@ -125,9 +125,9 @@ func (c *Connection) Close() {
 	c.MessageID = 0
 	server.Log.Infof("closing connection of device %v", DeviceID)
 	if c.Conn != nil {
-		c.Conn.Close()
+		_ = c.Conn.Close()
 		c.Conn = nil
-		c.Mgr.Provider.OnDeviceOffline(c.DeviceCode, c.VendorId)
+		_ = c.Mgr.Provider.OnDeviceOffline(c.DeviceCode, c.VendorId)
 	}
 	if c.SendChan != nil {
 		close(c.SendChan)

+ 2 - 1
services/mqttaccess/access.go

@@ -57,7 +57,6 @@ func (a *Access) GetStatus(args rpcs.ArgsGetStatus, reply *rpcs.ReplyGetStatus)
 }
 
 func (a *Access) SendCommand(args rpcs.ArgsSendCommand, reply *rpcs.ReplySendCommand) error {
-	server.Log.Infof("Access Send Command: %v, %v", args.DeviceId, args.Cmd)
 	cmd := &klink.CloudSend{
 		Action:      "cloudSend",
 		MsgId:       0,
@@ -73,6 +72,8 @@ func (a *Access) SendCommand(args rpcs.ArgsSendCommand, reply *rpcs.ReplySendCom
 	if err != nil {
 		return err
 	}
+	print("Access Send Command: %v, %v,%s\r\n", args.DeviceId, args.Cmd, string(msg))
+
 	return a.MqttBroker.SendMessageToDevice(args.DeviceId, "c", msg, time.Duration(args.WaitTime)*time.Second)
 }
 

+ 3 - 3
services/mqttaccess/mqtt_provider.go

@@ -57,9 +57,9 @@ func (mp *MQTTProvider) OnDeviceOnline(args rpcs.ArgsGetOnline, VendorId string)
 	return err
 }
 func (mp *MQTTProvider) OnDeviceOffline(deviceid string, vendorId string) error {
-	//if deviceid != "" {
-	//	deviceOnlineCount.Dec()
-	//}
+	if deviceid != "" {
+		deviceOnlineCount.Dec()
+	}
 	args := rpcs.ArgsGetOffline{
 		Id:       deviceid,
 		VendorId: vendorId,