getNewPDO(); return ($pdo != null ? $pdo->prepare($qry) : null); } function getNewPDO() { $pdo = null; try { $pdo = new PDO("mysql:host=192.168.1.7;dbname=homeAutomation", 'homer', 'vc8644'); } catch (PDOException $e) { $pdo = null; } $pdo = new PDO("mysql:host=192.168.1.7;dbname=homeAutomation", 'homer', 'vc8644'); return $pdo; } function recordWeight( $weight, $systemRAM, $reading ) { $sql = "INSERT INTO weight (weight,systemRAM,reading) VALUES (:weight,:systemRAM,:reading)"; $stmt = $this->connectWithPrepare($sql); $stmt->execute(array(':weight'=>$weight,':systemRAM'=>$systemRAM,':reading'=>$reading)); } function getStats( $byHour=false ) { if( $byHour == 1 ) { $sql = "SELECT TRUNCATE(AVG(weight),2) AS weight,TIME_FORMAT(`recordTime`,'%H') AS dataTime,DATE_FORMAT(`recordTime`,'%j%H') AS sortTime, "; $sql .= " FROM weight"; $sql .= " WHERE DATE_FORMAT(`recordTime`,'%j%H') < DATE_FORMAT(NOW(),'%j%H') "; $sql .= " GROUP BY DATE_FORMAT(`recordTime`,'%d%H') "; $sql .= " ORDER BY sortTime "; } else { $sql = "SELECT weight,TIME_FORMAT(`recordTime`,'%H:%i') AS dataTime, recordTime "; $sql .= " FROM weight"; $sql .= " ORDER BY recordTime"; } $stmt = $this->connectWithPrepare($sql); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // print_r($rows); foreach($rows as $row){ if( isset($row['weight']) ) { echo ",['".$row['dataTime']."',".$row['weight']."]"; } } } function getLastReading( ) { $sql = "SELECT weight, DATE_FORMAT(`recordTime`,'%W %M %D at %l:%i%p') AS dataTime "; $sql .= " FROM weight"; $sql .= " ORDER BY recordTime DESC "; $sql .= " LIMIT 1"; $stmt = $this->connectWithPrepare($sql); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo "Last reading on " . $row['dataTime']." was ".$row['weight'] . " uV"; } } $stats = new WeightTracker(); $weight = $stats->getCGIvariable( "weight" ); $reading = $stats->getCGIvariable( "reading" ); if( empty($weight) ) { $byHour = $stats->getCGIvariable( "byHour", "0" ); ?>
getCGIvariable( "ram", "0" ); $stats->recordWeight( $weight, $sysRAM, $reading ); echo "data recorded"; }