|
@@ -337,3 +337,29 @@ func CheckDeviceNetConfig(req *http.Request, r render.Render) {
|
|
|
Result: reply.Result,
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func CheckDeviceIsOnline(req *http.Request, r render.Render) {
|
|
|
+
|
|
|
+ identifier := req.URL.Query().Get("device_code")
|
|
|
+ device := &models.Device{}
|
|
|
+ err := server.RPCCallByName(nil, rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier", identifier, device)
|
|
|
+ if err != nil {
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ onlineargs := rpcs.ArgsGetDeviceOnlineStatus{
|
|
|
+ Id: device.DeviceIdentifier,
|
|
|
+ }
|
|
|
+ onlinereply := rpcs.ReplyGetDeviceOnlineStatus{}
|
|
|
+
|
|
|
+ err = server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetDeviceOnlineStatus", onlineargs, &onlinereply)
|
|
|
+ if err != nil || onlinereply.ClientIP == "" {
|
|
|
+ r.JSON(http.StatusOK, Common{
|
|
|
+ Result: 2,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ r.JSON(http.StatusOK, Common{
|
|
|
+ Result: 1,
|
|
|
+ })
|
|
|
+}
|