Skip to content

Commit

Permalink
webapp: add Modbus
Browse files Browse the repository at this point in the history
Add Modbus configuration and info views.

Signed-off-by: Bobby Noelte <[email protected]>
  • Loading branch information
b0661 committed Apr 8, 2024
1 parent c9f1e36 commit 8043faa
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 2 deletions.
8 changes: 7 additions & 1 deletion webapp/src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li>
<router-link @click="onClick" class="dropdown-item" to="/settings/ntp">{{ $t('menu.NTPSettings') }}</router-link>
</li>
<li>
<router-link @click="onClick" class="dropdown-item" to="/settings/modbus">{{ $t('menu.ModbusSettings') }}</router-link>
</li>
<li>
<router-link @click="onClick" class="dropdown-item" to="/settings/mqtt">{{ $t('menu.MQTTSettings') }}</router-link>
</li>
Expand Down Expand Up @@ -79,6 +82,9 @@
<li>
<router-link @click="onClick" class="dropdown-item" to="/info/ntp">{{ $t('menu.NTP') }}</router-link>
</li>
<li>
<router-link @click="onClick" class="dropdown-item" to="/info/modbus">{{ $t('menu.Modbus') }}</router-link>
</li>
<li>
<router-link @click="onClick" class="dropdown-item" to="/info/mqtt">{{ $t('menu.MQTT') }}</router-link>
</li>
Expand Down Expand Up @@ -184,4 +190,4 @@ export default defineComponent({
}
},
});
</script>
</script>
19 changes: 19 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Settings": "Einstellungen",
"NetworkSettings": "Netzwerk",
"NTPSettings": "NTP",
"ModbusSettings": "Modbus",
"MQTTSettings": "MQTT",
"InverterSettings": "Wechselrichter",
"SecuritySettings": "Sicherheit",
Expand All @@ -16,6 +17,7 @@
"System": "System",
"Network": "Netzwerk",
"NTP": "NTP",
"Modbus": "Modbus",
"MQTT": "MQTT",
"Console": "Konsole",
"About": "Über",
Expand Down Expand Up @@ -284,6 +286,18 @@
"Day": "Tag",
"Night": "Nacht"
},
"modbusinfo": {
"ModbusInformation": "Modbus-Informationen",
"ConfigurationSummary": "@:mqttinfo.ConfigurationSummary",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"IDDTUPro": "ID für DTUPro Datensatz",
"IDTotal": "ID für OpenDTU Zusammenfassung aller angemeldeter Inverter (SunSpec)"
},
"mqttinfo": {
"MqttInformation": "MQTT-Informationen",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -427,6 +441,11 @@
"EnableMdns": "mDNS aktivieren",
"MdnsSettings": "mDNS-Einstellungen"
},
"modbusadmin": {
"ModbusSettings": "Modbus-Einstellungen",
"ModbusConfiguration": "Modbus-Konfiguration",
"EnableModbus": "Modbus aktivieren"
},
"mqttadmin": {
"MqttSettings": "MQTT-Einstellungen",
"MqttConfiguration": "MQTT-Konfiguration",
Expand Down
19 changes: 19 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Settings": "Settings",
"NetworkSettings": "Network Settings",
"NTPSettings": "NTP Settings",
"ModbusSettings": "Modbus Settings",
"MQTTSettings": "MQTT Settings",
"InverterSettings": "Inverter Settings",
"SecuritySettings": "Security Settings",
Expand All @@ -16,6 +17,7 @@
"System": "System",
"Network": "Network",
"NTP": "NTP",
"Modbus": "Modbus",
"MQTT": "MQTT",
"Console": "Console",
"About": "About",
Expand Down Expand Up @@ -284,6 +286,18 @@
"Day": "Day",
"Night": "Night"
},
"modbusinfo": {
"ModbusInformation": "Modbus Information",
"ConfigurationSummary": "@:mqttinfo.ConfigurationSummary",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"IDDTUPro": "ID for DTUPro dataset",
"IDTotal": "ID for OpenDTU aggregation of all registered inverters (SunSpec)"
},
"mqttinfo": {
"MqttInformation": "MQTT Information",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -427,6 +441,11 @@
"EnableMdns": "Enable mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Modbus Settings",
"ModbusConfiguration": "Modbus Configuration",
"EnableModbus": "Enable Modbus"
},
"mqttadmin": {
"MqttSettings": "MQTT Settings",
"MqttConfiguration": "MQTT Configuration",
Expand Down
19 changes: 19 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Settings": "Paramètres",
"NetworkSettings": "Réseau",
"NTPSettings": "Heure locale",
"ModbusSettings": "Modbus",
"MQTTSettings": "MQTT",
"InverterSettings": "Onduleurs",
"SecuritySettings": "Sécurité",
Expand All @@ -16,6 +17,7 @@
"System": "Système",
"Network": "Réseau",
"NTP": "NTP",
"Modbus": "Modbus",
"MQTT": "MQTT",
"Console": "Console",
"About": "A propos",
Expand Down Expand Up @@ -284,6 +286,18 @@
"Day": "Jour",
"Night": "Nuit"
},
"modbusinfo": {
"ModbusInformation": "Modbus Information",
"ConfigurationSummary": "@:mqttinfo.ConfigurationSummary",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"IDDTUPro": "ID pour l'ensemble de données DTUPro",
"IDTotal": "ID pour l'agrégation OpenDTU de tous les onduleurs enregistrés (SunSpec)"
},
"mqttinfo": {
"MqttInformation": "MQTT Information",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -427,6 +441,11 @@
"EnableMdns": "Activer mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Paramètres Modbus",
"ModbusConfiguration": "Configuration du système Modbus",
"EnableModbus": "Activer le Modbus"
},
"mqttadmin": {
"MqttSettings": "Paramètres MQTT",
"MqttConfiguration": "Configuration du système MQTT",
Expand Down
14 changes: 13 additions & 1 deletion webapp/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import HomeView from '@/views/HomeView.vue';
import InverterAdminView from '@/views/InverterAdminView.vue';
import LoginView from '@/views/LoginView.vue';
import MaintenanceRebootView from '@/views/MaintenanceRebootView.vue';
import ModbusAdminView from '@/views/ModbusAdminView.vue';
import ModbusInfoView from '@/views/ModbusInfoView.vue';
import MqttAdminView from '@/views/MqttAdminView.vue';
import MqttInfoView from '@/views/MqttInfoView.vue';
import NetworkAdminView from '@/views/NetworkAdminView.vue';
Expand Down Expand Up @@ -52,6 +54,11 @@ const router = createRouter({
name: 'NTP',
component: NtpInfoView
},
{
path: '/info/modbus',
name: 'Modbus',
component: ModbusInfoView
},
{
path: '/info/mqtt',
name: 'MqTT',
Expand All @@ -72,6 +79,11 @@ const router = createRouter({
name: 'NTP Settings',
component: NtpAdminView
},
{
path: '/settings/modbus',
name: 'Modbus Settings',
component: ModbusAdminView
},
{
path: '/settings/mqtt',
name: 'MqTT Settings',
Expand Down Expand Up @@ -115,4 +127,4 @@ const router = createRouter({
]
});

export default router;
export default router;
3 changes: 3 additions & 0 deletions webapp/src/types/ModbusConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ModbusConfig {
modbus_enabled: boolean;
}
8 changes: 8 additions & 0 deletions webapp/src/types/ModbusStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface ModbusStatus {
modbus_enabled: boolean;
modbus_hostname: string;
modbus_port: number;
modbus_ip: string;
modbus_id_dtupro: number;
modbus_id_total: number;
}
87 changes: 87 additions & 0 deletions webapp/src/views/ModbusAdminView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<template>
<BasePage :title="$t('modbusadmin.ModbusSettings')" :isLoading="dataLoading">
<BootstrapAlert v-model="showAlert" dismissible :variant="alertType">
{{ alertMessage }}
</BootstrapAlert>

<form @submit="saveModbusConfig">
<CardElement :text="$t('modbusadmin.ModbusConfiguration')" textVariant="text-bg-primary">
<InputElement :label="$t('modbusadmin.EnableModbus')"
v-model="modbusConfigList.modbus_enabled"
type="checkbox" wide/>

</CardElement>

<FormFooter @reload="getModbusConfig"/>
</form>
</BasePage>
</template>

<script lang="ts">
import BasePage from '@/components/BasePage.vue';
import BootstrapAlert from "@/components/BootstrapAlert.vue";
import CardElement from '@/components/CardElement.vue';
import FormFooter from '@/components/FormFooter.vue';
import InputElement from '@/components/InputElement.vue';
import type { ModbusConfig } from "@/types/ModbusConfig";
import { authHeader, handleResponse } from '@/utils/authentication';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
BasePage,
BootstrapAlert,
CardElement,
FormFooter,
InputElement,
},
data() {
return {
dataLoading: true,
modbusConfigList: {} as ModbusConfig,
alertMessage: "",
alertType: "info",
showAlert: false,
qosTypeList: [
{ key: 0, value: 'QOS0' },
{ key: 1, value: 'QOS1' },
{ key: 2, value: 'QOS2' },
],
};
},
created() {
this.getModbusConfig();
},
methods: {
getModbusConfig() {
this.dataLoading = true;
fetch("/api/modbus/config", { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter, this.$router))
.then((data) => {
this.modbusConfigList = data;
this.dataLoading = false;
});
},
saveModbusConfig(e: Event) {
e.preventDefault();
const formData = new FormData();
formData.append("data", JSON.stringify(this.modbusConfigList));
fetch("/api/modbus/config", {
method: "POST",
headers: authHeader(),
body: formData,
})
.then((response) => handleResponse(response, this.$emitter, this.$router))
.then(
(response) => {
this.alertMessage = this.$t('apiresponse.' + response.code, response.param);
this.alertType = response.type;
this.showAlert = true;
}
);
},
},
});
</script>
76 changes: 76 additions & 0 deletions webapp/src/views/ModbusInfoView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template>
<BasePage :title="$t('modbusinfo.ModbusInformation')" :isLoading="dataLoading" :show-reload="true" @reload="getModbusInfo">
<CardElement :text="$t('modbusinfo.ConfigurationSummary')" textVariant="text-bg-primary">
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tbody>
<tr>
<th>{{ $t('modbusinfo.Status') }}</th>
<td>
<StatusBadge :status="modbusDataList.modbus_enabled" true_text="modbusinfo.Enabled" false_text="modbusinfo.Disabled" />
</td>
</tr>
<tr>
<th>{{ $t('modbusinfo.Server') }}</th>
<td>{{ modbusDataList.modbus_hostname }}</td>
</tr>
<tr>
<th>{{ $t('modbusinfo.IpAddress') }}</th>
<td>{{ modbusDataList.modbus_ip }}</td>
</tr>
<tr>
<th>{{ $t('modbusinfo.Port') }}</th>
<td>{{ modbusDataList.modbus_port }}</td>
</tr>
<tr>
<th>{{ $t('modbusinfo.IDDTUPro') }}</th>
<td>{{ modbusDataList.modbus_id_dtupro }}</td>
</tr>
<tr>
<th>{{ $t('modbusinfo.IDTotal') }}</th>
<td>{{ modbusDataList.modbus_id_total }}</td>
</tr>
</tbody>
</table>
</div>
</CardElement>

</BasePage>
</template>

<script lang="ts">
import BasePage from '@/components/BasePage.vue';
import CardElement from '@/components/CardElement.vue';
import StatusBadge from '@/components/StatusBadge.vue';
import type { ModbusStatus } from '@/types/ModbusStatus';
import { authHeader, handleResponse } from '@/utils/authentication';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
BasePage,
CardElement,
StatusBadge
},
data() {
return {
dataLoading: true,
modbusDataList: {} as ModbusStatus,
};
},
created() {
this.getModbusInfo();
},
methods: {
getModbusInfo() {
this.dataLoading = true;
fetch("/api/modbus/status", { headers: authHeader() })
.then((response) => handleResponse(response, this.$emitter, this.$router))
.then((data) => {
this.modbusDataList = data;
this.dataLoading = false;
});
},
},
});
</script>

0 comments on commit 8043faa

Please sign in to comment.