www/ispindel/index.php

Sun, 23 May 2021 16:41:35 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 May 2021 16:41:35 +0200
changeset 752
f68e3bbc1ada
parent 585
fa6e702d0d24
child 847
dc9281501ca6
permissions
-rw-r--r--

Fermentables, hops, miscs and yeast now have tests against the added moment with the brewing stage. Added to inventory edit rows, delete rows, and pick choices for the moment to add or edit. Some more popups to explain certain blocks.

<?php

require($_SERVER['DOCUMENT_ROOT']."/config.php");

if ($_SERVER['HTTP_USER_AGENT'] == 'ESP8266HTTPClient') {
	//            /usr/bin/mosquitto_pub -h host] [-p port] [-u username [-P password]] -t topic -m message
	$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 );
	$node = 'ispindel-' . sprintf("%06x", floatval($data['ID']));

	$alarm = 0;
	$interval = $data['interval'];
        if (floatval($data['battery']) < 3.3) {
                $alarm += 4;
		if (($interval * 3) < 3600)
			$interval = 3600; // at least 3600 seconds when the battery is low.
		else
			$interval = $interval * 3;
	}

	$uuid = 'c0ffeeee-cafe-dead-beef-' . sprintf("%06x", 0xffffff - floatval($data['ID'])) . sprintf("%06x", floatval($data['ID']));
	$topic = 'mbv1.0/ispindels/NBIRTH/' . $node;
	$payload  = '{"metric":{"uuid":"' . $uuid . '","interval":' . $interval . ',';
	$payload .= '"properties":{"hardwaremake":"Wemos","hardwaremodel":"D1 mini","os":"Unknown","os_version":"Unknown","FW":"Unknown"},';
	$payload .= '"net":{"address":"' . $_SERVER['REMOTE_ADDR'] . '","ifname":"sta","rssi":' . $data['RSSI'] . '}}}';
	$pub = $publisher . $topic . ' -m \'' . $payload . '\'';
	exec($pub);

	$alarm = 0;
	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'] . '}}';
	$pub = $publisher . $topic . ' -m \'' .$payload . '\'';
	exec($pub);
}

?>

mercurial