ソースを参照

修复在线状态 #5

lijian 2 年 前
コミット
1ed5dc8ae0

+ 1 - 1
services/apiprovider/actions.go

@@ -130,7 +130,7 @@ func GetDeviceCurrentStatus(device *models.Device, config *productconfig.Product
 
 	err := server.RPCCallByName(ctx, rpcs.ControllerName, "Controller.GetStatus", statusargs, &statusreply)
 	if err != nil {
-		server.Log.Errorf("get devie status error: %v", err)
+		server.Log.Errorf("get device status error: %v", err)
 		r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
 		return
 	}

+ 2 - 2
services/apiprovider/middleware.go

@@ -102,9 +102,9 @@ func CheckDeviceOnline(context martini.Context, params martini.Params, req *http
 	}
 	onlinereply := rpcs.ReplyGetDeviceOnlineStatus{}
 	err = server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetDeviceOnlineStatus", onlineargs, &onlinereply)
-	if err != nil {
+	if err != nil || onlinereply.ClientIP == "" {
 		server.Log.Errorf("get device online status error: %v", err)
-		r.JSON(http.StatusOK, renderError(ErrDeviceNotOnline, errors.New("get device online status error "+err.Error())))
+		r.JSON(http.StatusOK, renderError(ErrDeviceNotOnline, errors.New("设备不在线")))
 		return
 	}
 

+ 0 - 17
services/mqttaccess/access.go

@@ -53,23 +53,6 @@ func (a *Access) GetStatus(args rpcs.ArgsGetStatus, reply *rpcs.ReplyGetStatus)
 		Cmd:      "report",
 	}
 	cmdReply := rpcs.ReplySendCommand{}
-	//// then wait for status report
-	//StatusChan[args.Id] = make(chan *protocol.Data)
-	//after := time.After(defaultTimeoutSecond * time.Second)
-	//server.Log.Debug("now waiting 5 seconds for status report...")
-	//select {
-	//case <-after:
-	//	// timeout
-	//	close(StatusChan[args.Id])
-	//	delete(StatusChan, args.Id)
-	//	return errors.New("get status timeout.")
-	//case data := <-StatusChan[args.Id]:
-	//	// go it
-	//	close(StatusChan[args.Id])
-	//	delete(StatusChan, args.Id)
-	//	reply.Status = data.SubData
-	//	return nil
-	//}
 	return a.SendCommand(cmdArgs, &cmdReply)
 }