feat(controller): site survey + multiple data model support
This commit is contained in:
parent
7461cbe121
commit
28ffde5fef
|
|
@ -76,6 +76,9 @@ func (a *Api) StartApi() {
|
|||
iot.HandleFunc("/{sn}/{mtp}/instances", a.deviceGetParameterInstances).Methods("PUT")
|
||||
iot.HandleFunc("/{sn}/{mtp}/operate", a.deviceOperateMsg).Methods("PUT")
|
||||
iot.HandleFunc("/{sn}/{mtp}/fw_update", a.deviceFwUpdate).Methods("PUT") //TODO: put it to work and generalize for usp and cwmp
|
||||
if a.enterpise {
|
||||
iot.HandleFunc("/{sn}/sitesurvey", a.deviceSiteSurvey).Methods("GET")
|
||||
}
|
||||
iot.HandleFunc("/{sn}/wifi", a.deviceWifi).Methods("PUT", "GET")
|
||||
dash := r.PathPrefix("/api/info").Subrouter()
|
||||
dash.HandleFunc("/vendors", a.vendorsInfo).Methods("GET")
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ func (a *Api) getEnterpriseResource(
|
|||
sn string,
|
||||
w http.ResponseWriter,
|
||||
body []byte,
|
||||
protocol, datamodel string,
|
||||
) error {
|
||||
model, err := cwmpGetDeviceModel(device, w)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = bridge.NatsEnterpriseInteraction("enterprise.v1.cwmp."+model+"."+sn+"."+resource+"."+action, body, w, a.nc)
|
||||
|
||||
err = bridge.NatsEnterpriseInteraction("enterprise.v1."+protocol+"."+datamodel+"."+model+"."+sn+"."+resource+"."+action, body, w, a.nc)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
36
backend/services/controller/internal/api/sitesurvey.go
Normal file
36
backend/services/controller/internal/api/sitesurvey.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/leandrofars/oktopus/internal/entity"
|
||||
"github.com/leandrofars/oktopus/internal/utils"
|
||||
)
|
||||
|
||||
func (a *Api) deviceSiteSurvey(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
sn := vars["sn"]
|
||||
|
||||
device, err := getDeviceInfo(w, sn, a.nc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == http.MethodGet {
|
||||
|
||||
if device.Cwmp == entity.Online {
|
||||
a.getEnterpriseResource("sitesurvey", "get", device, sn, w, []byte{}, "cwmp", "098")
|
||||
return
|
||||
}
|
||||
|
||||
if device.Mqtt == entity.Online || device.Stomp == entity.Online || device.Websockets == entity.Online {
|
||||
w.WriteHeader(http.StatusNotImplemented)
|
||||
w.Write(utils.Marshall("This feature is only working with CWMP devices"))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(utils.Marshall("Device is Offline"))
|
||||
}
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func (a *Api) deviceWifi(w http.ResponseWriter, r *http.Request) {
|
|||
if device.Cwmp == entity.Online {
|
||||
|
||||
if a.enterpise {
|
||||
a.getEnterpriseResource("wifi", "get", device, sn, w, []byte{})
|
||||
a.getEnterpriseResource("wifi", "get", device, sn, w, []byte{}, "cwmp", "098")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -354,7 +354,7 @@ func (a *Api) deviceWifi(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write(utils.Marshall(err.Error()))
|
||||
return
|
||||
}
|
||||
a.getEnterpriseResource("wifi", "set", device, sn, w, payload)
|
||||
a.getEnterpriseResource("wifi", "set", device, sn, w, payload, "cwmp", "098")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ func NatsEnterpriseInteraction(
|
|||
return err
|
||||
}
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write(utils.Marshall("Error to communicate with nats: " + err.Error()))
|
||||
w.Write(utils.Marshall("Error to communicate with nats:" + err.Error()))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user