From bdc8ddb5881e0ec351130338c2498389a8b499f5 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Sat, 2 Dec 2023 10:35:26 -0300 Subject: [PATCH 1/8] chore(devops): update compose go and nodejs version --- devops/docker-compose.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 342e2fd1bc3cbd65097928c5f0496c1c58cd6dbb Mon Sep 17 00:00:00 2001 From: leandrofars Date: Sat, 2 Dec 2023 11:16:19 -0300 Subject: [PATCH 2/8] docs(readme): mention agent simulator --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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. +

-------------------------------------------------------------------------------------------------------------------------------------------------------- From f26369c2365fa6cfa24dd7526fa6af89a7de5ac5 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Sat, 2 Dec 2023 11:24:16 -0300 Subject: [PATCH 3/8] chore: remove trash log --- .../services/controller/internal/db/info.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 } From 8a0fe71470fd7b469d7459ac655b954329467587 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Sat, 2 Dec 2023 11:37:38 -0300 Subject: [PATCH 4/8] chore: remove github workflows folder --- .github/workflows/github-actions-ec2.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .github/workflows/github-actions-ec2.yml diff --git a/.github/workflows/github-actions-ec2.yml b/.github/workflows/github-actions-ec2.yml deleted file mode 100644 index e69de29..0000000 From f96ff1d0755a13a58a1464ebb3244a95a3fc6bb6 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 13 Dec 2023 09:03:12 -0300 Subject: [PATCH 5/8] fix: info api dynamic broker connection --- backend/services/controller/internal/api/api.go | 7 +++++-- .../services/controller/internal/api/info.go | 17 +++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) 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 } From 0e0803438330c7bc5ee8c852d15fa1cebef6bfb8 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 13 Dec 2023 09:06:03 -0300 Subject: [PATCH 6/8] fix(frontend): console errors --- frontend/src/pages/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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()} /> Date: Wed, 13 Dec 2023 09:42:38 -0300 Subject: [PATCH 7/8] feat(frontend): new color palette for graphics --- frontend/src/sections/overview/overview-traffic.js | 11 ++++++++++- frontend/src/theme/colors.js | 10 +++++++++- frontend/src/theme/create-palette.js | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frontend/src/sections/overview/overview-traffic.js b/frontend/src/sections/overview/overview-traffic.js index 7e03824..7a98f13 100644 --- a/frontend/src/sections/overview/overview-traffic.js +++ b/frontend/src/sections/overview/overview-traffic.js @@ -59,7 +59,16 @@ const useChartOptions = (labels,title) => { 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..4aecba2 100644 --- a/frontend/src/theme/colors.js +++ b/frontend/src/theme/colors.js @@ -64,7 +64,15 @@ export const error = withAlphas({ lightest: '#FEF3F2', light: '#FEE4E2', main: '#F04438', - dark: '#B42318', + dark: '#29ADB2', 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, From 74734e846f3241a3024dbe817226c8571bd9e335 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Wed, 13 Dec 2023 16:32:08 -0300 Subject: [PATCH 8/8] fix(frontend): color palette --- frontend/src/theme/colors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/theme/colors.js b/frontend/src/theme/colors.js index 4aecba2..74ef40e 100644 --- a/frontend/src/theme/colors.js +++ b/frontend/src/theme/colors.js @@ -64,7 +64,7 @@ export const error = withAlphas({ lightest: '#FEF3F2', light: '#FEE4E2', main: '#F04438', - dark: '#29ADB2', + dark: '#B42318', darkest: '#7A271A', contrastText: '#FFFFFF' });