@@ -7,6 +7,7 @@ use LoxBerry::Web;
77use MIME::Base64;
88use Encode qw( decode encode) ;
99use LoxBerry::LoxoneTemplateBuilder;
10+ use LoxBerry::IO;
1011
1112# cgi
1213my $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
374448sub r_trim { my $s = shift ; $s =~ s /\s +$// ; return $s ; }
375449sub 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