Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp Reading to file in functions #1

Open
the-butterfry opened this issue May 4, 2019 · 0 comments
Open

Temp Reading to file in functions #1

the-butterfry opened this issue May 4, 2019 · 0 comments
Assignees

Comments

@the-butterfry
Copy link
Contributor

the-butterfry commented May 4, 2019

The original functions.php had a statement which set the temperature to 9999 if it couldn't read a sensor value (ie: sensor drops off network/disconnects). When I modified the way sensors were read into file, I broke that.

The problem is this:
Since temps are read once a minute from cron, and if a sensor goes rouge while the temp is being read, it will come back as 0 degrees in the file. This triggers the automatic heating function to turn everything on and heat the tub from a false reading. We need to get the else statement working again so it won't kick on the heater and pump. If the (tub) temp is set to 9999 it won't ever turn on because it's value is above any set temp.
Here's the code as it exists now.

function GetTemp($address)
{
global $m_connect;
$sql = "SELECT * FROM sensors WHERE address='$address' LIMIT 1";
$query = mysqli_query($m_connect,$sql);
$sensor = mysqli_fetch_assoc($query);

//File to read
$file = '/var/log/sensors/'.$address.'/sonoff_th';
if (file_exists($file)) {
//Read the file line by line
$lines = file($file);
//Get the temp from second line
$temp = ($lines[1]);
} else {
$temp = "9999";
}
return $temp + $sensor['calibration_value'];

}

@aaronbronow aaronbronow self-assigned this May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants