1. AWS mysql server
2. AWS webpage
3. raspberry pi code is ready
- Degree, Humidity, Movement
- Upload information to AWS mysql
4. Web page
Not yet
1. phone application for logging event.
2. analysis module.
After some month, if I have a time, I will add more information this project again.
Following code is web page code for data viewing and some snapshot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dataQuery($chartType){ | |
$chartData = array(); | |
$chartTimeQuery = ""; | |
$options = array(); | |
array_push($options, 'width', 1024); | |
array_push($options, 'height', 500); | |
if($chartType == 1){ | |
array_push($chartData, array("TIME", "DEGREE")); | |
$chartTimeQuery = "'%Y-%m-%d %H'"; | |
} else if($chartType == 2){ | |
array_push($chartData, array("TIME", "DEGREE")); | |
$chartTimeQuery = "'%Y-%m-%d'"; | |
} else if($chartType == 3){ | |
array_push($chartData, array("TIME", "HUMIDITY")); | |
$chartTimeQuery = "'%Y-%m-%d %H'"; | |
} else if($chartType == 4){ | |
array_push($chartData, array("TIME", "HUMIDITY")); | |
$chartTimeQuery = "'%Y-%m-%d'"; | |
} else if($chartType == 5){ | |
array_push($chartData, array("TIME", "MOVEMENT")); | |
$chartTimeQuery = "'%Y-%m-%d %H'"; | |
} else if($chartType == 6){ | |
array_push($chartData, array("TIME", "MOVEMENT")); | |
$chartTimeQuery = "'%Y-%m-%d'"; | |
} | |
$jsonArg = ""; | |
//Connect DB | |
$host = “YOURHOST"; | |
$user = “YOURUSERNAME"; | |
$password = “YOURPASSWORD"; | |
$dbname = “YOURDBNAME"; | |
$connect = mysqli_connect($host, $user, $password, $dbname); | |
if(mysqli_connect_errno($connect)) { | |
echo "DB connect fail"; | |
} else { | |
//echo "DB connect success"; | |
} | |
$dataQuery = "SELECT FROM_UNIXTIME(TIMESTAMP+OFFSET, $chartTimeQuery) as TIMESTAMP, AVG(DEGREE) as DEGREE, AVG(HUMIDITY) as HUMIDITY, AVG(MOVEMENT_COUNT) as MOVEMENT_COUNT from home_sensor_01 GROUP BY FROM_UNIXTIME( TIMESTAMP+OFFSET, $chartTimeQuery );"; | |
//printf("<br/> QUERY = %s <br/>", $dataQuery); | |
if( $result = $connect->query( $dataQuery ) ){ | |
//printf("Select returned %d rows. <br/>", $result->num_rows); | |
while($obj = $result->fetch_object()){ | |
if($chartType <= 2){ | |
$item = array($obj->TIMESTAMP, (float)$obj->DEGREE); | |
} else if($chartType <= 4) { | |
$item = array($obj->TIMESTAMP, (float)$obj->HUMIDITY); | |
} else if($chartType <= 6) { | |
$item = array($obj->TIMESTAMP, (float)$obj->MOVEMENT_COUNT); | |
} | |
array_push($chartData, $item); | |
printf("%s, %s, %s, %s <br/>", $obj->TIMESTAMP, $obj->DEGREE, $obj->HUMIDITY, $obj->MOVEMENT_COUNT); | |
} | |
} | |
$jsonArg = json_encode($chartData); | |
//printf("%s <br/>" , $jsonArg); | |
if($chartType == 1){ | |
echo("<script>drawHourChart($jsonArg, '#chart_deg_hour');</script>"); | |
} else if($chartType == 2){ | |
echo("<script>drawHourChart($jsonArg, '#chart_deg_day');</script>"); | |
} else if($chartType == 3){ | |
echo("<script>drawHourChart($jsonArg, '#chart_humidity_hour');</script>"); | |
} else if($chartType == 4){ | |
echo("<script>drawHourChart($jsonArg, '#chart_humidity_day');</script>"); | |
} else if($chartType == 5){ | |
echo("<script>drawHourChart($jsonArg, '#chart_movement_hour');</script>"); | |
} else if($chartType == 6){ | |
echo("<script>drawHourChart($jsonArg, '#chart_movement_day');</script>"); | |
} | |
} | |
?> | |
<script src="//www.google.com/jsapi"></script> | |
<script> | |
function drawHourChart(data, chartName) { | |
var options = <?php echo json_encode($options); ?>; | |
google.load('visualization', '1.0', {'packages':['corechart']}); | |
google.setOnLoadCallback(function() { | |
var chart = new google.visualization.ColumnChart(document.querySelector(chartName)); | |
chart.draw(google.visualization.arrayToDataTable(data), options); | |
}); | |
} | |
</script> | |
<?php | |
dataQuery(1); | |
dataQuery(3); | |
dataQuery(5); | |
dataQuery(2); | |
dataQuery(4); | |
dataQuery(6); | |
?> | |
<html> | |
<body> | |
Hour Degree<br/> | |
<div id="chart_deg_hour"></div> | |
Hour Humidity <br/> | |
<div id="chart_humidity_hour"></div> | |
Hour Movement <br/> | |
<div id="chart_movement_hour"></div> | |
Daily Degree <br/> | |
<div id="chart_deg_day"></div> | |
Daily Humidity <br/> | |
<div id="chart_humidity_day"></div> | |
Daily Movement <br/> | |
<div id="chart_movement_day"></div> | |
<body/> | |
</html> |