feat(api): device command execute (operate msg) [ close #135 ]

This commit is contained in:
leandrofars 2023-10-23 20:35:08 -03:00
parent a07082fb79
commit 2556eed53d
2 changed files with 21 additions and 1 deletions

View File

@ -57,7 +57,8 @@ func StartApi(a Api) {
iot.HandleFunc("/{sn}/set", a.deviceUpdateMsg).Methods("PUT")
iot.HandleFunc("/{sn}/parameters", a.deviceGetSupportedParametersMsg).Methods("PUT")
iot.HandleFunc("/{sn}/instances", a.deviceGetParameterInstances).Methods("PUT")
iot.HandleFunc("/{sn}/update", a.deviceFwUpdate).Methods("PUT")
iot.HandleFunc("/{sn}/operate", a.deviceOperateMsg).Methods("PUT")
iot.HandleFunc("/{sn}/fw_update", a.deviceFwUpdate).Methods("PUT")
iot.HandleFunc("/{sn}/wifi", a.deviceWifi).Methods("PUT", "GET")
// Middleware for requests which requires user to be authenticated

View File

@ -178,6 +178,25 @@ func (a *Api) deviceGetMsg(w http.ResponseWriter, r *http.Request) {
a.uspCall(msg, sn, w)
}
func (a *Api) deviceOperateMsg(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
sn := vars["sn"]
a.deviceExists(sn, w)
var receiver usp_msg.Operate
err := json.NewDecoder(r.Body).Decode(&receiver)
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
msg := utils.NewOperateMsg(receiver)
a.uspCall(msg, sn, w)
}
func (a *Api) deviceDeleteMsg(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
sn := vars["sn"]