Merge pull request #175 from OktopUSP/dev

Dev
This commit is contained in:
Leandro Antônio Farias Machado 2023-12-15 09:46:56 -03:00 committed by GitHub
commit 1c79528ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 31 deletions

View File

@ -239,6 +239,10 @@ OBS: Do not use those instructions in production. To implement the project in pr
<img src="https://github.com/OktopUSP/oktopus/assets/83298718/4599d566-eada-4313-8ae1-31dae82391de"/>
<img src="https://github.com/OktopUSP/oktopus/assets/83298718/501b4ccd-6147-4957-9096-695134e34b5e"/>
</li>
<h4>Agent Simulation:</h4>
<p>
In case you want a more complete and real-world simulation of devices you might use <a href="https://github.com/OktopUSP/agent-sim">Oktopus TR-369 Agent Simulator</a>.
</p>
</ul>
--------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -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,
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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()}
/>
</Grid>
<Grid

View File

@ -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,

View File

@ -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'
});

View File

@ -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,