Skip to content

Commit

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

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
  • Loading branch information
b0661 committed Jul 10, 2024
1 parent dab58cc commit 9e270e6
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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
26 changes: 26 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 @@ -290,6 +292,21 @@
"Day": "Tag",
"Night": "Nacht"
},
"modbusinfo": {
"ModbusInformation": "Modbus-Informationen",
"TCPSummary": "Konfigurationszusammenfassung Modbus TCP",
"ServerSummary": "Informationen zu den Modbus Servern",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"Clients": "Maximale Anzahl der Modbus TCP-Clients",
"IDDTUPro": "ID für DTUPro Datensatz",
"IDTotal": "ID für OpenDTU Inverter (SunSpec) als Aggregation aller angemeldeter Inverter",
"IDMeter": "ID für OpenDTU Zähler (SunSpec) für alle angemeldeten Inverter"
},
"mqttinfo": {
"MqttInformation": "MQTT-Informationen",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -434,6 +451,15 @@
"EnableMdns": "mDNS aktivieren",
"MdnsSettings": "mDNS-Einstellungen"
},
"modbusadmin": {
"ModbusSettings": "Modbus-Einstellungen",
"ModbusConfiguration": "Modbus-Konfiguration",
"EnableModbusTCP": "Modbus TCP aktivieren",
"Clients": "@:modbusinfo.Clients",
"IDDTUPro": "@:modbusinfo.IDDTUPro",
"IDTotal": "@:modbusinfo.IDTotal",
"IDMeter": "@:modbusinfo.IDMeter"
},
"mqttadmin": {
"MqttSettings": "MQTT-Einstellungen",
"MqttConfiguration": "MQTT-Konfiguration",
Expand Down
26 changes: 26 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 @@ -290,6 +292,21 @@
"Day": "Day",
"Night": "Night"
},
"modbusinfo": {
"ModbusInformation": "Modbus Information",
"TCPSummary": "Configuration Summary Modbus TCP",
"ServerSummary": "Modbus Server Information",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"Clients": "Maximum number of Modbus TCP clients",
"IDDTUPro": "ID for DTUPro dataset",
"IDTotal": "ID for OpenDTU Inverter (SunSpec) as aggregation of all registered inverters",
"IDMeter": "ID for OpenDTU Meter (SunSpec) for all registered inverters"
},
"mqttinfo": {
"MqttInformation": "MQTT Information",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -434,6 +451,15 @@
"EnableMdns": "Enable mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Modbus Settings",
"ModbusConfiguration": "Modbus Configuration",
"EnableModbusTCP": "Enable Modbus TCP",
"Clients": "@:modbusinfo.Clients",
"IDDTUPro": "@:modbusinfo.IDDTUPro",
"IDTotal": "@:modbusinfo.IDTotal",
"IDMeter": "@:modbusinfo.IDMeter"
},
"mqttadmin": {
"MqttSettings": "MQTT Settings",
"MqttConfiguration": "MQTT Configuration",
Expand Down
26 changes: 26 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 @@ -290,6 +292,21 @@
"Day": "Jour",
"Night": "Nuit"
},
"modbusinfo": {
"ModbusInformation": "Informations sur le Modbus",
"TCPSummary": "Résumé de la configuration Modbus TCP",
"ServerSummary": "Informations sur le serveur Modbus",
"Status": "@:mqttinfo.Status",
"Enabled": "@:mqttinfo.Enabled",
"Disabled": "@:mqttinfo.Disabled",
"Server": "@:mqttinfo.Server",
"IpAddress": "@:interfacenetworkinfo.IpAddress",
"Port": "@:mqttinfo.Port",
"Clients": "Nombre maximum de clients Modbus TCP",
"IDDTUPro": "ID pour l'ensemble de données DTUPro",
"IDTotal": "ID pour OpenDTU Inverter (SunSpec) comme agrégation de tous les onduleurs enregistrés",
"IDMeter": "ID pour OpenDTU Compteur (SunSpec) pour tous les onduleurs enregistrés"
},
"mqttinfo": {
"MqttInformation": "MQTT Information",
"ConfigurationSummary": "@:ntpinfo.ConfigurationSummary",
Expand Down Expand Up @@ -434,6 +451,15 @@
"EnableMdns": "Activer mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Paramètres Modbus",
"ModbusConfiguration": "Configuration du système Modbus",
"EnableModbusTCP": "Activer le Modbus TCP",
"Clients": "@:modbusinfo.Clients",
"IDDTUPro": "@:modbusinfo.IDDTUPro",
"IDTotal": "@:modbusinfo.IDTotal",
"IDMeter": "@:modbusinfo.IDMeter"
},
"mqttadmin": {
"MqttSettings": "Paramètres MQTT",
"MqttConfiguration": "Configuration du système MQTT",
Expand Down
12 changes: 12 additions & 0 deletions webapp/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 @@ -58,6 +60,11 @@ const router = createRouter({
name: 'NTP',
component: NtpInfoView
},
{
path: '/info/modbus',
name: 'Modbus',
component: ModbusInfoView
},
{
path: '/info/mqtt',
name: 'MqTT',
Expand All @@ -78,6 +85,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
7 changes: 7 additions & 0 deletions webapp/src/types/ModbusConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface ModbusConfig {
modbus_tcp_enabled: boolean;
modbus_clients: number;
modbus_id_dtupro: number;
modbus_id_total: number;
modbus_id_meter: number;
}
10 changes: 10 additions & 0 deletions webapp/src/types/ModbusStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface ModbusStatus {
modbus_tcp_enabled: boolean;
modbus_hostname: string;
modbus_port: number;
modbus_clients: number;
modbus_ip: string;
modbus_id_dtupro: number;
modbus_id_total: number;
modbus_id_meter: number;
}
93 changes: 93 additions & 0 deletions webapp/src/views/ModbusAdminView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<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.EnableModbusTCP')"
v-model="modbusConfigList.modbus_tcp_enabled"
type="checkbox" wide/>
<InputElement :label="$t('modbusadmin.Clients')"
v-model="modbusConfigList.modbus_clients"
type="number" min="1" max="4"/>
<InputElement :label="$t('modbusadmin.IDDTUPro')"
v-model="modbusConfigList.modbus_id_dtupro"
type="number" min="1" max="255"/>
<InputElement :label="$t('modbusadmin.IDTotal')"
v-model="modbusConfigList.modbus_id_total"
type="number" min="1" max="255"/>
<InputElement :label="$t('modbusadmin.IDMeter')"
v-model="modbusConfigList.modbus_id_meter"
type="number" min="1" max="255"/>
</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,
};
},
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>
Loading

0 comments on commit 9e270e6

Please sign in to comment.