Example #1
0
dio_tcsetattr($fd, array('baud' => 19200, 'bits' => 8, 'stop' => 1, 'parity' => 0));
$running = true;
$buf = "";
while ($running) {
    if ($fd === false) {
        exit(1);
    }
    $data = dio_read($fd);
    if (substr(bin2hex($data), 0, 4) == "0000") {
        $add = "";
        if (substr(bin2hex($buf), 0, 4) == "0000" and substr(bin2hex($buf), 0, 6) != "000000") {
            $add = "00";
        }
        $c = $add . bin2hex($buf);
        #file_put_contents("read.log", $c."\n", FILE_APPEND);
        $pi->save($c);
        $buf = $data;
    } else {
        $buf .= $data;
    }
}
class poolPi
{
    private $values = array();
    private $last = array();
    private $c;
    function __construct()
    {
        $this->c = new SQLite3('/home/pi/poolPi/RSPi/values.db');
        $result = $this->c->query("SELECT name FROM sqlite_master WHERE type='table';");
        $tables = array();