www/includes/db_profile_water.php

Thu, 10 Jan 2019 20:22:06 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Jan 2019 20:22:06 +0100
changeset 185
4c25db9e8102
parent 77
a9f8de2d7b2b
child 211
63d0e40c58b9
permissions
-rw-r--r--

Added configuration settings for MQTT in config.php. Finished screen box sizes for the fermenters monitor. Select beername and code from the current brew products and send it to the fermenter. Added switch commands to the fermenter. Delay data get from the fermenter after sending any command so there is time to process the commands. Turn switches off when the mode changes. Removed 0.2 degrees setpoint diffs for low and high, the fermenter must deal with it. Prevent turning the heater and cooler together on.

<?php

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

#Connect to the database
$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );

// get data and store in a json array
$query = "SELECT * FROM profile_water ORDER BY name";
if (isset($_GET['insert'])) {
	// INSERT COMMAND
	$sql  = "INSERT INTO `profile_water` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
	$sql .= "', calcium='" . $_GET['calcium'];
	$sql .= "', bicarbonate='" . $_GET['bicarbonate'];
	$sql .= "', sulfate='" . $_GET['sulfate'];
	$sql .= "', chloride='" . $_GET['chloride'];
	$sql .= "', sodium='" . $_GET['sodium'];
	$sql .= "', magnesium='" . $_GET['magnesium'];
	$sql .= "', ph='" . $_GET['ph'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
	$sql .= "', total_alkalinity='" . $_GET['total_alkalinity'];
	$sql .= "';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_profile_water: inserted ".$_GET['name']);
	}
	echo $result;

} else if (isset($_GET['update'])) {
	// UPDATE COMMAND
	$sql  = "UPDATE `profile_water` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
	$sql .= "', calcium='" . $_GET['calcium'];
	$sql .= "', bicarbonate='" . $_GET['bicarbonate'];
	$sql .= "', sulfate='" . $_GET['sulfate'];
	$sql .= "', chloride='" . $_GET['chloride'];
	$sql .= "', sodium='" . $_GET['sodium'];
	$sql .= "', magnesium='" . $_GET['magnesium'];
	$sql .= "', ph='" . $_GET['ph'];
	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
	$sql .= "', total_alkalinity='" . $_GET['total_alkalinity'];
	$sql .= "' WHERE record='" . $_GET['record'] . "';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_profile_water: updated record ".$_GET['record']);
	}
	echo $result;

} else if (isset($_GET['delete'])) {
	// DELETE COMMAND
	$sql = "DELETE FROM `profile_water` WHERE record='".$_GET['record']."';";
	$result = mysqli_query($connect, $sql);
	if (! $result) {
		syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
	} else {
		syslog(LOG_NOTICE, "db_profile_water: deleted record ".$_GET['record']);
	}
	echo $result;

} else {
	// SELECT COMMAND
	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
		$waters[] = array(
			'record' => $row['record'],
			'name' => $row['name'],
			'calcium' => $row['calcium'],
			'bicarbonate' => $row['bicarbonate'],
			'sulfate' => $row['sulfate'],
			'chloride' => $row['chloride'],
			'sodium' => $row['sodium'],
			'magnesium' => $row['magnesium'],
			'ph' => $row['ph'],
			'notes' => $row['notes'],
			'total_alkalinity' => $row['total_alkalinity']
		);
	}
	echo json_encode($waters);
}
?>

mercurial