Example #1
0
 private function SetValueFloat($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueFloat($id) != $value) {
         SetValueFloat($id, $value);
         return true;
     }
     return false;
 }
Example #2
0
 protected function SetValueFloat($Ident, $Value)
 {
     $ID = $this->GetIDForIdent($Ident);
     if (GetValueFloat($ID) != $Value) {
         SetValueFloat($ID, intval($Value));
         return true;
     }
     return false;
 }
Example #3
0
function SetVariable($VarID, $Type, $Value)
{
    switch ($Type) {
        case 0:
            // boolean
            SetValueBoolean($VarID, $Value);
            break;
        case 1:
            // integer
            SetValueInteger($VarID, $Value);
            break;
        case 2:
            // float
            SetValueFloat($VarID, $Value);
            break;
        case 3:
            // string
            SetValueString($VarID, $Value);
            break;
    }
}
Example #4
0
 private function UpdateVariable(ISCP_API_Data $APIData)
 {
     if ($APIData->Data == "N/A") {
         return;
     }
     switch ($APIData->Mapping->VarType) {
         case IPSVarType::vtBoolean:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = ISCP_API_Commands::$BoolValueMapping[$APIData->Data];
             SetValueBoolean($VarID, $Value);
             break;
         case IPSVarType::vtFloat:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData / 100;
             SetValueFloat($VarID, $Value);
             //                throw new Exception("Float VarType not implemented.");
             break;
         case IPSVarType::vtInteger:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = hexdec($APIData->Data);
             SetValueInteger($VarID, $Value);
             break;
         case IPSVarType::vtString:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData->Data;
             SetValueString($VarID, $Value);
             break;
         case IPSVarType::vtDualInteger:
             $Prefix = substr($APIData->Data, 0, 1);
             $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 1, 2)];
             SetValueInteger($VarID, $Value);
             if (strlen($APIData->Data) > 3) {
                 $Prefix = substr($APIData->Data, 3, 1);
                 $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
                 $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 4, 2)];
                 SetValueInteger($VarID, $Value);
             }
     }
 }
 /**
  * parsing incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $caps = $this->GetCaps();
     //$this->debug(__FUNCTION__,print_r($this->all_caps,true));
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         switch ($cap) {
             //Integer
             case 'Hum':
                 //hum
             //hum
             case 'RainCounter':
                 //raincounter
             //raincounter
             case 'Press':
                 //pressure
             //pressure
             case 'Forecast':
                 //willi
             //willi
             case 'UV':
                 //UVIndex
             //UVIndex
             case 'Light':
                 //Brightness
             //Brightness
             case 'Level':
                 //level
             //level
             case 'TS':
                 //TimeStamp
             //TimeStamp
             case 'Lost':
                 //lost
             //lost
             case 'Signal':
                 if (strlen($s) == 0) {
                     continue;
                 }
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //float
             //float
             case 'Temp':
                 //temp
             //temp
             case 'Wind':
                 //wind
             //wind
             case 'WindChill':
                 //wind
             //wind
             case 'WindGust':
                 //wind
             //wind
             case 'WindDir':
                 //wind
             //wind
             case 'Rain':
                 //rain
             //rain
             case 'RainDaily':
                 //rain this day
             //rain this day
             case 'RainHourly':
                 //rain 1h
             //rain 1h
             case 'RainLastDay':
                 //rain 24h
                 if (strlen($s) == 0) {
                     continue;
                 }
                 $fv = (double) $s;
                 SetValueFloat($vid, $fv);
                 break;
                 //String
             //String
             case 'Name':
                 //
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
                 //special
             //special
             case 'IsRaining':
                 //israining
                 if ($s == 'YES') {
                     SetValueBoolean($vid, true);
                     $s = "Its Raining";
                 } else {
                     SetValueBoolean($vid, false);
                     $s = "{$cap}({$vid}): No Rain";
                 }
                 break;
                 //special
             //special
             case 'Storm':
                 //israining
                 if ($s == 'YES') {
                     //is reversed
                     SetValueBoolean($vid, false);
                     $s = "Its Storm";
                 } else {
                     SetValueBoolean($vid, true);
                     $s = "OK";
                 }
                 break;
             case 'Battery':
                 //battery
                 $state = !preg_match("/LOW|WARN/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s);
     }
 }
Example #6
0
 private function DecodeIOSample(TXB_API_IO_Sample $IOSample)
 {
     $ActiveDPins = unpack("n", substr($IOSample->Sample, 1, 2))[1];
     $ActiveAPins = ord($IOSample->Sample[3]);
     if ($ActiveDPins != 0) {
         $PinValue = unpack("n", substr($IOSample->Sample, 4, 2))[1];
         foreach ($this->DPin_Name as $Index => $Pin_Name) {
             if ($Pin_Name == '') {
                 continue;
             }
             $Bit = pow(2, $Index);
             if (($ActiveDPins & $Bit) == $Bit) {
                 //                        {$IFDEF DEBUG}        SendData('DPIN','I:'+floattostr(Power(2,ord(i))));{$ENDIF}
                 $VarID = @$this->GetIDForIdent($Pin_Name);
                 if ($VarID === false) {
                     $VarID = $this->RegisterVariableBoolean($Pin_Name, $Pin_Name);
                 }
                 if (($PinValue & $Bit) == $Bit) {
                     //                            {$IFDEF DEBUG}          SendData(DPin_Name[i],'true - Bit:'+inttostr(ord(i)));{$ENDIF}
                     SetValueBoolean($VarID, true);
                 } else {
                     //                            {$IFDEF DEBUG}          SendData(DPin_Name[i],'false - Bit:'+inttostr(ord(i)));{$ENDIF}
                     SetValueBoolean($VarID, false);
                 }
             }
         }
     }
     if ($ActiveAPins != 0) {
         $i = 0;
         foreach ($this->APin_Name as $Index => $Pin_Name) {
             if ($Pin_Name == "") {
                 continue;
             }
             $Bit = pow(2, $Index);
             if (($ActiveAPins & $Bit) == $Bit) {
                 //                    {$IFDEF DEBUG}        SendData('APIN','I:'+floattostr(Power(2,ord(i))));{$ENDIF}
                 $PinAValue = 0;
                 $PinAValue = unpack("n", substr($IOSample->Sample, 6 + $i * 2, 2))[1];
                 $PinAValue = $PinAValue * 1.171875;
                 if ($Pin_Name == 'VSS') {
                     $VarID = @$this->GetIDForIdent($Pin_Name);
                     if ($VarID === false) {
                         $VarID = $this->RegisterVariableFloat('VSS', 'VSS', '~Volt');
                     }
                     SetValueFloat($VarID, $PinAValue / 1000);
                 } else {
                     $VarID = @$this->GetIDForIdent($Pin_Name);
                     if ($VarID === false) {
                         $VarID = $this->RegisterVariableInteger($Pin_Name, $Pin_Name);
                     }
                     SetValueInteger($VarID, $PinAValue);
                 }
                 $i++;
             }
         }
     }
 }
Example #7
0
 public function SetVolume($volume)
 {
     if ($volume < -80) {
         $volume = -80;
     }
     if ($volume > 16) {
         $volume = -20;
     }
     // dont use maximum 16 - if wrong parameter it will not be to loud
     SetValueFloat($this->GetIDForIdent('VOLUME'), $volume);
     $volume = $volume * 10;
     return $this->Request("<Volume><Lvl><Val>{$volume}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume>", 'PUT');
 }
Example #8
0
 private function SetValueFloat($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueFloat($id) != $value) {
         SetValueFloat($id, $value);
     }
 }
Example #9
0
 protected function DoGewicht($ModulID, $data)
 {
     $gewichtdatum = false;
     $gewicht = 0;
     $fettfrei = 0;
     $fettanteil = 0;
     $fettprozent = 0;
     $bmi = 0;
     $groesse = 0;
     $puls = 0;
     $this->Logging("Gewichtsdaten werden ausgewertet.");
     $id = @IPS_GetVariableIDByName("Groesse", $ModulID);
     if ($id > 0) {
         $groesse = GetValueInteger($id);
     }
     $CatID = @IPS_GetCategoryIDByName("Waage", $ModulID);
     if ($CatID === false) {
         $this->Logging("CatID ist auf FALSE!");
         return;
     }
     $data = $data['measuregrps'];
     $time = @$data[0]['date'];
     $this->Logging("Zeitstempel der Daten : " . date('d.m.Y H:i:s', $time));
     $this->Logging("Anzahl der Messgruppen : " . count($data));
     foreach ($data as $d) {
         $daten = $d['measures'];
         $this->Logging("Anzahl der Messungen : " . count($daten));
         $id = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID);
         if ($id > 0) {
             $old = GetValueInteger($id);
             if ($old == $time) {
                 $this->Logging("Keine neuen Daten : " . date('d.m.Y H:i:s', $old));
                 //return false;
             }
             SetValueInteger($id, $time);
         }
         foreach ($daten as $messung) {
             $val = floatval($messung['value']) * floatval("1e" . $messung['unit']);
             $this->Logging("Messung Type : " . $messung['type'] . " : " . $val);
             if ($messung['type'] == 1 and $gewicht == 0) {
                 $gewicht = round($val, 2);
             }
             if ($messung['type'] == 5 and $fettfrei == 0) {
                 $fettfrei = round($val, 2);
             }
             if ($messung['type'] == 6 and $fettprozent == 0) {
                 $fettprozent = round($val, 2);
             }
             if ($messung['type'] == 8 and $fettanteil == 0) {
                 $fettanteil = round($val, 2);
             }
             if ($messung['type'] == 11 and $puls == 0) {
                 $puls = round($val, 2);
             }
         }
     }
     $bmi = round($gewicht / ($groesse / 100 * ($groesse / 100)), 2);
     $id = IPS_GetVariableIDByName("Gewicht", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $gewicht);
     }
     $id = IPS_GetVariableIDByName("Fett Anteil", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettanteil);
     }
     $id = IPS_GetVariableIDByName("Fettfrei Anteil", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettfrei);
     }
     $id = IPS_GetVariableIDByName("Fett Prozent", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettprozent);
     }
     $id = IPS_GetVariableIDByName("BMI", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $bmi);
     }
     $id = @IPS_GetVariableIDByName("Puls", $CatID);
     if ($id > 0) {
         SetValueInteger($id, $puls);
     }
 }
 /**
  * handle incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $this->debug(__FUNCTION__, 'Parse');
     $caps = $this->GetCaps();
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         $this->debug(__FUNCTION__, "Handle {$cap} ({$vid}) = {$s}");
         switch ($cap) {
             //boolean types
             case 'Alert':
                 //Status
                 $state = $s != 'YES';
                 //reversed display
                 SetValueBoolean($vid, $state);
                 break;
                 //Counter types with factor
             //Counter types with factor
             case 'Counter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $last = GetValueInteger($vid);
                         $opid = $this->GetIDForIdent('OCounter');
                         if ($opid) {
                             $offset = GetValueInteger($opid);
                             if ($last > $iv) {
                                 $offset += 65535;
                                 $this->debug(__FUNCTION__, "EMWZ:Increase Offset by 65535: {$offset}");
                                 SetValueInteger($opid, $offset);
                             }
                             $iv = $iv + $offset;
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for OCounter");
                         }
                         $pvid = $this->GetIDForIdent('TPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor);
                             //counter%ticks pro kw
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for TPower");
                         }
                         break;
                     case 'EMEM':
                         $last = GetValueInteger($vid);
                         $opid = $this->GetIDForIdent('OCounter');
                         if ($opid) {
                             $offset = GetValueInteger($opid);
                             if ($last > $iv) {
                                 $offset += 65535;
                                 $this->debug(__FUNCTION__, "EMEM:Increase Offset by 65535: {$offset}");
                                 SetValueInteger($opid, $offset);
                             }
                             $iv = $iv + $offset;
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for OCounter");
                         }
                         $pvid = $this->GetIDForIdent('TPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //counter%ticks pro kw
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for TPower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('TGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //Counter%ticks pro m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:TGas:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for TGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
             case 'ACounter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $pvid = $this->GetIDForIdent('APower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for APower");
                         }
                         break;
                     case 'EMEM':
                         $pvid = $this->GetIDForIdent('APower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for APower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('AGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:AGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for AGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
             case 'PCounter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $pvid = $this->GetIDForIdent('PPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:PPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for PPower");
                         }
                         break;
                     case 'EMEM':
                         $pvid = $this->GetIDForIdent('PPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:PPower:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for PPower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('PGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:PGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for PGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
                 //int types
             //int types
             case 'Signal':
                 //RSSI
             //RSSI
             case 'LoadPct':
                 //Load in Pct
             //Load in Pct
             case 'Charged':
                 //Charged in Pct
             //Charged in Pct
             case 'OCounter':
                 //old counter
             //old counter
             case 'TS':
                 //Timestamp
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //float types with factor
             //float types with factor
             case 'AGas':
                 //Actual
             //Actual
             case 'TGas':
                 //Total
             //Total
             case 'PGas':
                 //Peak
             //Peak
             case 'APower':
                 //Actual
             //Actual
             case 'PPower':
                 //Peak
             //Peak
             case 'TPower':
                 //Total
             //Total
             case 'AWater':
                 //Actual
             //Actual
             case 'TWater':
                 //Total
             //Total
             case 'PWater':
                 //Peak
                 $fv = (double) $s;
                 $factor = $this->GetCounterFactor();
                 $val = $fv * $factor;
                 SetValueFloat($vid, $val);
                 break;
                 //float types
             //float types
             case 'VoltIn':
                 //InputVolt
             //InputVolt
             case 'VoltOut':
                 //Output Volt
             //Output Volt
             case 'Nominal':
                 //Nominal Power
             //Nominal Power
             case 'Watt':
                 //Absolute Load
             //Absolute Load
             case 'Freq':
                 //Frequency
             //Frequency
             case 'TimeLeft':
                 //TimeLeft
                 $fv = (double) $s;
                 SetValueFloat($vid, $fv);
                 break;
                 //string types
             //string types
             case 'Name':
             case 'Status':
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         //switch
         $this->debug(__FUNCTION__, "{$cap}:({$vid})=" . $s);
     }
     //for
 }
 protected function DoGewicht($ModulID, $data)
 {
     $gewichtdatum = false;
     $gewicht = 0;
     $fettfrei = 0;
     $fettanteil = 0;
     $fettprozent = 0;
     $bmi = 0;
     $groesse = 0;
     $id = @IPS_GetVariableIDByName("Groesse", $ModulID);
     if ($id > 0) {
         $groesse = GetValueInteger($id);
     }
     $CatID = @IPS_GetCategoryIDByName("Waage", $ModulID);
     if ($CatID === false) {
         return;
     }
     $time = @$data['measuregrps'][0]['date'];
     $data = @$data['measuregrps'][0]['measures'];
     if (count($data) != 4) {
         $this->Logging("Fehler bei DoGewicht " . count($data));
         //return;
     }
     $id = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID);
     if ($id > 0) {
         $old = GetValueInteger($id);
         if ($old == $time) {
             // keine neue Daten
             return false;
         }
         SetValueInteger($id, $time);
     }
     foreach ($data as $messung) {
         $val = floatval($messung['value']) * floatval("1e" . $messung['unit']);
         if ($messung['type'] == 1) {
             $gewicht = round($val, 2);
         }
         if ($messung['type'] == 5) {
             $fettfrei = round($val, 2);
         }
         if ($messung['type'] == 6) {
             $fettprozent = round($val, 2);
         }
         if ($messung['type'] == 8) {
             $fettanteil = round($val, 2);
         }
     }
     $bmi = round($gewicht / ($groesse / 100 * ($groesse / 100)), 2);
     $id = IPS_GetVariableIDByName("Gewicht", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $gewicht);
     }
     $id = IPS_GetVariableIDByName("Fett Anteil", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettanteil);
     }
     $id = IPS_GetVariableIDByName("Fettfrei Anteil", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettfrei);
     }
     $id = IPS_GetVariableIDByName("Fett Prozent", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $fettprozent);
     }
     $id = IPS_GetVariableIDByName("BMI", $CatID);
     if ($id > 0) {
         SetValueFloat($id, $bmi);
     }
 }
    public function ReceiveData($JSONString)
    {                                                                    // *************** Daten zusammen tragen ************
           $data = json_decode($JSONString);
           $BufferID = $this->GetIDForIdent("BufferIN");
           $DatasetID = $this->GetIDForIdent("Dataset");
           $SensorenID = $this->GetIDForIdent("Sensoren");
           $Head = GetValueString($BufferID);                            // holt sich die gespeicherten Restdaten aus der Variablen
           $dazu = utf8_decode($data->Buffer);                           // holen des neuen
           $all = $Head.$dazu;                                           // setzt alle zusammen
                                                                         // *************** Datensatz separieren *************
           $Startsequenz = chr(0x0D).chr(0x0A).chr(0x0D).chr(0x0A);      // damit fängt der Datensatz an
           $Datasets = explode ($Startsequenz, $all);                    // Nun zerlegen wir den Senf und basteln ein Array
           $AnzahlDatasets = count ($Datasets);
           if ($AnzahlDatasets > 1)                                      // checkt ob ein vollständiger da ist
           {
           SetValueString($BufferID, $Datasets[1]);                      // schreibt die Reste wieder zurück
           SetValueString($DatasetID, $Datasets[0]);                     // schreibt vollständigen Datensatz in Dataset, kann später wieder raus
           // ab hier zerlegen wir das Dataset 0                         // *************** Datensatz verarbeiten ************
           $AnzahlSensoren = substr_count($Datasets[0], 'ROM');          // hier zählen wir wieviele Sensoren vorhanden sind
           SetValueInteger($SensorenID, $AnzahlSensoren);                // und füllen damit die Variable

           $Sensoren = $Datasets[0];

           $Startsequenz1 = "ROM = ";                                    // damit fängt der Datensatz an
           $Ende1nachZeichen = 21;                                       // und ist xx Zeichen lang
           $Sensordaten[0] = explode ($Startsequenz1, $Sensoren);
            $SensorkorrROM = "Hardware ID des 1-W Bausteines";
            $Sensordaten[0][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[0][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende1nachZeichen);
            $Sensordaten[0][3] = $SensorkorrROM;
           SetValueString($this->GetIDForIdent("Sensor1_ROM"), $Sensordaten[0][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor2_ROM"), $Sensordaten[0][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor3_ROM"), $Sensordaten[0][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array

           $Startsequenz2 = "Chip = ";                                    // damit fängt der Datensatz an
           $Ende2nachZeichen = 8;                                         // und ist xx Zeichen lang
           $Sensordaten[1] = explode ($Startsequenz2, $Sensoren);
            $SensorkorrROM = "Typ des 1-W Bausteines";
            $Sensordaten[1][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[1][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende2nachZeichen);
            $Sensordaten[1][3] = $SensorkorrROM;
           SetValueString($this->GetIDForIdent("Sensor1_Typ"), $Sensordaten[1][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor2_Typ"), $Sensordaten[1][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueString($this->GetIDForIdent("Sensor3_Typ"), $Sensordaten[1][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array

           $Startsequenz3 = "Temperature = ";                              // damit fängt der Datensatz an
           $Ende3nachZeichen = 5;                                          // und ist xx Zeichen lang
           $Sensordaten[2] = explode ($Startsequenz3, $Sensoren);
            $SensorkorrROM = "Temperatur des 1-W Bausteines in Celsius";
            $Sensordaten[2][0] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][1];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][1] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][2];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][2] = $SensorkorrROM;
            $SensorkorrROM = $Sensordaten[2][3];
            $SensorkorrROM = substr($SensorkorrROM, 0, $Ende3nachZeichen);
            $Sensordaten[2][3] = $SensorkorrROM;
           SetValueFloat($this->GetIDForIdent("Sensor1_Temp"), $Sensordaten[2][1]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueFloat($this->GetIDForIdent("Sensor2_Temp"), $Sensordaten[2][2]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           SetValueFloat($this->GetIDForIdent("Sensor3_Temp"), $Sensordaten[2][3]);  // und füllen damit die Variable, und dann Befüllen aus dem Array
           }
           else
           {
           SetValueString($BufferID, $all);                              // schreibt alles wieder zurück, weil es noch nicht vollständig war
           }
    }