diff --git a/backend/services/controller/internal/api/api.go b/backend/services/controller/internal/api/api.go index cae0316..fcc8d2f 100644 --- a/backend/services/controller/internal/api/api.go +++ b/backend/services/controller/internal/api/api.go @@ -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") diff --git a/backend/services/controller/internal/api/enterprise.go b/backend/services/controller/internal/api/enterprise.go index 59cfc5a..5c1abf6 100644 --- a/backend/services/controller/internal/api/enterprise.go +++ b/backend/services/controller/internal/api/enterprise.go @@ -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 } diff --git a/backend/services/controller/internal/api/sitesurvey.go b/backend/services/controller/internal/api/sitesurvey.go new file mode 100644 index 0000000..c3fe71b --- /dev/null +++ b/backend/services/controller/internal/api/sitesurvey.go @@ -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")) + } +} diff --git a/backend/services/controller/internal/api/wifi.go b/backend/services/controller/internal/api/wifi.go index f21539c..b6353f7 100644 --- a/backend/services/controller/internal/api/wifi.go +++ b/backend/services/controller/internal/api/wifi.go @@ -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 } diff --git a/backend/services/controller/internal/bridge/bridge.go b/backend/services/controller/internal/bridge/bridge.go index 0cb9537..542f8a3 100644 --- a/backend/services/controller/internal/bridge/bridge.go +++ b/backend/services/controller/internal/bridge/bridge.go @@ -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 }