Skip to content

Commit 049381a

Browse files
authored
Merge pull request #517 from openWB/feature_http_api
setting http api
2 parents cc8a23c + b16cdaf commit 049381a

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

src/views/GeneralConfig.vue

+121
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,122 @@
109109
</openwb-base-alert>
110110
</div>
111111
</div>
112+
<div v-if="!installAssistantActive">
113+
<openwb-base-button-group-input
114+
title="HTTP-API"
115+
:buttons="[
116+
{
117+
buttonValue: false,
118+
text: 'Aus',
119+
class: 'btn-outline-danger',
120+
},
121+
{
122+
buttonValue: true,
123+
text: 'An',
124+
class: 'btn-outline-success',
125+
},
126+
]"
127+
:model-value="
128+
$store.state.mqtt['openWB/general/http_api']
129+
"
130+
@update:model-value="
131+
updateState('openWB/general/http_api', $event)
132+
"
133+
>
134+
<template #help>
135+
<p>
136+
Mit der HTTP-API kann man den Wert eines
137+
MQTT-Topics per HTTPs (Port 8443) abfragen oder
138+
neu setzen. Topics können über GET oder POST
139+
abgefragt, neue Werte nur mit POST gesetzt
140+
werden.
141+
</p>
142+
<p>
143+
Beispiel 1: Abfrage des aktuellen
144+
Systemzeitstempels
145+
</p>
146+
<ul>
147+
<li>
148+
GET-Request:<br />
149+
<openwb-base-copy-to-clipboard
150+
class="text-info"
151+
tooltip="URL kopieren"
152+
>
153+
https://{{
154+
getIpAddress()
155+
}}:8443/v1/?topic=openWB/system/time
156+
</openwb-base-copy-to-clipboard>
157+
</li>
158+
<li>
159+
POST-Request über 'curl' mit privatem
160+
SSL-Zertifikat und Verarbeitung durch
161+
'jq':<br />
162+
<openwb-base-copy-to-clipboard
163+
class="text-info"
164+
tooltip="Befehl kopieren"
165+
>
166+
curl -k -s -X POST --data
167+
'{"topic":"openWB/system/time"}'
168+
https://{{ getIpAddress() }}:8443/v1/ |
169+
jq .
170+
</openwb-base-copy-to-clipboard>
171+
</li>
172+
</ul>
173+
<p>
174+
Die zurückgegebenen Daten sind im JSON-Format.
175+
Der Inhalt ist nach folgendem Schema aufgebaut:
176+
</p>
177+
<pre class="border border-info w-100 p-1">{{
178+
JSON.stringify(
179+
{
180+
status: "success",
181+
topic: "openWB/system/time",
182+
message: 1721287000.646975,
183+
},
184+
null,
185+
4,
186+
)
187+
}}</pre>
188+
<p>
189+
Im Fehlerfall wird der Status auf "failed"
190+
gesetzt und eine Fehlermeldung zurückgegeben.
191+
</p>
192+
<p>Beispiel 2: integriertes Display abschalten</p>
193+
<ul>
194+
<li>
195+
POST-Request über 'curl' mit privatem
196+
SSL-Zertifikat und Verarbeitung durch
197+
'jq':<br />
198+
<openwb-base-copy-to-clipboard
199+
class="text-info"
200+
tooltip="Befehl kopieren"
201+
>
202+
curl -k -s -X POST --data '{"topic":
203+
"openWB/set/optional/int_display/active",
204+
"message": false}' https://{{
205+
getIpAddress()
206+
}}:8443/v1/ | jq .
207+
</openwb-base-copy-to-clipboard>
208+
</li>
209+
</ul>
210+
<p>
211+
Die zurückgegebenen Daten sind im JSON-Format.
212+
Der Inhalt ist nach folgendem Schema aufgebaut:
213+
</p>
214+
<pre class="border border-info w-100 p-1">{{
215+
JSON.stringify(
216+
{
217+
status: "success",
218+
topic: "openWB/set/optional/int_display/active",
219+
message: false,
220+
},
221+
null,
222+
4,
223+
)
224+
}}</pre>
225+
</template>
226+
</openwb-base-button-group-input>
227+
</div>
112228
</openwb-base-card>
113229
<openwb-base-card title="Hardware">
114230
<div v-if="$store.state.mqtt['openWB/general/extern'] === true">
@@ -594,6 +710,7 @@ export default {
594710
"openWB/general/extern",
595711
"openWB/general/control_interval",
596712
"openWB/general/grid_protection_configured",
713+
"openWB/general/http_api",
597714
"openWB/general/external_buttons_hw",
598715
"openWB/general/modbus_control",
599716
"openWB/general/notifications/selected",
@@ -608,6 +725,7 @@ export default {
608725
"openWB/general/web_theme",
609726
"openWB/system/configurable/ripple_control_receivers",
610727
"openWB/system/configurable/web_themes",
728+
"openWB/system/ip_address",
611729
],
612730
};
613731
},
@@ -642,6 +760,9 @@ export default {
642760
},
643761
},
644762
methods: {
763+
getIpAddress() {
764+
return this.$store.state.mqtt["openWB/system/ip_address"];
765+
},
645766
getWebThemeDefaults(webThemeType) {
646767
const webThemeDefaults = this.webThemeList.find(
647768
(element) => element.value == webThemeType,

0 commit comments

Comments
 (0)