function raspberrypi_controller() { global $mysqli, $session, $route, $user; include "Modules/raspberrypi/raspberrypi_model.php"; $raspberrypi = new RaspberryPI($mysqli); $result = false; // html views if ($route->format == 'html') { if ($route->action == "config" && $session['write']) { $result = view("Modules/raspberrypi/raspberrypi_view.php", array('settings' => $raspberrypi->get())); } if ($route->action == "api" && $session['write']) { $result = view("Modules/raspberrypi/raspberrypi_apipage.php", array()); } } // JSON api if ($route->format == 'json') { if ($route->action == "set" && $session['write']) { $result = $raspberrypi->set($session['userid'], $user->get_apikey_write($session['userid']), get('fields')); } if ($route->action == "get" && ($session['read'] || $_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR'])) { $result = $raspberrypi->get(); } if ($route->action == "setrunning" && ($session['write'] || $_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR'])) { $result = $raspberrypi->set_running(); } if ($route->action == "getrunning" && $session['read']) { $result = $raspberrypi->get_running(); } } return array('content' => $result); }
chdir($basedir); // 1) Load settings and core scripts require "process_settings.php"; // 2) Database $mysqli = new mysqli($server, $username, $password, $database); $redis = new Redis(); $redis->connect("127.0.0.1"); // 3) User sessions require "Modules/user/user_model.php"; $user = new User($mysqli, $redis, null); include "Modules/raspberrypi/raspberrypi_model.php"; $raspberrypi = new RaspberryPI($mysqli); include "Modules/packetgen/packetgen_model.php"; $packetgen = new PacketGen($mysqli, $redis); $raspberrypi->set_running(); $settings = $raspberrypi->get(); $apikey = $settings->apikey; if (!$settings->userid) { $settings->userid = 1; } $session = array(); $session['userid'] = $settings->userid; $group = $settings->sgroup; $frequency = $settings->frequency; $baseid = $settings->baseid; // Create a stream context that configures the serial port // And enables canonical input. $c = stream_context_create(array('dio' => array('data_rate' => 9600, 'data_bits' => 8, 'stop_bits' => 1, 'parity' => 0, 'flow_control' => 0, 'is_canonical' => 1))); // Are we POSIX or Windows? POSIX platforms do not have a // Standard port naming scheme so it could be /dev/ttyUSB0 // or some long /dev/tty.serial_port_name_thingy on OSX.