Skip to content

Commit 11ea36b

Browse files
committed
webapp: add Modbus TCP
Add Modbus TCP configuration and info views. Signed-off-by: Bobby Noelte <[email protected]>
1 parent c517f7b commit 11ea36b

File tree

9 files changed

+262
-2
lines changed

9 files changed

+262
-2
lines changed

webapp/src/components/NavBar.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<li>
3434
<router-link @click="onClick" class="dropdown-item" to="/settings/ntp">{{ $t('menu.NTPSettings') }}</router-link>
3535
</li>
36+
<li>
37+
<router-link @click="onClick" class="dropdown-item" to="/settings/modbus">{{ $t('menu.ModbusSettings') }}</router-link>
38+
</li>
3639
<li>
3740
<router-link @click="onClick" class="dropdown-item" to="/settings/mqtt">{{ $t('menu.MQTTSettings') }}</router-link>
3841
</li>
@@ -79,6 +82,9 @@
7982
<li>
8083
<router-link @click="onClick" class="dropdown-item" to="/info/ntp">{{ $t('menu.NTP') }}</router-link>
8184
</li>
85+
<li>
86+
<router-link @click="onClick" class="dropdown-item" to="/info/modbus">{{ $t('menu.Modbus') }}</router-link>
87+
</li>
8288
<li>
8389
<router-link @click="onClick" class="dropdown-item" to="/info/mqtt">{{ $t('menu.MQTT') }}</router-link>
8490
</li>
@@ -184,4 +190,4 @@ export default defineComponent({
184190
}
185191
},
186192
});
187-
</script>
193+
</script>

webapp/src/locales/de.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"Settings": "Einstellungen",
55
"NetworkSettings": "Netzwerk",
66
"NTPSettings": "NTP",
7+
"ModbusSettings": "Modbus",
78
"MQTTSettings": "MQTT",
89
"InverterSettings": "Wechselrichter",
910
"SecuritySettings": "Sicherheit",
@@ -16,6 +17,7 @@
1617
"System": "System",
1718
"Network": "Netzwerk",
1819
"NTP": "NTP",
20+
"Modbus": "Modbus",
1921
"MQTT": "MQTT",
2022
"Console": "Konsole",
2123
"About": "Über",
@@ -284,6 +286,19 @@
284286
"Day": "Tag",
285287
"Night": "Nacht"
286288
},
289+
"modbusinfo": {
290+
"ModbusInformation": "Modbus-Informationen",
291+
"TCPSummary": "Konfigurationszusammenfassung Modbus TCP",
292+
"ServerSummary": "Informationen zu den Modbus Servern",
293+
"Status": "@:mqttinfo.Status",
294+
"Enabled": "@:mqttinfo.Enabled",
295+
"Disabled": "@:mqttinfo.Disabled",
296+
"Server": "@:mqttinfo.Server",
297+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
298+
"Port": "@:mqttinfo.Port",
299+
"IDDTUPro": "ID für DTUPro Datensatz",
300+
"IDTotal": "ID für OpenDTU Zusammenfassung aller angemeldeter Inverter (SunSpec)"
301+
},
287302
"mqttinfo": {
288303
"MqttInformation": "MQTT-Informationen",
289304
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -427,6 +442,11 @@
427442
"EnableMdns": "mDNS aktivieren",
428443
"MdnsSettings": "mDNS-Einstellungen"
429444
},
445+
"modbusadmin": {
446+
"ModbusSettings": "Modbus-Einstellungen",
447+
"ModbusConfiguration": "Modbus-Konfiguration",
448+
"EnableModbusTCP": "Modbus TCP aktivieren"
449+
},
430450
"mqttadmin": {
431451
"MqttSettings": "MQTT-Einstellungen",
432452
"MqttConfiguration": "MQTT-Konfiguration",

webapp/src/locales/en.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"Settings": "Settings",
55
"NetworkSettings": "Network Settings",
66
"NTPSettings": "NTP Settings",
7+
"ModbusSettings": "Modbus Settings",
78
"MQTTSettings": "MQTT Settings",
89
"InverterSettings": "Inverter Settings",
910
"SecuritySettings": "Security Settings",
@@ -16,6 +17,7 @@
1617
"System": "System",
1718
"Network": "Network",
1819
"NTP": "NTP",
20+
"Modbus": "Modbus",
1921
"MQTT": "MQTT",
2022
"Console": "Console",
2123
"About": "About",
@@ -284,6 +286,19 @@
284286
"Day": "Day",
285287
"Night": "Night"
286288
},
289+
"modbusinfo": {
290+
"ModbusInformation": "Modbus Information",
291+
"TCPSummary": "Configuration Summary Modbus TCP",
292+
"ServerSummary": "Modbus Server Information",
293+
"Status": "@:mqttinfo.Status",
294+
"Enabled": "@:mqttinfo.Enabled",
295+
"Disabled": "@:mqttinfo.Disabled",
296+
"Server": "@:mqttinfo.Server",
297+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
298+
"Port": "@:mqttinfo.Port",
299+
"IDDTUPro": "ID for DTUPro dataset",
300+
"IDTotal": "ID for OpenDTU aggregation of all registered inverters (SunSpec)"
301+
},
287302
"mqttinfo": {
288303
"MqttInformation": "MQTT Information",
289304
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -427,6 +442,11 @@
427442
"EnableMdns": "Enable mDNS",
428443
"MdnsSettings": "mDNS Settings"
429444
},
445+
"modbusadmin": {
446+
"ModbusSettings": "Modbus Settings",
447+
"ModbusConfiguration": "Modbus Configuration",
448+
"EnableModbusTCP": "Enable Modbus TCP"
449+
},
430450
"mqttadmin": {
431451
"MqttSettings": "MQTT Settings",
432452
"MqttConfiguration": "MQTT Configuration",

webapp/src/locales/fr.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"Settings": "Paramètres",
55
"NetworkSettings": "Réseau",
66
"NTPSettings": "Heure locale",
7+
"ModbusSettings": "Modbus",
78
"MQTTSettings": "MQTT",
89
"InverterSettings": "Onduleurs",
910
"SecuritySettings": "Sécurité",
@@ -16,6 +17,7 @@
1617
"System": "Système",
1718
"Network": "Réseau",
1819
"NTP": "NTP",
20+
"Modbus": "Modbus",
1921
"MQTT": "MQTT",
2022
"Console": "Console",
2123
"About": "A propos",
@@ -284,6 +286,19 @@
284286
"Day": "Jour",
285287
"Night": "Nuit"
286288
},
289+
"modbusinfo": {
290+
"ModbusInformation": "Informations sur le Modbus",
291+
"TCPSummary": "Résumé de la configuration Modbus TCP",
292+
"ServerSummary": "Informations sur le serveur Modbus",
293+
"Status": "@:mqttinfo.Status",
294+
"Enabled": "@:mqttinfo.Enabled",
295+
"Disabled": "@:mqttinfo.Disabled",
296+
"Server": "@:mqttinfo.Server",
297+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
298+
"Port": "@:mqttinfo.Port",
299+
"IDDTUPro": "ID pour l'ensemble de données DTUPro",
300+
"IDTotal": "ID pour l'agrégation OpenDTU de tous les onduleurs enregistrés (SunSpec)"
301+
},
287302
"mqttinfo": {
288303
"MqttInformation": "MQTT Information",
289304
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -427,6 +442,11 @@
427442
"EnableMdns": "Activer mDNS",
428443
"MdnsSettings": "mDNS Settings"
429444
},
445+
"modbusadmin": {
446+
"ModbusSettings": "Paramètres Modbus",
447+
"ModbusConfiguration": "Configuration du système Modbus",
448+
"EnableModbusTCP": "Activer le Modbus TCP"
449+
},
430450
"mqttadmin": {
431451
"MqttSettings": "Paramètres MQTT",
432452
"MqttConfiguration": "Configuration du système MQTT",

webapp/src/router/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import HomeView from '@/views/HomeView.vue';
88
import InverterAdminView from '@/views/InverterAdminView.vue';
99
import LoginView from '@/views/LoginView.vue';
1010
import MaintenanceRebootView from '@/views/MaintenanceRebootView.vue';
11+
import ModbusAdminView from '@/views/ModbusAdminView.vue';
12+
import ModbusInfoView from '@/views/ModbusInfoView.vue';
1113
import MqttAdminView from '@/views/MqttAdminView.vue';
1214
import MqttInfoView from '@/views/MqttInfoView.vue';
1315
import NetworkAdminView from '@/views/NetworkAdminView.vue';
@@ -52,6 +54,11 @@ const router = createRouter({
5254
name: 'NTP',
5355
component: NtpInfoView
5456
},
57+
{
58+
path: '/info/modbus',
59+
name: 'Modbus',
60+
component: ModbusInfoView
61+
},
5562
{
5663
path: '/info/mqtt',
5764
name: 'MqTT',
@@ -72,6 +79,11 @@ const router = createRouter({
7279
name: 'NTP Settings',
7380
component: NtpAdminView
7481
},
82+
{
83+
path: '/settings/modbus',
84+
name: 'Modbus Settings',
85+
component: ModbusAdminView
86+
},
7587
{
7688
path: '/settings/mqtt',
7789
name: 'MqTT Settings',
@@ -115,4 +127,4 @@ const router = createRouter({
115127
]
116128
});
117129

118-
export default router;
130+
export default router;

webapp/src/types/ModbusConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface ModbusConfig {
2+
modbus_tcp_enabled: boolean;
3+
}

webapp/src/types/ModbusStatus.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface ModbusStatus {
2+
modbus_tcp_enabled: boolean;
3+
modbus_hostname: string;
4+
modbus_port: number;
5+
modbus_ip: string;
6+
modbus_id_dtupro: number;
7+
modbus_id_total: number;
8+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<template>
2+
<BasePage :title="$t('modbusadmin.ModbusSettings')" :isLoading="dataLoading">
3+
<BootstrapAlert v-model="showAlert" dismissible :variant="alertType">
4+
{{ alertMessage }}
5+
</BootstrapAlert>
6+
7+
<form @submit="saveModbusConfig">
8+
<CardElement :text="$t('modbusadmin.ModbusConfiguration')" textVariant="text-bg-primary">
9+
<InputElement :label="$t('modbusadmin.EnableModbusTCP')"
10+
v-model="modbusConfigList.modbus_tcp_enabled"
11+
type="checkbox" wide/>
12+
13+
</CardElement>
14+
15+
<FormFooter @reload="getModbusConfig"/>
16+
</form>
17+
</BasePage>
18+
</template>
19+
20+
<script lang="ts">
21+
import BasePage from '@/components/BasePage.vue';
22+
import BootstrapAlert from "@/components/BootstrapAlert.vue";
23+
import CardElement from '@/components/CardElement.vue';
24+
import FormFooter from '@/components/FormFooter.vue';
25+
import InputElement from '@/components/InputElement.vue';
26+
import type { ModbusConfig } from "@/types/ModbusConfig";
27+
import { authHeader, handleResponse } from '@/utils/authentication';
28+
import { defineComponent } from 'vue';
29+
30+
export default defineComponent({
31+
components: {
32+
BasePage,
33+
BootstrapAlert,
34+
CardElement,
35+
FormFooter,
36+
InputElement,
37+
},
38+
data() {
39+
return {
40+
dataLoading: true,
41+
modbusConfigList: {} as ModbusConfig,
42+
alertMessage: "",
43+
alertType: "info",
44+
showAlert: false,
45+
qosTypeList: [
46+
{ key: 0, value: 'QOS0' },
47+
{ key: 1, value: 'QOS1' },
48+
{ key: 2, value: 'QOS2' },
49+
],
50+
};
51+
},
52+
created() {
53+
this.getModbusConfig();
54+
},
55+
methods: {
56+
getModbusConfig() {
57+
this.dataLoading = true;
58+
fetch("/api/modbus/config", { headers: authHeader() })
59+
.then((response) => handleResponse(response, this.$emitter, this.$router))
60+
.then((data) => {
61+
this.modbusConfigList = data;
62+
this.dataLoading = false;
63+
});
64+
},
65+
saveModbusConfig(e: Event) {
66+
e.preventDefault();
67+
68+
const formData = new FormData();
69+
formData.append("data", JSON.stringify(this.modbusConfigList));
70+
71+
fetch("/api/modbus/config", {
72+
method: "POST",
73+
headers: authHeader(),
74+
body: formData,
75+
})
76+
.then((response) => handleResponse(response, this.$emitter, this.$router))
77+
.then(
78+
(response) => {
79+
this.alertMessage = this.$t('apiresponse.' + response.code, response.param);
80+
this.alertType = response.type;
81+
this.showAlert = true;
82+
}
83+
);
84+
},
85+
},
86+
});
87+
</script>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<template>
2+
<BasePage :title="$t('modbusinfo.ModbusInformation')" :isLoading="dataLoading" :show-reload="true" @reload="getModbusInfo">
3+
<CardElement :text="$t('modbusinfo.TCPSummary')" textVariant="text-bg-primary">
4+
<div class="table-responsive">
5+
<table class="table table-hover table-condensed">
6+
<tbody>
7+
<tr>
8+
<th>{{ $t('modbusinfo.Status') }}</th>
9+
<td>
10+
<StatusBadge :status="modbusDataList.modbus_tcp_enabled" true_text="modbusinfo.Enabled" false_text="modbusinfo.Disabled" />
11+
</td>
12+
</tr>
13+
<tr>
14+
<th>{{ $t('modbusinfo.Server') }}</th>
15+
<td>{{ modbusDataList.modbus_hostname }}</td>
16+
</tr>
17+
<tr>
18+
<th>{{ $t('modbusinfo.IpAddress') }}</th>
19+
<td>{{ modbusDataList.modbus_ip }}</td>
20+
</tr>
21+
<tr>
22+
<th>{{ $t('modbusinfo.Port') }}</th>
23+
<td>{{ modbusDataList.modbus_port }}</td>
24+
</tr>
25+
</tbody>
26+
</table>
27+
</div>
28+
</CardElement>
29+
<CardElement :text="$t('modbusinfo.ServerSummary')" textVariant="text-bg-primary">
30+
<div class="table-responsive">
31+
<table class="table table-hover table-condensed">
32+
<tbody>
33+
<tr>
34+
<th>{{ $t('modbusinfo.IDDTUPro') }}</th>
35+
<td>{{ modbusDataList.modbus_id_dtupro }}</td>
36+
</tr>
37+
<tr>
38+
<th>{{ $t('modbusinfo.IDTotal') }}</th>
39+
<td>{{ modbusDataList.modbus_id_total }}</td>
40+
</tr>
41+
</tbody>
42+
</table>
43+
</div>
44+
</CardElement>
45+
46+
</BasePage>
47+
</template>
48+
49+
<script lang="ts">
50+
import BasePage from '@/components/BasePage.vue';
51+
import CardElement from '@/components/CardElement.vue';
52+
import StatusBadge from '@/components/StatusBadge.vue';
53+
import type { ModbusStatus } from '@/types/ModbusStatus';
54+
import { authHeader, handleResponse } from '@/utils/authentication';
55+
import { defineComponent } from 'vue';
56+
57+
export default defineComponent({
58+
components: {
59+
BasePage,
60+
CardElement,
61+
StatusBadge
62+
},
63+
data() {
64+
return {
65+
dataLoading: true,
66+
modbusDataList: {} as ModbusStatus,
67+
};
68+
},
69+
created() {
70+
this.getModbusInfo();
71+
},
72+
methods: {
73+
getModbusInfo() {
74+
this.dataLoading = true;
75+
fetch("/api/modbus/status", { headers: authHeader() })
76+
.then((response) => handleResponse(response, this.$emitter, this.$router))
77+
.then((data) => {
78+
this.modbusDataList = data;
79+
this.dataLoading = false;
80+
});
81+
},
82+
},
83+
});
84+
</script>

0 commit comments

Comments
 (0)