fix energy display: use electricity field, convert Wh to kWh for portal
This commit is contained in:
parent
0287921b38
commit
72d4a4f82f
@ -179,7 +179,7 @@ $daten = json_decode($inputstream, true);
|
|||||||
if($relayOnTime !== null) $json['relayOnTime'] = $relayOnTime;
|
if($relayOnTime !== null) $json['relayOnTime'] = $relayOnTime;
|
||||||
if($uptime !== null) $json['uptime'] = $uptime;
|
if($uptime !== null) $json['uptime'] = $uptime;
|
||||||
if($loadWatts !== null) $json['loadWatts'] = $loadWatts;
|
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
|
// Handle sequence number - use fCnt from ChirpStack if available
|
||||||
$seqNumber_dev = 1; // Default
|
$seqNumber_dev = 1; // Default
|
||||||
@ -286,6 +286,18 @@ if(isset($daten['deviceName'])) {
|
|||||||
$row = mysqli_fetch_assoc($result2);
|
$row = mysqli_fetch_assoc($result2);
|
||||||
|
|
||||||
if($row && isset($row['id'])) {
|
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
|
$sql3 = "UPDATE last_device_message SET
|
||||||
id = '".$row['id']."',
|
id = '".$row['id']."',
|
||||||
time = '".$row['time']."',
|
time = '".$row['time']."',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user