Skip to content

Commit

Permalink
Loxone Grabber; Miniserver select
Browse files Browse the repository at this point in the history
  • Loading branch information
mschlenstedt committed Mar 9, 2019
1 parent 2dfc233 commit bc9a8f4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 70 deletions.
69 changes: 33 additions & 36 deletions bin/datatoloxone.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
##########################################################################

# Version of this script
my $version = "4.4.0.3";
my $version = "4.5.0.0";

our $pcfg = new Config::Simple("$lbpconfigdir/weather4lox.cfg");
my $udpport = $pcfg->param("SERVER.UDPPORT");
Expand Down Expand Up @@ -79,7 +79,7 @@

my $i;

# Clear HTML databse
# Clear HTML database
open(F,">$lbplogdir/weatherdata.html");
flock(F,2);
print F "";
Expand Down Expand Up @@ -1684,42 +1684,39 @@

sub send {

# Create HTML webpage
LOGINF "Adding value to weatherdata.html. Value:$name\@$value";
open(F,">>$lbplogdir/weatherdata.html");
print F "$name\@$value<br>\n";
close(F);

# Send by UDP
my %miniservers;
%miniservers = LoxBerry::System::get_miniservers();

#if ($miniservers{1}{IPAddress} ne "" && $sendudp) {
if ($sendudp) {
$tmpudp .= "$name\@$value; ";
LOGINF "Adding value to UDP send queue. Value:$name\@$value";
if ($udp == 1) {
foreach my $ms (sort keys %miniservers) {
if ($miniservers{$ms}{IPAddress} ne "" && $udpport ne "") {
LOGINF "$sendqueue: Send Data to " . $miniservers{$ms}{Name};
# Send value
my $sock = IO::Socket::INET->new(
Proto => 'udp',
PeerPort => $udpport,
PeerAddr => $miniservers{$ms}{IPAddress},
);
$sock->send($tmpudp);
LOGOK "$sendqueue: Sent OK to " . $miniservers{$ms}{Name} . ". IP:" . $miniservers{$ms}{IPAddress} . " Port:$udpport";
$sendqueue++;
Time::HiRes::usleep (10000); # 10 Milliseconds
# Create HTML webpage
LOGINF "Adding value to weatherdata.html. Value:$name\@$value";
open(F,">>$lbplogdir/weatherdata.html");
print F "$name\@$value<br>\n";
close(F);

# Send by UDP
my $msno = defined $pcfg->param("SERVER.MSNO") ? $pcfg->param("SERVER.MSNO") : 1;
my %miniservers = LoxBerry::System::get_miniservers();

#if ($miniservers{1}{IPAddress} ne "" && $sendudp) {
if ($sendudp) {
$tmpudp .= "$name\@$value; ";
LOGINF "Adding value to UDP send queue. Value:$name\@$value";
if ($udp == 1) {
if ($miniservers{$msno}{IPAddress} ne "" && $udpport ne "") {
LOGINF "$sendqueue: Send Data to " . $miniservers{$msno}{Name};
# Send value
my $sock = IO::Socket::INET->new(
Proto => 'udp',
PeerPort => $udpport,
PeerAddr => $miniservers{$msno}{IPAddress},
);
$sock->send($tmpudp);
LOGOK "$sendqueue: Sent OK to " . $miniservers{$msno}{Name} . ". IP:" . $miniservers{$msno}{IPAddress} . " Port:$udpport";
$sendqueue++;
Time::HiRes::usleep (10000); # 10 Milliseconds
}
$udp = 0;
$tmpudp = "";
}
$udp = 0;
$tmpudp = "";
}
}

return();
}
return();

}
exit;
Expand Down
15 changes: 12 additions & 3 deletions bin/fetch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
##########################################################################

# Version of this script
my $version = "4.4.0";
my $version = "4.5.0.0";

my $pcfg = new Config::Simple("$lbpconfigdir/weather4lox.cfg");
my $service = $pcfg->param("SERVER.WEATHERSERVICE");
Expand Down Expand Up @@ -80,15 +80,24 @@

}

# Grab some data from Loxone Miniserver
if ( $pcfg->param("SERVER.LOXGRABBER") ) {
if ($verbose) {
system ("$lbpbindir/grabber_loxone.pl -v");
} else {
system ("$lbpbindir/grabber_loxone.pl");
}
}

# Data to Loxone
$log->open;
LOGINF "Starting script datatoloxone.pl";
$log->close;

if ($verbose) {
system ("$lbpbindir/datatoloxone.pl -v");
system ("$lbpbindir/datatoloxone.pl -v");
} else {
system ("$lbpbindir/datatoloxone.pl");
system ("$lbpbindir/datatoloxone.pl");
}

# Exit
Expand Down
4 changes: 2 additions & 2 deletions bin/grabber_loxone.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Grabber for overwriting data by Loxone data

# Copyright 2016-2018 Michael Schlenstedt, michael@loxberry.de
# Christian Fenzl, christian@loxberry.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,15 +38,14 @@
##########################################################################

# Version of this script
my $version = "4.4.3.1";
my $version = "4.5.0.0";

my $currentnametmp = "$lbplogdir/current.dat.tmp";
my $currentname = "$lbplogdir/current.dat";

my $pcfg = new Config::Simple("$lbpconfigdir/weather4lox.cfg");

# Read language phrases

my %L = LoxBerry::System::readlanguage("language.ini");

# Create a logging object
Expand Down
2 changes: 2 additions & 0 deletions config/weather4lox.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SENDDFC=""
WEATHERSERVICE=darksky
UDPPORT=7000
METRIC=1
MSNO=1
LOXGRABBER=0

[WEB]
THEME=dark
Expand Down
2 changes: 1 addition & 1 deletion plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EMAIL=Michael@loxberry.de
# The version of your plugin - important if you would like to write an
# upgrade script. Use a correct syntax, which is supported by LoxBerry:
# More info: http://www.loxwiki.eu/x/LYG3AQ
VERSION=4.4.3
VERSION=4.5.0

# Short name and prefered subfolder of your Plugin (do not use blanks - they
# will be filtered - and use lowercase only)! Used for script names in
Expand Down
4 changes: 4 additions & 0 deletions templates/lang/language_en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ LABEL_UNITS="Units"
LABEL_METRIC="Metric"
LABEL_IMPERIAL="English/Imperial"
LABEL_FETCH_DATA="Fetch Weather Data"
LABEL_LOXGRABBER="Loxone Grabber"
HINT_LOXGRABBER="Grab local data from Miniserver and use it here."
LABEL_MINISERVER="Miniserver"
HINT_MINISERVER="Use this Niniserver with the plugin."
LABEL_ON="On"
LABEL_OFF="Off"
LABEL_1MINUTE="Every Minute"
Expand Down
57 changes: 29 additions & 28 deletions templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ <h2><TMPL_VAR SETTINGS.LABEL_SERVER_SETTINGS></h2>
&nbsp;
</td>
</tr>
<tr>
<td width="25%">
<label id="labelloxgrabber"><TMPL_VAR SETTINGS.LABEL_LOXGRABBER></label>
</td>
<td width="50%">
<TMPL_VAR LOXGRABBER>
</td>
<td width="5%" valign="middle">
&nbsp;
</td>
<td width="20%">
<font size="-1"><TMPL_VAR SETTINGS.HINT_LOXGRABBER></font>
</td>
</tr>
<tr>
<td width="25%">
<label id="labelauto"><TMPL_VAR SETTINGS.LABEL_FETCH_DATA></label>
Expand Down Expand Up @@ -406,6 +420,7 @@ <h2><TMPL_VAR SETTINGS.LABEL_WU_SETTINGS></h2>

// Add some attributes PERL::CGI doesn't provide
$('select[name=getdata]').attr('data-role','flipswitch');
$('select[name=loxgrabber]').attr('data-role','flipswitch');
$('select[name=weatherservice]').attr('data-mini','true');
$('select[name=wulang]').attr('data-mini','true');
$('select[name=darkskylang]').attr('data-mini','true');
Expand Down Expand Up @@ -469,6 +484,20 @@ <h2><TMPL_VAR SETTINGS.LABEL_MINISERVERCONNECTION></h2>
&nbsp;
</td>
</tr>
<tr>
<td width="25%">
<label id="labelminiserver"><TMPL_VAR SETTINGS.LABEL_MINISERVER></label>
</td>
<td width="50%">
<TMPL_VAR MINISERVER>
</td>
<td width="5%" valign="middle">
&nbsp;
</td>
<td width="20%">
<font size="-1"><TMPL_VAR SETTINGS.HINT_MINISERVER></font>
</td>
</tr>
<tr>
<td width="25%">
<label id="labelsendudp"><TMPL_VAR SETTINGS.LABEL_SENDBYUDP></label>
Expand Down Expand Up @@ -529,34 +558,6 @@ <h2><TMPL_VAR SETTINGS.LABEL_MINISERVERCONNECTION></h2>
<font size="-1"><TMPL_VAR SETTINGS.HINT_HTML></font>
</td>
</tr>

<!-- Patch data with local Miniserver VI's -->

<!--
<tr>
<td width="25%">
<label id="labelquerylocaldata"><TMPL_VAR SETTINGS.LABEL_QUERYLOCALDATA></label>
</td>
<td width="50%">
<table border=0>
<tr><td>
<fieldset>
<select id="querylocaldata" name="querylocaldata" data-role="flipswitch">
<option value="0"><TMPL_VAR SETTINGS.LABEL_OFF></option>
<option selected=selected value="1"><TMPL_VAR SETTINGS.LABEL_ON></option>
</select>
</fieldset>
</td></tr>
</table>
</td>
<td width="5%" valign="middle">
</td>
<td width="20%">
<font size="-1"><TMPL_VAR SETTINGS.HINT_QUERYLOCALDATA></font>
</td>
</tr>
-->

<tr>
<td width="25%">
<label id="labeldfc"><TMPL_VAR SETTINGS.LABEL_DFC></label>
Expand Down
21 changes: 21 additions & 0 deletions webfrontend/htmlauth/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ if ($R::saveformdata1) {
$cfg->param("WEATHERBIT.LANG", "$R::weatherbitlang");
$cfg->param("WEATHERBIT.COUNTRY", "$R::weatherbitcountry");

$cfg->param("SERVER.LOXGRABBER", "$R::loxgrabber");
$cfg->param("SERVER.GETDATA", "$R::getdata");
$cfg->param("SERVER.CRON", "$R::cron");
$cfg->param("SERVER.METRIC", "$R::metric");
Expand Down Expand Up @@ -326,6 +327,7 @@ if ($R::saveformdata2) {
$cfg->param("SERVER.SENDHFC", "$hfc");
$cfg->param("SERVER.SENDUDP", "$R::sendudp");
$cfg->param("SERVER.UDPPORT", "$R::udpport");
$cfg->param("SERVER.MSNO", "$R::msno");

$cfg->save();

Expand Down Expand Up @@ -418,6 +420,21 @@ if ($R::form eq "1" || !$R::form) {
);
$template->param( METRIC => $metric );

# LoxGrabber
@values = ('0', '1' );
%labels = (
'0' => $L{'SETTINGS.LABEL_OFF'},
'1' => $L{'SETTINGS.LABEL_ON'},
);
my $loxgrabber = $cgi->popup_menu(
-name => 'loxgrabber',
-id => 'loxgrabber',
-values => \@values,
-labels => \%labels,
-default => $cfg->param('SERVER.LOXGRABBER'),
);
$template->param( LOXGRABBER => $loxgrabber );

# GetData
@values = ('0', '1' );
%labels = (
Expand Down Expand Up @@ -682,6 +699,10 @@ if ($R::form eq "1" || !$R::form) {
$template->param( "FORM2", 1);
$template->param( "WEBSITE", "http://$ENV{HTTP_HOST}/plugins/$lbpplugindir/weatherdata.html");

# Miniserver
my $mshtml = mslist_select_html( FORMID => 'msno', SELECTED => $cfg->param('SERVER.MSNO', DATA_MINI => 1 );
$template->param( MINISERVER => $mshtml );

# SendUDP
@values = ('0', '1' );
%labels = (
Expand Down

0 comments on commit bc9a8f4

Please sign in to comment.