Skip to content

Commit

Permalink
PiHome Smart Heating
Browse files Browse the repository at this point in the history
Added Celsius vs Fahrenheit capability. #13
  • Loading branch information
pihome-shc committed Jan 9, 2019
1 parent fbf817b commit 90fd392
Show file tree
Hide file tree
Showing 23 changed files with 330 additions and 111 deletions.
2 changes: 1 addition & 1 deletion add_holidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<?php
ShowWeather($conn);
?>
</div>

</div>
</div>
<!-- /.col-lg-4 -->
Expand Down
4 changes: 2 additions & 2 deletions boostlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
</div>
<!-- /.panel-body -->
<div class="panel-footer">
<?php
<?php
ShowWeather($conn);
?>
</div>
</div>
<?php if(isset($conn)) { $conn->close();} ?>
<?php if(isset($conn)) { $conn->close();} ?>
4 changes: 2 additions & 2 deletions chartfooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
showTooltip(item.pageX,
item.pageY,
color,
"<strong>" + item.series.label + "</strong> At: " + new Date(x).getHours() + ":" + (new Date(x).getMinutes()<10?'0':'') + new Date(x).getMinutes() +"<br> <strong>Temp : " + $.formatNumber(y, { format: "#,###", locale: "us" }) + "&deg;</strong> ");
"<strong>" + item.series.label + "</strong> At: " + (new Date(x).getHours()<10?'0':'') + new Date(x).getHours() + ":" + (new Date(x).getMinutes()<10?'0':'') + new Date(x).getMinutes() +"<br> <strong>Temp : " + $.formatNumber(y, { format: "#,###", locale: "us" }) + "&deg;</strong> ");
}
} else {
$("#tooltip").remove();
Expand Down Expand Up @@ -276,4 +276,4 @@ function showTooltipu(x, y, color, contents) {
var btotal_minuts = <?php echo json_encode($btotal_minuts); ?>;
var bon_minuts = <?php echo json_encode($bon_minuts); ?>;
var bsave_minuts = <?php echo json_encode($bsave_minuts); ?>;
</script>
</script>
2 changes: 1 addition & 1 deletion chartlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ function clean($string) {
<br>
<div class="flot-chart">
<div class="flot-chart-content" id="system_c"></div>
</div>
</div>
25 changes: 12 additions & 13 deletions cron/boiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,21 @@
$sensor = mysqli_fetch_array($result);
$zone_c = $sensor['payload'];

//Have to account for midnight rollover conditions
$query = "SELECT * FROM schedule_daily_time_zone_view
WHERE ((`end`>`start` AND CURTIME() between `start` AND `end`)
OR (`end`<`start` AND CURTIME()<`end`)
OR (`end`<`start` AND CURTIME()>`start`))
AND zone_id = {$zone_id}
AND time_status = '1'
LIMIT 1;";
/*$query = "SELECT * FROM schedule_daily_time_zone_view WHERE CURTIME() between `start` AND `end` AND zone_id = {$zone_id} AND time_status = '1' LIMIT 1;";
$result = $conn->query($query);
$schedule = mysqli_fetch_array($result);
$sch_status = $schedule['tz_status'];
$sch_start_time = $schedule['start'];
$sch_end_time = $schedule['end'];
$sch_c = $schedule['temperature'];
*/
//Have to account for midnight rollover conditions
$query = "SELECT * FROM schedule_daily_time_zone_view WHERE ((`end`>`start` AND CURTIME() between `start` AND `end`) OR (`end`<`start` AND CURTIME()<`end`) OR (`end`<`start` AND CURTIME()>`start`)) AND zone_id = {$zone_id} AND time_status = '1' LIMIT 1;";
//echo $query . PHP_EOL;
$result = $conn->query($query);
if(mysqli_num_rows($result)<=0)
{
if(mysqli_num_rows($result)<=0){
$sch_status=0;
}
else
{
}else{
$schedule = mysqli_fetch_array($result);
$sch_status = $schedule['tz_status'];
$sch_start_time = $schedule['start'];
Expand Down
29 changes: 18 additions & 11 deletions cron/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# add following line to show up when some one ssh to pi /etc/profile
# sudo python /var/www/cron/login.py
# clear everything from /etc/motd to remove generic message.
import socket, os, re, time, sys, subprocess
import socket, os, re, time, sys, subprocess, fcntl, struct
from threading import Thread
class bc:
HEADER = '\033[0;36;40m'
Expand Down Expand Up @@ -35,17 +35,24 @@ class bc:
output = df.communicate()[0]
device, size, used, available, percent, mountpoint = \
output.split("\n")[1].split()

print bc.org +"Disk/SD Card Usage" + bc.ENDC
print "Filesystem Size Used Avail Used%"
print device+" "+size+" "+used+" "+available+" "+percent

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('google.com', 0))
ip = s.getsockname()[0]
#Get the Local IP
end = re.search('^[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}', ip)
#Chop down the last IP Digits
create_ip = re.search('^[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.', ip)
print "WebServer: "+bc.GREEN +"http://"+str(end.group(0))+"/"+ bc.ENDC
print "PhpMyAdmin: "+bc.GREEN +"http://"+str(end.group(0))+"/phpmyadmin"+ bc.ENDC
def get_interface_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])

def get_ip():
ip = socket.gethostbyname(socket.gethostname())
if ip.startswith("127."):
interfaces = ["eth0","eth1","eth2","wlan0","wlan1","wifi0","ath0","ath1","ppp0"]
for ifname in interfaces:
try:
ip = get_interface_ip(ifname)
break
except IOError:
pass
return ip
print "WebServer: "+bc.GREEN +"http://"+str(get_ip())+"/"+ bc.ENDC
print "PhpMyAdmin: "+bc.GREEN +"http://"+str(get_ip())+"/phpmyadmin"+ bc.ENDC
16 changes: 12 additions & 4 deletions cron/weather_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@
$appid = $row['openweather_api'];
//Get Current Weather Data
if($city != NULL)

$weather_current_api = "http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&" . $units . "&appid=".$appid;
else
$weather_current_api = "http://api.openweathermap.org/data/2.5/weather?zip=".$zip.",".$country."&" . $units . "&appid=".$appid;
$json = file_get_contents($weather_current_api);
file_put_contents('/var/www/weather_current.json', $json);

echo "\033[36m".date('Y-m-d H:i:s'). "\033[0m - Weather Data Downloaded \n";
//add weather temperature to database
$weather_data = json_decode($json, true);
//weather_c is now dependent upon the units specified in the query.

$weather_c= round($weather_data['main']['temp']); //-272.15);
//$c = $weather_data['main']['temp'];
$wind_speed = round($weather_data['wind']['speed']); //*1.609344, 2);
$sunrise = $weather_data['sys']['sunrise'];
$sunset = $weather_data['sys']['sunset'];
$title = $weather_data['weather'][0]['main'];
Expand All @@ -80,7 +84,9 @@
//Call 5 day / 3 hour forecast data
//$weather_fivedays_api = "http://api.openweathermap.org/data/2.5/forecast?q=".$city.",".$country."&units=metric&appid=".$appid;
if($city != NULL)

$weather_fivedays_api = "http://api.openweathermap.org/data/2.5/forecast?q=".$city.",".$country."&" . $units . "&lang=en&appid=".$appid;
else
$weather_fivedays_api = "http://api.openweathermap.org/data/2.5/forecast?zip=".$zip.",".$country."&" . $units . "&lang=en&appid=".$appid;
$json = file_get_contents($weather_fivedays_api);
file_put_contents('/var/www/weather_5days.json', $json);
$weather_fivedays = json_decode($json, true);
Expand All @@ -107,7 +113,9 @@
//6 days weather forecast data
//$weather_sixdays_api = "http://api.openweathermap.org/data/2.5/forecast/daily?q=".$city.",".$country."&appid=".$appid;
if($city != NULL)

$weather_sixdays_api = "http://api.openweathermap.org/data/2.5/forecast/daily?q=".$city.",".$country."&" . $units . "&cnt=7&lang=en&appid=".$appid;
else
$weather_sixdays_api = "http://api.openweathermap.org/data/2.5/forecast/daily?zip=".$zip.",".$country."&" . $units . "&cnt=7&lang=en&appid=".$appid;
$json = file_get_contents($weather_sixdays_api);
file_put_contents('/var/www/weather_6days.json', $json);
echo "\033[36m".date('Y-m-d H:i:s'). "\033[0m - Weather Data Downloaded \n";
Expand Down
62 changes: 59 additions & 3 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
//update frost temperature
if($what=="frost"){
if($opp=="update"){
$temp=TempToDB($conn,$_GET['frost_temp']);
$temp=TempToDB($conn,$_GET['frost_temp']);
$query = "UPDATE frost_protection SET temperature = '" . number_format($temp,1) . "', sync = 0 LIMIT 1";
if($conn->query($query))
{
Expand All @@ -201,13 +201,69 @@
}
}


//update units
if($what=="units"){
if($opp=="update"){
$query = "UPDATE `system` SET `c_f`=" . $_GET['val'] . ";";
if($conn->query($query))
{
header('Content-type: application/json');
echo json_encode(array('Success'=>'Success','Query'=>$query));
return;
}
else
{
header('Content-type: application/json');
echo json_encode(array('Message'=>'Database query failed.\r\nQuery=' . $query));
return;
}
}
}


//update openweather
if($what=="openweather"){
if($opp=="update"){
if($_GET['rad_CityZip']=='City') {
$query = "UPDATE `system` SET `country`='" . $_GET['sel_Country'] . "'
,`openweather_api`='" . $_GET['inp_APIKEY'] . "'
,`city`='" . $_GET['inp_City'] . "',`zip`=NULL;";
if($conn->query($query))
{
header('Content-type: application/json');
echo json_encode(array('Success'=>'Success','Query'=>$query));
return;
}
else
{
header('Content-type: application/json');
echo json_encode(array('Message'=>'Database query failed.\r\nQuery=' . $query));
return;
}
}
else if($_GET['rad_CityZip']=='Zip') {
$query = "UPDATE `system` SET `country`='" . $_GET['sel_Country'] . "'
,`openweather_api`='" . $_GET['inp_APIKEY'] . "'
,`zip`='" . $_GET['inp_Zip'] . "',`city`=NULL;";
if($conn->query($query))
{
header('Content-type: application/json');
echo json_encode(array('Success'=>'Success','Query'=>$query));
return;
}
else
{
header('Content-type: application/json');
echo json_encode(array('Message'=>'Database query failed.\r\nQuery=' . $query));
return;
}
}
else {
header('Content-type: application/json');
echo json_encode(array('Message'=>'Invalid value for rad_CityZip.\r\n$_GET=' . print_r($_GET)));
return;
}
}
}
//Database Backup
if($what=="db_backup"){
shell_exec("php start_backup.php");
Expand Down
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
<?php if ($_SERVER['REQUEST_URI'] == '/chart.php'){include("chartfooter.php");} ?>
</body>
</html>
<?php if(isset($conn)) { $conn->close();} ?>
<?php if(isset($conn)) { $conn->close();} ?>
6 changes: 3 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<a class="navbar-brand" href="home.php"><img src="images/navi-logo.png" width="32"></a>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<li class="dropdown">
<li class="dropdown">
<a href="index.php">
<i class="fa fa-home fa-fw"></i>
</a>
Expand Down Expand Up @@ -197,7 +197,7 @@
<br>
<div class="row">
<div class="col-lg-12">
<?php if(filesize('weather_6days.json')>0) { ?>
<?php if(filesize('weather_6days.json')>0) { ?>
<h4 class="text-center">Six Days Weather</h4>
<div class="list-group">
<?php
Expand All @@ -210,7 +210,7 @@
}
?>
</div>
<?php } //end of filesize if ?>
<?php } //end of filesize if ?>
<a href="weather.php" button type="button" class="btn btn-default login btn-sm btn-edit">3 Hour Forcast</a>
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
</div></div>
Expand Down
4 changes: 2 additions & 2 deletions homelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@
}
else {
//We shouldn't get here.
$status='';
$shactive='fa-question';
$status='blue';
$shactive='';
$shcolor='';
$target=''; //show no target temperature
}
Expand Down
3 changes: 0 additions & 3 deletions model.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@
</div>
</div>';


//Units
$c_f = settings($conn, 'c_f');
if($c_f==1 || $c_f=='1')
$TUnit='F';
else
$TUnit='C';

echo '
<div class="modal fade" id="change_units" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
Expand All @@ -131,7 +129,6 @@
</div>
</div>';


//Boiler Safety settings
echo '
<div class="modal fade" id="boiler_safety_setup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Expand Down
4 changes: 2 additions & 2 deletions night_climate.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$max =TempToDB($conn,$_POST['max'][$id]);
$query = "UPDATE schedule_night_climat_zone SET sync = '0', status='$status', min_temperature='" . number_format($min,1) . "', max_temperature='" . number_format($max,1) . "' WHERE id='$id'";
$zoneresults = $conn->query($query);
if ($zoneresults) {
if ($zoneresults) {
$message_success .= "<p>Night Climate Temp Changed Successfully!!!</p>";
} else {
$error .= "<p>Night Climate Changes Failed with error: </p><p>".mysqli_error($conn). "</p>";
Expand Down Expand Up @@ -105,7 +105,7 @@
?>
<label>Minimum Temperature</label>
<select class="form-control input-sm" type="number" id="<?php echo $sncz["id"];?>" name="min[<?php echo $sncz["id"];?>]" placeholder="Zone Temperature" >
<?php
<?php
$c_f = settings($conn, 'c_f');
if($c_f==1 || $c_f=='1') {
for($t=64;$t<=74;$t++)
Expand Down
35 changes: 0 additions & 35 deletions schedule_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,41 +111,6 @@
}
}
?>



<option>0</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
<option>32</option>
<option>33</option>
<option>34</option>
<option>35</option>
<option>36</option>
<option>37</option>
<option>38</option>
<option>39</option>
<option>40</option>
<option>41</option>
<option>42</option>
<option>43</option>
<option>44</option>
<option>45</option>

</select>
<div class="help-block with-errors"></div></div></div>

Expand Down
Loading

0 comments on commit 90fd392

Please sign in to comment.