Skip to content

Commit e4121c2

Browse files
committed
Add Templates for MQTT input and output
1 parent 2515e8b commit e4121c2

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

templates/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ <h2><TMPL_VAR SETTINGS.LABEL_TCP_UDP></h2>
375375
<center>
376376
<button type="submit" name="download_input" form="input_output_form" id="btnsubmit" data-role="button" data-inline="true" data-mini="true" data-icon="check"><TMPL_VAR SETTINGS.DOWNLOAD_INPUT></button>
377377
<button type="submit" name="download_output" form="input_output_form" id="btnsubmit" data-role="button" data-inline="true" data-mini="true" data-icon="check"><TMPL_VAR SETTINGS.DOWNLOAD_OUTPUT></button>
378+
<button type="submit" name="download_input_mqtt" form="input_output_form" id="btnsubmit" data-role="button" data-inline="true" data-mini="true" data-icon="check"><TMPL_VAR SETTINGS.DOWNLOAD_INPUT_MQTT></button>
379+
<button type="submit" name="download_output_mqtt" form="input_output_form" id="btnsubmit" data-role="button" data-inline="true" data-mini="true" data-icon="check"><TMPL_VAR SETTINGS.DOWNLOAD_OUTPUT_MQTT></button>
378380
</center>
379381
</p>
380382

templates/lang/language_de.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ HINT_MS_UDPPORT="Der UDP Port an dem der Miniserver die Daten lesen soll"
2929
LABEL_TEMPLATEBUILDER="Eingänge / Ausgänge"
3030
DOWNLOAD_INPUT="Download UDP Input XML"
3131
DOWNLOAD_OUTPUT="Download TCP Output XML"
32+
DOWNLOAD_INPUT_MQTT="Download MQTT Input XML"
33+
DOWNLOAD_OUTPUT_MQTT="Download MQTT Output XML"
3234
BUTTON_CANCEL="Abbrechen"
3335
BUTTON_SAVE="Speichern"
3436
BUTTON_OK="OK"

templates/lang/language_en.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ HINT_MS_UDPPORT="The UDP port of the Miniserver where the data should be receive
2929
LABEL_TEMPLATEBUILDER="Inputs / Outputs"
3030
DOWNLOAD_INPUT="Download UDP Input XML"
3131
DOWNLOAD_OUTPUT="Download TCP Output XML"
32+
DOWNLOAD_INPUT_MQTT="Download MQTT Input XML"
33+
DOWNLOAD_OUTPUT_MQTT="Download MQTT Output XML"
3234
BUTTON_CANCEL="Cancel"
3335
BUTTON_SAVE="Save"
3436
BUTTON_OK="OK"

webfrontend/htmlauth/index.cgi

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use LoxBerry::Web;
77
use MIME::Base64;
88
use Encode qw(decode encode);
99
use LoxBerry::LoxoneTemplateBuilder;
10+
use LoxBerry::IO;
1011

1112
# cgi
1213
my $cgi = CGI->new;
@@ -189,6 +190,79 @@ if ($R::saveformdata2) {
189190
print "Content-Disposition: attachment; filename=wolf_output.xml\n\n";
190191
print HTML::Entities::decode_entities($VO->output);
191192
exit
193+
} elsif (defined $R::download_input_mqtt) {
194+
my $VIhttp = LoxBerry::LoxoneTemplateBuilder->VirtualInHttp(
195+
Title => "Wolf ISM8 MQTT",
196+
Address => "http://localhost",
197+
PollingTime => "604800",
198+
Comment => "Created by LoxBerry Wolf ISM8 Plugin ($mday.$mon.$year)",
199+
);
200+
201+
my $count = scalar(@datenpunkte);
202+
203+
# Generate a temporary arroy for all virtual inputs
204+
for ($i = 1; $i < $count; $i++) {
205+
my $id = sprintf "%03d", $datenpunkte[$i][0];
206+
my $device = $datenpunkte[$i][1];
207+
my $name = encode('UTF-8', $datenpunkte[$i][1]." ".$datenpunkte[$i][2]);
208+
my $topic = encode('UTF-8', "wolfism8_".getMQTTFriendly($datenpunkte[$i][1])."_".getMQTTFriendly($datenpunkte[$i][2]));
209+
if ($id == '000') {
210+
next;
211+
}
212+
213+
foreach $item (@devices) {
214+
if ($item eq $device) {
215+
my $linenr = $VIhttp->VirtualInHttpCmd (
216+
Title => "$topic",
217+
Comment => "$name"
218+
);
219+
}
220+
}
221+
}
222+
223+
print ("Content-Type:application/x-download\n");
224+
print "Content-Disposition: attachment; filename=wolf_mqtt_input.xml\n\n";
225+
print HTML::Entities::decode_entities($VIhttp->output);
226+
exit
227+
} elsif (defined $R::download_output_mqtt) {
228+
my $mqttcred = LoxBerry::IO::mqtt_connectiondetails();
229+
my $port = $mqttcred->{udpinport};
230+
my $VO = LoxBerry::LoxoneTemplateBuilder->VirtualOut(
231+
Title => "Wolf ISM8 MQTT",
232+
Address => "/dev/udp/$ip/$port",
233+
Comment => "Created by LoxBerry Wolf ISM8 Plugin ($mday.$mon.$year)",
234+
);
235+
236+
my $count = scalar(@datenpunkte);
237+
238+
# Generate a temporary arroy for all virtual inputs
239+
for ($i = 1; $i < $count; $i++) {
240+
my $id = sprintf "%03d", $datenpunkte[$i][0];
241+
my $name = encode('UTF-8', $datenpunkte[$i][1]." ".$datenpunkte[$i][2]);
242+
my $topic = encode('UTF-8', "wolfism8/".getMQTTFriendly($datenpunkte[$i][1])."/".getMQTTFriendly($datenpunkte[$i][2]));
243+
my $topic_name = $topic;
244+
$topic_name =~ s/\//_/g;
245+
246+
if ($id == '000') {
247+
next;
248+
}
249+
250+
foreach $item (@devices) {
251+
if ($item eq $device) {
252+
my $linenr = $VO->VirtualOutCmd (
253+
Title => "$topic_name",
254+
Comment => "$name",
255+
CmdOn => "retain $topic \v",
256+
Analog => 1,
257+
);
258+
}
259+
}
260+
}
261+
262+
print ("Content-Type:application/x-download\n");
263+
print "Content-Disposition: attachment; filename=wolf_mqtt_output.xml\n\n";
264+
print HTML::Entities::decode_entities($VO->output);
265+
exit
192266
}
193267

194268
exit
@@ -374,6 +448,35 @@ sub loadDatenpunkte
374448
sub r_trim { my $s = shift; $s =~ s/\s+$//; return $s; }
375449
sub max($$) { $_[$_[0] < $_[1]]; }
376450

451+
sub getMQTTFriendly($)
452+
#Ersetzt alle Zeichen so, dass das Ergebnis als MQTT Topic taugt.
453+
{
454+
my $working_string = shift;
455+
456+
# Alles nach einem Klammer Anfang wird verworfen
457+
$working_string =~ s/\(.*//;
458+
459+
# Alles nach einem + wird verworfen
460+
$working_string =~ s/\+.*//;
461+
462+
# Leerzeichen am Ende wird verworfen
463+
$working_string =~ s/\s+$//;
464+
465+
my @tbr = ("/", "_");
466+
467+
for (my $i=0; $i <= scalar(@tbr)-1; $i+=2)
468+
{
469+
my $f = $tbr[$i];
470+
if ($working_string =~ /$f/)
471+
{
472+
my $r = $tbr[$i+1];
473+
$working_string =~ s/$f/$r/g;
474+
}
475+
}
476+
477+
return $working_string;
478+
}
479+
377480

378481
#####################################################
379482
# Save

0 commit comments

Comments
 (0)