The Register Variable is trowing data properly (see example) and I am able to read it. How to adapt the data so I am able to put the data in the created variables?
<?
// wenn das Skript von einer RegisterVariable-Instanz aus aufgerufen worden ist
if ($_IPS['SENDER'] == "RegisterVariable") {
// bereits im Puffer der Instanz vorhandene Daten in $data kopieren
$data = RegVar_GetBuffer($_IPS['INSTANCE']);
// neu empfangene Daten an $data anhängen
$data .= $_IPS['VALUE'];
// $data2 .= $_IPS['VALUE'];
// QUESTION IS THIS A STRING OR A ARRAY ( I THINK STRING)
// echo "test123";
// echo $_IPS['SENDER'];
// $lines = explode(")", $data);
$liness = preg_split('/\r\n|\r|\n/', $data);
if (in_array("1-0:1.8.2", $liness))
{
echo "Match found";
}
// echo $lines[0]; // piece1
// echo $lines[1]; // piece2
// echo $lines; // piece1
// print_r($liness);
// var_dump(substr( $data, 2));
// var_dump(substr( $data, 2));
// var_dump($liness["1-0:1.7.0"]);
/// tester
// SetValue(11690 /*[Energie\Momentanverbrauch]*/ , $data);
////
// $data = explode(",", $_IPS['VALUE']);
// SetValue(12345, $data2[0]);
// SetValue(11690, $data[3]);
// if str_starts_with($data, "0-1") {
// echo "BINGO" }
if (substr($data, 0, 10) == "0-1:24.2.1") // Zählerstand gas
{
$ar = explode(")(",$data);
SetValueFloat(55015 /*[Energie\Momentanverbrauch]*/ , floatval($ar[1]));
}
<?
// if the script was called from a RegisterVariable instance
if ($_IPS['SENDER'] == "RegisterVariable") {
// Copy data already in the instances buffer to data
$data = RegVar_GetBuffer($_IPS['INSTANCE']);
// Append newly received data to data
$data .= $_IPS['VALUE'];
// split Lines from RegisterVariable
$liness = preg_split('/\r\n|\r|\n/', $data);
// print_r($liness);
// Set identifier to the specific ObjectIDs
IPS_SetIdent(44599, "1-0:72.7.0");
IPS_SetIdent(59046, "0-0:96.14.0");
//later: continue IPS_SetIdent for every variable
foreach($liness as $k => $v);
$id = IPS_GetObjectIDByIdent($parentCategoryID, $k);
SetValue($id, $v);
}
Looking at the debug of the RegisterVariable and documentation. I updated the script (to wrap data correctly and prevent broken lines etc. ) Data is now grouping and buffering the way I want.
// if the script was called from a RegisterVariable instance
if ($_IPS['SENDER'] == "RegisterVariable") {
// Copy data already in the instances buffer to data
$buf = RegVar_GetBuffer($_IPS['INSTANCE']);
// Append newly received data to $data
$buf .= $_IPS['VALUE'];
// Write back remaining buffer > solution for broken datalines received. // ONLY OLD DATA IS SHOWN WHEN THIS IS WRONG
RegVar_SetBuffer($_IPS['INSTANCE'], $buf);
// split to array
$lines = preg_split('/\r\n|\r|\n/', $buf);
Every batch of data starts with /ISK5\2M550T-1013 - followed by all information line by line.
1-0:1.8.1(000044.676kWh)
1-0:1.8.2(000046.373kWh)
1-0:2.8.1(000123.223kWh)
1-0:2.8.2(000319.614kWh)
0-0:96.14.0(0001)
etc etc.
I now am to trying to use the an easy filter to obtain the data.
$meterstandelectra = array_filter($lines, function($key) {
return strpos($key, '1-0:1.8.1') === 0; // strpos = first positions in the key are en is strictly true ( === 0)
}, ARRAY_FILTER_USE_BOTH);
// $latest = end($meterstandelectra);
echo $meterstandelectra;
or filter bu string position
if (strpos($buf, ‚0-0:1.0.0‘) === 0)
{
// $data in durch = separierte Datensätze zerlegen
$datasets = explode(‚)‘, $lines);
// $data auf den Inhalt des letzten (unvollständigen) Datensatzes setzen
$buf = $datasets[count($datasets) - 1];
echo „JAJASJ“;
// print_r( $datasets);
}
challenge is still to last is to clear the buffer (I get error messages because of the buffer size)