diff --git a/debug_G2H-RS.php b/debug_G2H-RS.php index f65ff08..61c2df4 100644 --- a/debug_G2H-RS.php +++ b/debug_G2H-RS.php @@ -179,7 +179,7 @@ $daten = json_decode($inputstream, true); if($relayOnTime !== null) $json['relayOnTime'] = $relayOnTime; if($uptime !== null) $json['uptime'] = $uptime; if($loadWatts !== null) $json['loadWatts'] = $loadWatts; - if($powerConsumptionWh !== null) $json['power_consumption'] = $powerConsumptionWh; + if($powerConsumptionWh !== null) $json['electricity'] = round($powerConsumptionWh / 1000, 6); // Handle sequence number - use fCnt from ChirpStack if available $seqNumber_dev = 1; // Default @@ -286,6 +286,18 @@ if(isset($daten['deviceName'])) { $row = mysqli_fetch_assoc($result2); if($row && isset($row['id'])) { + // power_consumption in data_formatted nachträglich eintragen + if($powerConsumptionWh !== null) { + $df = json_decode($row['data_formatted'], true); + if($df !== null) { + $df['electricity'] = round($powerConsumptionWh / 1000, 6); + $newDf = mysqli_real_escape_string($iotconnection, json_encode($df)); + mysqli_query($iotconnection, + "UPDATE device_messages SET data_formatted = '$newDf' WHERE id = '{$row['id']}'"); + $row['data_formatted'] = $newDf; + } + } + $sql3 = "UPDATE last_device_message SET id = '".$row['id']."', time = '".$row['time']."',