|
@@ -272,6 +272,43 @@ func SendCommandToDevice(device *models.Device, config *productconfig.ProductCon
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func SendCommandToDeviceV2(device *models.Device, config *productconfig.ProductConfig,
|
|
|
|
+ urlparams martini.Params, req *http.Request, r render.Render) {
|
|
|
|
+ timeout := req.URL.Query().Get("timeout")
|
|
|
|
+
|
|
|
|
+ server.Log.Printf("ACTION SendCommandToDevice, identifier:: %v, request: %v, timeout: %v",
|
|
|
|
+ device.DeviceIdentifier, req.Body, timeout)
|
|
|
|
+
|
|
|
|
+ var args map[string]interface{}
|
|
|
|
+ decoder := json.NewDecoder(req.Body)
|
|
|
|
+ err := decoder.Decode(&args)
|
|
|
|
+ if err != nil {
|
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrWrongRequestFormat, err))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ j := gjson.New(args)
|
|
|
|
+ cmdargs := rpcs.ArgsSendCommand{
|
|
|
|
+ DeviceId: device.DeviceIdentifier,
|
|
|
|
+ SubDevice: j.GetString("subDeviceId"),
|
|
|
|
+ WaitTime: uint32(defaultTimeOut),
|
|
|
|
+ Params: j.GetMap("data.params"),
|
|
|
|
+ Cmd: j.GetString("data.cmd"),
|
|
|
|
+ }
|
|
|
|
+ cmdreply := rpcs.ReplySendCommand{}
|
|
|
|
+
|
|
|
|
+ err = server.RPCCallByName(context.Background(), rpcs.ControllerName, "Agent.SendCommand", cmdargs, &cmdreply)
|
|
|
|
+ if err != nil {
|
|
|
|
+ server.Log.Errorf("send devie command error: %v", err)
|
|
|
|
+ r.JSON(http.StatusOK, renderError(ErrSystemFault, err))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r.JSON(http.StatusOK, Common{})
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
// AddRule 增加设备规则
|
|
// AddRule 增加设备规则
|
|
func AddRule(device *models.Device, req *http.Request, r render.Render) {
|
|
func AddRule(device *models.Device, req *http.Request, r render.Render) {
|
|
var ruleReq CreateRuleRequest
|
|
var ruleReq CreateRuleRequest
|