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 +

Agent Simulation:

+

+ 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()} /> { theme.palette.success.main, theme.palette.error.main, ] - }else{ + }else if(title === "Vendors"){ + options.colors = [ + theme.palette.graphics.dark, + theme.palette.graphics.darkest, + theme.palette.graphics.light, + theme.palette.graphics.main, + theme.palette.graphics.lightest, + ] + } + else{ options.colors = [ theme.palette.primary.main, theme.palette.info.main, diff --git a/frontend/src/theme/colors.js b/frontend/src/theme/colors.js index e3b59fa..74ef40e 100644 --- a/frontend/src/theme/colors.js +++ b/frontend/src/theme/colors.js @@ -68,3 +68,11 @@ export const error = withAlphas({ darkest: '#7A271A', contrastText: '#FFFFFF' }); + +export const graphics = withAlphas({ + lightest: '#9EC8B9', + light: '#706233', + main: '#1B4242', + dark: '#FFC5C5', + darkest: '#7071E8' +}); \ No newline at end of file diff --git a/frontend/src/theme/create-palette.js b/frontend/src/theme/create-palette.js index b7c74d7..43e67f4 100644 --- a/frontend/src/theme/create-palette.js +++ b/frontend/src/theme/create-palette.js @@ -1,6 +1,6 @@ import { common } from '@mui/material/colors'; import { alpha } from '@mui/material/styles'; -import { error, indigo, info, neutral, success, warning } from './colors'; +import { error, indigo, info, neutral, success, warning, graphics } from './colors'; export function createPalette() { return { @@ -18,6 +18,7 @@ export function createPalette() { }, divider: '#F2F4F7', error, + graphics, info, mode: 'light', neutral,