Skip to content

Commit

Permalink
Fallback
Browse files Browse the repository at this point in the history
Anpassungen mussten Rückgängig gemacht werden - Multi-Diagramme nicht möglich
  • Loading branch information
christian1180 committed Nov 24, 2024
1 parent 22d9fbe commit dcdc2f8
Show file tree
Hide file tree
Showing 5 changed files with 810 additions and 405 deletions.
50 changes: 32 additions & 18 deletions diagramm_collect.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php

// Eintrag in Crontab
//
// Sofern kein PHP-CLI zur Verfügung steht:
// */1 * * * * curl --silent http://localhost/homehub/diagramm_collect.php >/dev/null 2>&1
//
// mit PHP-CLI
// */1 * * * * /usr/bin/php -f /pfad-zu-homehub/diagramm_collect.php >/dev/null 2>&1

include("config/config.php");

require_once(__DIR__.'/interface.php');

// interface Pfad bestimmen
$interface = $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].str_replace("diagramm_collect.php", "",$_SERVER['PHP_SELF']);
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$interface = "https://".$interface;
}
else $interface = "http://".$interface;
echo $interface;

date_default_timezone_set("Europe/Berlin");
$tage = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa");


// Lese aus custom.json die diagramm ise_id welche geloggt werden sollen
$data = file_get_contents(__DIR__.'/config/custom.json');
$data = file_get_contents('config/custom.json');
$json = json_decode($data, true);


Expand Down Expand Up @@ -112,7 +113,9 @@
$historyZaehler = 0;

// Abfrage an die CCU
$xml = simplexml_load_string(api_state($ccu, $diagramm_change, true));
$xmlFile = $interface.'interface.php?state.cgi&onlyvalue=1&datapoint_id='.$diagramm_change;
echo $xmlFile;
$xml = simplexml_load_file($xmlFile);
echo $xml;
foreach ( $xml->datapoint as $states )
{
Expand All @@ -128,10 +131,10 @@
$states['value'] = $x[0].'.'.substr($x[1],0,1);
}

if(file_exists(__DIR__."/cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv"))
if(file_exists("cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv"))
{
// Lese Datei in Array
$lines = file(__DIR__."/cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv");
$lines = file("cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv");

// Sortiere alte Einträge aus
if(count((array)$lines)>= $history[$historyZaehler])
Expand Down Expand Up @@ -162,7 +165,7 @@
{
// Schreiben
$inhalt = $inhalt.$tage[date("w")]." ".date("H:i",time()).";".$states['value']."\n";
$file_handle = fopen(__DIR__."/cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
$file_handle = fopen("cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
fwrite($file_handle, $inhalt);
fclose($file_handle);
}
Expand All @@ -175,7 +178,7 @@
{
// Schreiben
$inhalt = $inhalt.$tage[date("w")]." ".date("H:i",time()).";".$states['value']."\n";
$file_handle = fopen(__DIR__."/cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
$file_handle = fopen("cache/diagramm_change_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
fwrite($file_handle, $inhalt);
fclose($file_handle);
}
Expand All @@ -192,8 +195,10 @@
$historyZaehler = 0;

// Abfrage an die CCU
$xml = simplexml_load_string(api_state($ccu, $diagramm, true));
echo $xml;
$xmlFile = $interface.'/interface.php?state.cgi&onlyvalue=1&datapoint_id='.$diagramm;
echo $xmlFile;
$xml = simplexml_load_file($xmlFile);
echo $xml;
foreach ($xml->datapoint as $states)
{
$inhalt = "";
Expand All @@ -220,10 +225,10 @@



if(file_exists(__DIR__."/cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv"))
if(file_exists("cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv"))
{
// Lese Datei in Array
$lines = file(__DIR__."/cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv");
$lines = file("cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv");

// Sortiere alte Einträge aus
if(count((array)$lines)>= $history[$historyZaehler])
Expand Down Expand Up @@ -251,12 +256,21 @@
{
$inhalt = $inhalt.date("H:i",time()).";".$states['value']."\n";
}
$file_handle = fopen(__DIR__."/cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
$file_handle = fopen("cache/diagramm_".$states['ise_id']."_".$history[$historyZaehler].".csv", 'w+');
fwrite($file_handle, $inhalt);
fclose($file_handle);
$historyZaehler++;
}
}
echo "Ende";

function curl_get_content( $url ) {
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl_handle);
curl_close($curl_handle);
return $content;
}
?>
51 changes: 40 additions & 11 deletions import.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?php

$exportFile = 'config/export.json';

ini_set('display_errors', 'on');
$beginn = microtime(true);

require_once(__DIR__.'/interface.php');
$exportFile = 'config/export.json';

// Lösche vorhandene export.json
if(file_exists($exportFile))
Expand All @@ -14,12 +10,33 @@
}
touch($exportFile);

$export = array();

// Wenn Konfiguration nicht existiert wechsele zum Setup
if(!file_exists("config/config.php"))
{
header('Location: setup.php');
exit;
}
else
{
// Lade Konfiuration der Homematic
require("config/config.php");
}

$export = array();
$interface = $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].str_replace("import.php", "",$_SERVER['PHP_SELF']);
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$interface = "https://".$interface;
}
else $interface = "http://".$interface;

// Devices und Channels von der CCU laden
$devicesXml = simplexml_load_string(api_devicelist($ccu));
$statesXml = simplexml_load_string(api_statelist($ccu));
$devicelistCgi = curl_get_content($interface.'/interface.php?devicelist.cgi');
$devicesXml = simplexml_load_string($devicelistCgi);

$statelistCgi = curl_get_content($interface.'/interface.php?statelist.cgi');
$statesXml = simplexml_load_string($statelistCgi);



// Devices
Expand Down Expand Up @@ -131,7 +148,8 @@
unset($statesXml);

// Systemvariablen von der CCU laden
$sysvarsXml = simplexml_load_string(api_sysvarlist($ccu));
$sysvarlistCgi = curl_get_content($interface.'/interface.php?sysvarlist.cgi');
$sysvarsXml = simplexml_load_string($sysvarlistCgi);

// Systemvariablen
foreach ($sysvarsXml->systemVariable as $sysvar) {
Expand All @@ -149,7 +167,8 @@
unset($sysvarsXml);

// Programme von der CCU laden
$programsXml = simplexml_load_string(api_programlist($ccu));
$programlistCgi = curl_get_content($interface.'/interface.php?programlist.cgi');
$programsXml = simplexml_load_string($programlistCgi);

// Programme
foreach ($programsXml->program as $program) {
Expand Down Expand Up @@ -187,7 +206,17 @@
}
else
{
header('Location: ./index.php');
header('Location: index.php');
}

function curl_get_content( $url ) {
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl_handle);
curl_close($curl_handle);
return $content;
}
?>

19 changes: 17 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@

}

// definiere Interface
$interface = $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].str_replace("index.php", "",$_SERVER['PHP_SELF']);
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$interface = "https://".$interface;
}
else $interface = "http://".$interface;

// Prüfe auf config.php
if(!file_exists("config/config.php"))
{
header('Location: setup.php');
exit;
}

// Lade Konfiuration der Homematic
require_once(__DIR__.'/interface.php');
require("config/config.php");

// Setze Variable selectedCat auf die aktuelle Seite
if(!isset($_GET['seite']))
Expand Down Expand Up @@ -422,7 +436,8 @@
$str = file_get_contents('dev/export.json');
} else {

$xml = simplexml_load_string(api_systemNotification($ccu));
//$xml = simplexml_load_file('http://'.$homematicIp.'/config/xmlapi/systemNotification.cgi?sid='.$apitoken);
$xml = simplexml_load_file($interface.'interface.php?systemNotification.cgi');
$str = file_get_contents('config/export.json');
}
// Für Devices
Expand Down
Loading

0 comments on commit dcdc2f8

Please sign in to comment.