Skip to content

Commit 9e270e6

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

File tree

10 files changed

+298
-0
lines changed

10 files changed

+298
-0
lines changed

webapp/src/components/NavBar.vue

Lines changed: 6 additions & 0 deletions
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>

webapp/src/locales/de.json

Lines changed: 26 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",
@@ -290,6 +292,21 @@
290292
"Day": "Tag",
291293
"Night": "Nacht"
292294
},
295+
"modbusinfo": {
296+
"ModbusInformation": "Modbus-Informationen",
297+
"TCPSummary": "Konfigurationszusammenfassung Modbus TCP",
298+
"ServerSummary": "Informationen zu den Modbus Servern",
299+
"Status": "@:mqttinfo.Status",
300+
"Enabled": "@:mqttinfo.Enabled",
301+
"Disabled": "@:mqttinfo.Disabled",
302+
"Server": "@:mqttinfo.Server",
303+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
304+
"Port": "@:mqttinfo.Port",
305+
"Clients": "Maximale Anzahl der Modbus TCP-Clients",
306+
"IDDTUPro": "ID für DTUPro Datensatz",
307+
"IDTotal": "ID für OpenDTU Inverter (SunSpec) als Aggregation aller angemeldeter Inverter",
308+
"IDMeter": "ID für OpenDTU Zähler (SunSpec) für alle angemeldeten Inverter"
309+
},
293310
"mqttinfo": {
294311
"MqttInformation": "MQTT-Informationen",
295312
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -434,6 +451,15 @@
434451
"EnableMdns": "mDNS aktivieren",
435452
"MdnsSettings": "mDNS-Einstellungen"
436453
},
454+
"modbusadmin": {
455+
"ModbusSettings": "Modbus-Einstellungen",
456+
"ModbusConfiguration": "Modbus-Konfiguration",
457+
"EnableModbusTCP": "Modbus TCP aktivieren",
458+
"Clients": "@:modbusinfo.Clients",
459+
"IDDTUPro": "@:modbusinfo.IDDTUPro",
460+
"IDTotal": "@:modbusinfo.IDTotal",
461+
"IDMeter": "@:modbusinfo.IDMeter"
462+
},
437463
"mqttadmin": {
438464
"MqttSettings": "MQTT-Einstellungen",
439465
"MqttConfiguration": "MQTT-Konfiguration",

webapp/src/locales/en.json

Lines changed: 26 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",
@@ -290,6 +292,21 @@
290292
"Day": "Day",
291293
"Night": "Night"
292294
},
295+
"modbusinfo": {
296+
"ModbusInformation": "Modbus Information",
297+
"TCPSummary": "Configuration Summary Modbus TCP",
298+
"ServerSummary": "Modbus Server Information",
299+
"Status": "@:mqttinfo.Status",
300+
"Enabled": "@:mqttinfo.Enabled",
301+
"Disabled": "@:mqttinfo.Disabled",
302+
"Server": "@:mqttinfo.Server",
303+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
304+
"Port": "@:mqttinfo.Port",
305+
"Clients": "Maximum number of Modbus TCP clients",
306+
"IDDTUPro": "ID for DTUPro dataset",
307+
"IDTotal": "ID for OpenDTU Inverter (SunSpec) as aggregation of all registered inverters",
308+
"IDMeter": "ID for OpenDTU Meter (SunSpec) for all registered inverters"
309+
},
293310
"mqttinfo": {
294311
"MqttInformation": "MQTT Information",
295312
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -434,6 +451,15 @@
434451
"EnableMdns": "Enable mDNS",
435452
"MdnsSettings": "mDNS Settings"
436453
},
454+
"modbusadmin": {
455+
"ModbusSettings": "Modbus Settings",
456+
"ModbusConfiguration": "Modbus Configuration",
457+
"EnableModbusTCP": "Enable Modbus TCP",
458+
"Clients": "@:modbusinfo.Clients",
459+
"IDDTUPro": "@:modbusinfo.IDDTUPro",
460+
"IDTotal": "@:modbusinfo.IDTotal",
461+
"IDMeter": "@:modbusinfo.IDMeter"
462+
},
437463
"mqttadmin": {
438464
"MqttSettings": "MQTT Settings",
439465
"MqttConfiguration": "MQTT Configuration",

webapp/src/locales/fr.json

Lines changed: 26 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",
@@ -290,6 +292,21 @@
290292
"Day": "Jour",
291293
"Night": "Nuit"
292294
},
295+
"modbusinfo": {
296+
"ModbusInformation": "Informations sur le Modbus",
297+
"TCPSummary": "Résumé de la configuration Modbus TCP",
298+
"ServerSummary": "Informations sur le serveur Modbus",
299+
"Status": "@:mqttinfo.Status",
300+
"Enabled": "@:mqttinfo.Enabled",
301+
"Disabled": "@:mqttinfo.Disabled",
302+
"Server": "@:mqttinfo.Server",
303+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
304+
"Port": "@:mqttinfo.Port",
305+
"Clients": "Nombre maximum de clients Modbus TCP",
306+
"IDDTUPro": "ID pour l'ensemble de données DTUPro",
307+
"IDTotal": "ID pour OpenDTU Inverter (SunSpec) comme agrégation de tous les onduleurs enregistrés",
308+
"IDMeter": "ID pour OpenDTU Compteur (SunSpec) pour tous les onduleurs enregistrés"
309+
},
293310
"mqttinfo": {
294311
"MqttInformation": "MQTT Information",
295312
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -434,6 +451,15 @@
434451
"EnableMdns": "Activer mDNS",
435452
"MdnsSettings": "mDNS Settings"
436453
},
454+
"modbusadmin": {
455+
"ModbusSettings": "Paramètres Modbus",
456+
"ModbusConfiguration": "Configuration du système Modbus",
457+
"EnableModbusTCP": "Activer le Modbus TCP",
458+
"Clients": "@:modbusinfo.Clients",
459+
"IDDTUPro": "@:modbusinfo.IDDTUPro",
460+
"IDTotal": "@:modbusinfo.IDTotal",
461+
"IDMeter": "@:modbusinfo.IDMeter"
462+
},
437463
"mqttadmin": {
438464
"MqttSettings": "Paramètres MQTT",
439465
"MqttConfiguration": "Configuration du système MQTT",

webapp/src/router/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import HomeView from '@/views/HomeView.vue';
99
import InverterAdminView from '@/views/InverterAdminView.vue';
1010
import LoginView from '@/views/LoginView.vue';
1111
import MaintenanceRebootView from '@/views/MaintenanceRebootView.vue';
12+
import ModbusAdminView from '@/views/ModbusAdminView.vue';
13+
import ModbusInfoView from '@/views/ModbusInfoView.vue';
1214
import MqttAdminView from '@/views/MqttAdminView.vue';
1315
import MqttInfoView from '@/views/MqttInfoView.vue';
1416
import NetworkAdminView from '@/views/NetworkAdminView.vue';
@@ -58,6 +60,11 @@ const router = createRouter({
5860
name: 'NTP',
5961
component: NtpInfoView
6062
},
63+
{
64+
path: '/info/modbus',
65+
name: 'Modbus',
66+
component: ModbusInfoView
67+
},
6168
{
6269
path: '/info/mqtt',
6370
name: 'MqTT',
@@ -78,6 +85,11 @@ const router = createRouter({
7885
name: 'NTP Settings',
7986
component: NtpAdminView
8087
},
88+
{
89+
path: '/settings/modbus',
90+
name: 'Modbus Settings',
91+
component: ModbusAdminView
92+
},
8193
{
8294
path: '/settings/mqtt',
8395
name: 'MqTT Settings',

webapp/src/types/ModbusConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface ModbusConfig {
2+
modbus_tcp_enabled: boolean;
3+
modbus_clients: number;
4+
modbus_id_dtupro: number;
5+
modbus_id_total: number;
6+
modbus_id_meter: number;
7+
}

webapp/src/types/ModbusStatus.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface ModbusStatus {
2+
modbus_tcp_enabled: boolean;
3+
modbus_hostname: string;
4+
modbus_port: number;
5+
modbus_clients: number;
6+
modbus_ip: string;
7+
modbus_id_dtupro: number;
8+
modbus_id_total: number;
9+
modbus_id_meter: number;
10+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
<InputElement :label="$t('modbusadmin.Clients')"
13+
v-model="modbusConfigList.modbus_clients"
14+
type="number" min="1" max="4"/>
15+
<InputElement :label="$t('modbusadmin.IDDTUPro')"
16+
v-model="modbusConfigList.modbus_id_dtupro"
17+
type="number" min="1" max="255"/>
18+
<InputElement :label="$t('modbusadmin.IDTotal')"
19+
v-model="modbusConfigList.modbus_id_total"
20+
type="number" min="1" max="255"/>
21+
<InputElement :label="$t('modbusadmin.IDMeter')"
22+
v-model="modbusConfigList.modbus_id_meter"
23+
type="number" min="1" max="255"/>
24+
</CardElement>
25+
26+
<FormFooter @reload="getModbusConfig"/>
27+
</form>
28+
</BasePage>
29+
</template>
30+
31+
<script lang="ts">
32+
import BasePage from '@/components/BasePage.vue';
33+
import BootstrapAlert from "@/components/BootstrapAlert.vue";
34+
import CardElement from '@/components/CardElement.vue';
35+
import FormFooter from '@/components/FormFooter.vue';
36+
import InputElement from '@/components/InputElement.vue';
37+
import type { ModbusConfig } from "@/types/ModbusConfig";
38+
import { authHeader, handleResponse } from '@/utils/authentication';
39+
import { defineComponent } from 'vue';
40+
41+
export default defineComponent({
42+
components: {
43+
BasePage,
44+
BootstrapAlert,
45+
CardElement,
46+
FormFooter,
47+
InputElement,
48+
},
49+
data() {
50+
return {
51+
dataLoading: true,
52+
modbusConfigList: {} as ModbusConfig,
53+
alertMessage: "",
54+
alertType: "info",
55+
showAlert: false,
56+
};
57+
},
58+
created() {
59+
this.getModbusConfig();
60+
},
61+
methods: {
62+
getModbusConfig() {
63+
this.dataLoading = true;
64+
fetch("/api/modbus/config", { headers: authHeader() })
65+
.then((response) => handleResponse(response, this.$emitter, this.$router))
66+
.then((data) => {
67+
this.modbusConfigList = data;
68+
this.dataLoading = false;
69+
});
70+
},
71+
saveModbusConfig(e: Event) {
72+
e.preventDefault();
73+
74+
const formData = new FormData();
75+
formData.append("data", JSON.stringify(this.modbusConfigList));
76+
77+
fetch("/api/modbus/config", {
78+
method: "POST",
79+
headers: authHeader(),
80+
body: formData,
81+
})
82+
.then((response) => handleResponse(response, this.$emitter, this.$router))
83+
.then(
84+
(response) => {
85+
this.alertMessage = this.$t('apiresponse.' + response.code, response.param);
86+
this.alertType = response.type;
87+
this.showAlert = true;
88+
}
89+
);
90+
},
91+
},
92+
});
93+
</script>

0 commit comments

Comments
 (0)