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 Apr 14, 2024
1 parent 1f08b32 commit 04ebf74
Show file tree
Hide file tree
Showing 9 changed files with 260 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
20 changes: 20 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 @@ -287,6 +289,19 @@
"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",
"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 @@ -430,6 +445,11 @@
"EnableMdns": "mDNS aktivieren",
"MdnsSettings": "mDNS-Einstellungen"
},
"modbusadmin": {
"ModbusSettings": "Modbus-Einstellungen",
"ModbusConfiguration": "Modbus-Konfiguration",
"EnableModbusTCP": "Modbus TCP aktivieren"
},
"mqttadmin": {
"MqttSettings": "MQTT-Einstellungen",
"MqttConfiguration": "MQTT-Konfiguration",
Expand Down
20 changes: 20 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 @@ -287,6 +289,19 @@
"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",
"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 @@ -430,6 +445,11 @@
"EnableMdns": "Enable mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Modbus Settings",
"ModbusConfiguration": "Modbus Configuration",
"EnableModbusTCP": "Enable Modbus TCP"
},
"mqttadmin": {
"MqttSettings": "MQTT Settings",
"MqttConfiguration": "MQTT Configuration",
Expand Down
20 changes: 20 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 @@ -287,6 +289,19 @@
"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",
"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 @@ -430,6 +445,11 @@
"EnableMdns": "Activer mDNS",
"MdnsSettings": "mDNS Settings"
},
"modbusadmin": {
"ModbusSettings": "Paramètres Modbus",
"ModbusConfiguration": "Configuration du système Modbus",
"EnableModbusTCP": "Activer le Modbus TCP"
},
"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
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_tcp_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_tcp_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.EnableModbusTCP')"
v-model="modbusConfigList.modbus_tcp_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>
84 changes: 84 additions & 0 deletions webapp/src/views/ModbusInfoView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<BasePage :title="$t('modbusinfo.ModbusInformation')" :isLoading="dataLoading" :show-reload="true" @reload="getModbusInfo">
<CardElement :text="$t('modbusinfo.TCPSummary')" 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_tcp_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>
</tbody>
</table>
</div>
</CardElement>
<CardElement :text="$t('modbusinfo.ServerSummary')" textVariant="text-bg-primary">
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tbody>
<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 04ebf74

Please sign in to comment.