diff --git a/.github/workflows/github-actions-ec2.yml b/.github/workflows/github-actions-ec2.yml
deleted file mode 100644
index e69de29..0000000
diff --git a/README.md b/README.md
index 11855d5..b6a87d4 100644
--- a/README.md
+++ b/README.md
@@ -239,6 +239,10 @@ OBS: Do not use those instructions in production. To implement the project in pr
+
+ In case you want a more complete and real-world simulation of devices you might use Oktopus TR-369 Agent Simulator. +
-------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/backend/services/controller/internal/api/api.go b/backend/services/controller/internal/api/api.go index 4a247ca..d893654 100644 --- a/backend/services/controller/internal/api/api.go +++ b/backend/services/controller/internal/api/api.go @@ -11,6 +11,7 @@ import ( "github.com/leandrofars/oktopus/internal/api/cors" "github.com/leandrofars/oktopus/internal/api/middleware" "github.com/leandrofars/oktopus/internal/db" + "github.com/leandrofars/oktopus/internal/mqtt" "github.com/leandrofars/oktopus/internal/mtp" usp_msg "github.com/leandrofars/oktopus/internal/usp_message" "github.com/leandrofars/oktopus/internal/utils" @@ -23,6 +24,7 @@ type Api struct { Broker mtp.Broker MsgQueue map[string](chan usp_msg.Msg) QMutex *sync.Mutex + Mqtt mqtt.Mqtt } const REQUEST_TIMEOUT = time.Second * 30 @@ -32,13 +34,14 @@ const ( AdminUser ) -func NewApi(port string, db db.Database, b mtp.Broker, msgQueue map[string](chan usp_msg.Msg), m *sync.Mutex) Api { +func NewApi(port string, db db.Database, mqtt *mqtt.Mqtt, msgQueue map[string](chan usp_msg.Msg), m *sync.Mutex) Api { return Api{ Port: port, Db: db, - Broker: b, + Broker: mqtt, MsgQueue: msgQueue, QMutex: m, + Mqtt: *mqtt, } } diff --git a/backend/services/controller/internal/api/info.go b/backend/services/controller/internal/api/info.go index 2a3d3c8..44d8e72 100644 --- a/backend/services/controller/internal/api/info.go +++ b/backend/services/controller/internal/api/info.go @@ -60,24 +60,21 @@ func (a *Api) generalInfo(w http.ResponseWriter, r *http.Request) { result.VendorsCount = vendorcount result.ProductClassCount = productclasscount - /* ------------ TODO: [mqtt rtt] create common function for this ------------ */ - //TODO: address with value from env or something like that - conn, err := net.Dial("tcp", "127.0.0.1:1883") + conn, err := net.Dial("tcp", a.Mqtt.Addr+":"+a.Mqtt.Port) if err != nil { - json.NewEncoder(w).Encode("Error to connect to broker") w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode("Error to connect to broker: " + err.Error()) return } defer conn.Close() info, err := tcpInfo(conn.(*net.TCPConn)) if err != nil { - json.NewEncoder(w).Encode("Error to get TCP socket info") w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode("Error to get TCP socket info") return } rtt := time.Duration(info.Rtt) * time.Microsecond - /* -------------------------------------------------------------------------- */ result.MqttRtt = rtt / 1000 @@ -85,8 +82,6 @@ func (a *Api) generalInfo(w http.ResponseWriter, r *http.Request) { if err != nil { log.Println(err) } - - return } func (a *Api) vendorsInfo(w http.ResponseWriter, r *http.Request) { @@ -100,8 +95,6 @@ func (a *Api) vendorsInfo(w http.ResponseWriter, r *http.Request) { if err != nil { log.Println(err) } - - return } func (a *Api) productClassInfo(w http.ResponseWriter, r *http.Request) { @@ -115,8 +108,6 @@ func (a *Api) productClassInfo(w http.ResponseWriter, r *http.Request) { if err != nil { log.Println(err) } - - return } func (a *Api) statusInfo(w http.ResponseWriter, r *http.Request) { @@ -141,6 +132,4 @@ func (a *Api) statusInfo(w http.ResponseWriter, r *http.Request) { if err != nil { log.Println(err) } - - return } diff --git a/backend/services/controller/internal/db/info.go b/backend/services/controller/internal/db/info.go index 0ddb91f..a72e150 100644 --- a/backend/services/controller/internal/db/info.go +++ b/backend/services/controller/internal/db/info.go @@ -40,9 +40,9 @@ func (d *Database) RetrieveVendorsInfo() ([]VendorsCount, error) { log.Println(err) return nil, err } - for _, result := range results { - log.Println(result) - } + // for _, result := range results { + // log.Println(result) + // } return results, nil } @@ -65,9 +65,9 @@ func (d *Database) RetrieveStatusInfo() ([]StatusCount, error) { log.Println(err) return nil, err } - for _, result := range results { - log.Println(result) - } + // for _, result := range results { + // log.Println(result) + // } return results, nil } @@ -90,8 +90,8 @@ func (d *Database) RetrieveProductsClassInfo() ([]ProductClassCount, error) { log.Println(err) return nil, err } - for _, result := range results { - log.Println(result) - } + // for _, result := range results { + // log.Println(result) + // } return results, nil } diff --git a/devops/docker-compose.yaml b/devops/docker-compose.yaml index 2c86a00..473ac4b 100644 --- a/devops/docker-compose.yaml +++ b/devops/docker-compose.yaml @@ -1,7 +1,7 @@ services: oktopustr369: - image: 'golang:1.18' + image: 'golang:1.21.4' container_name: oktopustr369 tty: true stdin_open: true @@ -32,7 +32,7 @@ services: ipv4_address: 172.16.235.3 mochi: - image: 'golang:1.18' + image: 'golang:1.21.4' container_name: mochi tty: true stdin_open: true @@ -48,7 +48,7 @@ services: ipv4_address: 172.16.235.4 socketio: - image: 'node:14.20' + image: 'node:16.20.2' container_name: socketio tty: true stdin_open: true diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index a9fcc1c..b98018e 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -41,6 +41,10 @@ const Page = () => { let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/info/general`, requestOptions)) if (result.status === 401){ router.push("/auth/login") + }else if (result.status != 200){ + console.log("Status:", result.status) + let content = await result.json() + console.log("Message:", content) }else{ let content = await result.json() console.log("general info result:", content) @@ -154,7 +158,7 @@ const Page = () => { //difference={16} positive={false} sx={{ height: '100%' }} - value={devicesCount} + value={devicesCount.toString()} />