diff -r d8ace3fa9ac7 -r dc9281501ca6 www/ispindel/index.php --- a/www/ispindel/index.php Sun Mar 05 12:44:33 2023 +0100 +++ b/www/ispindel/index.php Sat Aug 19 15:11:35 2023 +0200 @@ -7,8 +7,21 @@ $publisher = '/usr/bin/mosquitto_pub -h '.MQTT_HOST.' -t '; $input = file_get_contents('php://input'); - //syslog(LOG_NOTICE, "ispindel " . $input); $data = json_decode($input, true ); + + if ($data['temp_units'] == 'K') { + $tempC = floatval($data['temperature']) - 273.15; + } else if ($data['temp_units'] == 'F') { + $tempC = floatval($data['temperature']) / 1.8 - 32; + } else { + $tempC = floatval($data['temperature']); + } + + /* The rounding in the tilt using less digits results in a 0.25 plato difference. Calculate here again using the calibration data. */ + $tilt = $data['angle']; + $plato = (0.00028548 * $tilt * $tilt * $tilt) + (-0.03492272 * $tilt * $tilt) + (1.617106176 * $tilt) + -21.412976092; + syslog(LOG_NOTICE, "ispindel " . $input . " plato ".$plato); + $node = 'ispindel-' . sprintf("%06x", floatval($data['ID'])); $alarm = 0; @@ -33,18 +46,10 @@ if (floatval($data['battery']) < 3.3) $alarm += 4; - if ($data['temp_units'] == 'K') { - $tempC = floatval($data['temperature']) - 273.15; - } else if ($data['temp_units'] == 'F') { - $tempC = floatval($data['temperature']) / 1.8 - 32; - } else { - $tempC = floatval($data['temperature']); - } - $uuid = 'c0ffeeee-cafe-dead-bee0-' . sprintf("%06x", 0xffffff - floatval($data['ID'])) . sprintf("%06x", floatval($data['ID'])); $topic = 'mbv1.0/ispindels/DBIRTH/' . $node; $payload = '{"unit":{"uuid":"' . $uuid .'","alias":"' . $data['name'] . '","alarm":' . $alarm . ',"interval":' . $interval; - $payload .= ',"angle":' . $data['angle'] . ',"temperature":' . $tempC . ',"battery":' . $data['battery'] . ',"gravity":' . $data['gravity'] . '}}'; + $payload .= ',"angle":' . $data['angle'] . ',"temperature":' . $tempC . ',"battery":' . $data['battery'] . ',"gravity":' . $plato . '}}'; $pub = $publisher . $topic . ' -m \'' .$payload . '\''; exec($pub); }