Skip to content

Commit 77d2f85

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

File tree

9 files changed

+260
-0
lines changed

9 files changed

+260
-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: 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",
@@ -287,6 +289,19 @@
287289
"Day": "Tag",
288290
"Night": "Nacht"
289291
},
292+
"modbusinfo": {
293+
"ModbusInformation": "Modbus-Informationen",
294+
"TCPSummary": "Konfigurationszusammenfassung Modbus TCP",
295+
"ServerSummary": "Informationen zu den Modbus Servern",
296+
"Status": "@:mqttinfo.Status",
297+
"Enabled": "@:mqttinfo.Enabled",
298+
"Disabled": "@:mqttinfo.Disabled",
299+
"Server": "@:mqttinfo.Server",
300+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
301+
"Port": "@:mqttinfo.Port",
302+
"IDDTUPro": "ID für DTUPro Datensatz",
303+
"IDTotal": "ID für OpenDTU Zusammenfassung aller angemeldeter Inverter (SunSpec)"
304+
},
290305
"mqttinfo": {
291306
"MqttInformation": "MQTT-Informationen",
292307
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -430,6 +445,11 @@
430445
"EnableMdns": "mDNS aktivieren",
431446
"MdnsSettings": "mDNS-Einstellungen"
432447
},
448+
"modbusadmin": {
449+
"ModbusSettings": "Modbus-Einstellungen",
450+
"ModbusConfiguration": "Modbus-Konfiguration",
451+
"EnableModbusTCP": "Modbus TCP aktivieren"
452+
},
433453
"mqttadmin": {
434454
"MqttSettings": "MQTT-Einstellungen",
435455
"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",
@@ -287,6 +289,19 @@
287289
"Day": "Day",
288290
"Night": "Night"
289291
},
292+
"modbusinfo": {
293+
"ModbusInformation": "Modbus Information",
294+
"TCPSummary": "Configuration Summary Modbus TCP",
295+
"ServerSummary": "Modbus Server Information",
296+
"Status": "@:mqttinfo.Status",
297+
"Enabled": "@:mqttinfo.Enabled",
298+
"Disabled": "@:mqttinfo.Disabled",
299+
"Server": "@:mqttinfo.Server",
300+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
301+
"Port": "@:mqttinfo.Port",
302+
"IDDTUPro": "ID for DTUPro dataset",
303+
"IDTotal": "ID for OpenDTU aggregation of all registered inverters (SunSpec)"
304+
},
290305
"mqttinfo": {
291306
"MqttInformation": "MQTT Information",
292307
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -430,6 +445,11 @@
430445
"EnableMdns": "Enable mDNS",
431446
"MdnsSettings": "mDNS Settings"
432447
},
448+
"modbusadmin": {
449+
"ModbusSettings": "Modbus Settings",
450+
"ModbusConfiguration": "Modbus Configuration",
451+
"EnableModbusTCP": "Enable Modbus TCP"
452+
},
433453
"mqttadmin": {
434454
"MqttSettings": "MQTT Settings",
435455
"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",
@@ -287,6 +289,19 @@
287289
"Day": "Jour",
288290
"Night": "Nuit"
289291
},
292+
"modbusinfo": {
293+
"ModbusInformation": "Informations sur le Modbus",
294+
"TCPSummary": "Résumé de la configuration Modbus TCP",
295+
"ServerSummary": "Informations sur le serveur Modbus",
296+
"Status": "@:mqttinfo.Status",
297+
"Enabled": "@:mqttinfo.Enabled",
298+
"Disabled": "@:mqttinfo.Disabled",
299+
"Server": "@:mqttinfo.Server",
300+
"IpAddress": "@:interfacenetworkinfo.IpAddress",
301+
"Port": "@:mqttinfo.Port",
302+
"IDDTUPro": "ID pour l'ensemble de données DTUPro",
303+
"IDTotal": "ID pour l'agrégation OpenDTU de tous les onduleurs enregistrés (SunSpec)"
304+
},
290305
"mqttinfo": {
291306
"MqttInformation": "MQTT Information",
292307
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
@@ -430,6 +445,11 @@
430445
"EnableMdns": "Activer mDNS",
431446
"MdnsSettings": "mDNS Settings"
432447
},
448+
"modbusadmin": {
449+
"ModbusSettings": "Paramètres Modbus",
450+
"ModbusConfiguration": "Configuration du système Modbus",
451+
"EnableModbusTCP": "Activer le Modbus TCP"
452+
},
433453
"mqttadmin": {
434454
"MqttSettings": "Paramètres MQTT",
435455
"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: 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)