|
@@ -93,11 +93,8 @@ func GetDeviceInfoByIdentifier(urlparams martini.Params, r render.Render) {
|
|
|
identifier := urlparams["identifier"]
|
|
|
server.Log.Printf("ACTION GetDeviceInfoByIdentifier, identifier:: %v", identifier)
|
|
|
device := &models.Device{}
|
|
|
- span, ctx := opentracing.StartSpanFromContext(context.Background(), "GetDeviceInfoByIdentifier")
|
|
|
- defer span.Finish()
|
|
|
- ext.SpanKindRPCClient.Set(span)
|
|
|
- span.SetTag("identifier", identifier)
|
|
|
- err := server.RPCCallByName(ctx, rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier", identifier, device)
|
|
|
+
|
|
|
+ err := server.RPCCallByName(context.Background(), rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier", identifier, device)
|
|
|
if err != nil {
|
|
|
r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
|
|
|
return
|
|
@@ -149,6 +146,32 @@ func GetDeviceLatestStatus() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// DeviceUpgrade 设备OTA升级
|
|
|
+func DeviceUpgrade(device *models.Device, urlparams martini.Params, req *http.Request, r render.Render) {
|
|
|
+ var param DeviceUpgradeReq
|
|
|
+ decoder := json.NewDecoder(req.Body)
|
|
|
+ err := decoder.Decode(¶m)
|
|
|
+ if err != nil {
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrWrongRequestFormat, err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var args rpcs.ArgsDeviceUpgrade
|
|
|
+ args.DeviceId = param.DeviceId
|
|
|
+ args.SudDeviceId = param.SubDeviceId
|
|
|
+ args.Url = param.Url
|
|
|
+ args.Md5 = param.MD5
|
|
|
+ args.Version = param.Version
|
|
|
+ var reply rpcs.ReplyEmptyResult
|
|
|
+ err = server.RPCCallByName(context.Background(), rpcs.MQTTAccessName, "Access.SetStatus", args, &reply)
|
|
|
+ if err != nil {
|
|
|
+ server.Log.Errorf("设备OTA升级失败:", err)
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ r.JSON(http.StatusOK, Common{})
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// SetDeviceStatus set device status
|
|
|
func SetDeviceStatus(device *models.Device, config *productconfig.ProductConfig,
|
|
|
urlparams martini.Params, req *http.Request, r render.Render) {
|