Пример #1
0
<?php

require_once "conf.php";
require_once "funcoes.php";
pg_retorna("SELECT *,\n                                 to_char(timestamp, 'DD/MM/YY HH24:MI:SS') as timestamp_ajustado\n\t\t\t\t\t\t\t\t FROM data WHERE 1 = 1      \n                                              AND id_sensor = " . $_GET["id_sensor"] . "\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t  AND id_end_device = " . $_GET["id_end_device"] . "\n\t\t\t\t\t\t\t\t\t\t\t  ORDER BY timestamp DESC LIMIT 1", $rQryDataUlt);
?>


<html>
  <head>
    <meta http-equiv="refresh" content="7" > 
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});
      
    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);
      
    function drawChart() {
      var jsonData = $.ajax({
          url: "getData.php?tipo=<?php 
echo $_GET["tipo"];
?>
&id_end_device=<?php 
echo $_GET["id_end_device"];
?>
&id_sensor=<?php 
Пример #2
0
<?php

require_once "conf.php";
require_once "funcoes.php";
$_GET["tipo"] = "end_device";
$_GET["id_end_device"] = "666";
if (!$_GET["periodo"]) {
    $_GET["periodo"] = 24;
}
pg_retorna("SELECT *,\n                                 to_char(timestamp, 'DD-MM-YY HH24:MI:SS') as timestamp_ajustado\n\t\t\t\t\t\t\t\t FROM data WHERE 1 = 1      \n                                              AND id_sensor = 2\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t  ORDER BY timestamp DESC LIMIT 1", $rQryDataTemperatura);
pg_retorna("SELECT *,\n                                 to_char(timestamp, 'DD-MM-YY HH24:MI:SS') as timestamp_ajustado\n\t\t\t\t\t\t\t\t FROM data WHERE 1 = 1      \n                                              AND id_sensor = 3\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t  ORDER BY timestamp DESC LIMIT 1", $rQryDataUmidade);
?>

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});
      
    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);
      
    function drawChart() {
      var jsonData1 = $.ajax({
          url: "getData.php?tipo=<?php 
echo $_GET["tipo"];
?>
Пример #3
0
<?php 
require_once "conf.php";
require_once "funcoes.php";
if ($_GET["tipo"] == "end_device") {
    if ($_GET["id_end_device"]) {
        $end_device_sql = "AND id_end_device = " . $_GET["id_end_device"] . "";
    }
    if ($_GET["periodo"] > 24) {
        $timestamp_sql = "to_char(timestamp, 'DD-MM-YY HH24:MI') as timestamp_ajustado";
    } else {
        $timestamp_sql = "to_char(timestamp, 'HH24:MI') as timestamp_ajustado";
    }
    $iQryData = pg_retorna("SELECT *,\n                                 " . $timestamp_sql . "\n\t\t\t\t\t\t\t\t FROM data WHERE 1 = 1 \n                                               " . $end_device_sql . "\n                                              AND id_sensor = " . $_GET["id_sensor"] . "  \t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t  AND timestamp > (now()::timestamp(0) at time zone 'GMT-2' - INTERVAL '" . $_GET["periodo"] . " HOUR') ORDER BY timestamp ASC", $rQryData);
}
$array = array();
$array['cols'][] = array('type' => 'string');
$array['cols'][] = array('type' => 'number');
//HERE you have the difference
for ($i = 0; $i < $iQryData; $i++) {
    if ($rQryData[$i]["payload"] > 0) {
        $array['rows'][]['c'] = array(array('v' => $rQryData[$i]["timestamp_ajustado"]), array('v' => $rQryData[$i]["payload"]));
    }
}
echo json_encode($array);
?>