/**
  * Read average temperature value of multiple sensors
  * <pre class="POST"> POST [url]/i2c/temperature/</pre>
  *
  * @example
  * [
  *     "sensor_id"
  *   , "sensor_id"
  * ]
  *
  * @return JSON - **Object** result info
  *
  * @since   2016-02-07
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if id exists
  **/
 public function temperature_multiple()
 {
     try {
         $config = \Rhonda\Config::get('config');
         // Load post body
         $body = \Rhonda\RequestBody::get();
         $celsius = 0;
         $fahrenheit = 0;
         $count = count($body);
         foreach ($body as $sensor_id) {
             $sensor = new \Models\I2c();
             $sensor->id = $sensor_id;
             $sensor->path = $config->BUS_PATH;
             $temp = $sensor->get_temperature();
             $celsius = $celsius + $temp->celsius;
             $fahrenheit = $fahrenheit + $temp->fahrenheit;
         }
         $average = new \stdClass();
         $average->celsius = $celsius / $count;
         $average->fahrenheit = $fahrenheit / $count;
         echo json_encode($average);
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
Beispiel #2
0
 /**
  * Requires a database config file or object to be loaded and the mysqli extension for PHP to be installed</br>
  *
  * Escape a String
  * @example
  * <code>
  *   $string = "that's all folks";
  *   $string = \Rhonda\Mysql::real_escape($string);
  * </code>
  *
  * Escape an Object
  * @example
  * <code>
  *   $object = new \stdClass();
  *   $object->thing = "it's for real";
  *   $object = \Rhonda\Mysql::real_escape($object);
  * </code>
  *
  * Escape an Array
  * @example
  * <code>
  * $array = array(
  *    "ray"=>"it's escaping arrays"
  *  , "ray2"=>"escape's this one too"
  * );
  * $array = \Rhonda\Mysql::real_escape($ray);
  *
  * @return Type - Mysql escaped resource that was operated on
  *
  * @since   2015-11-20
  * @author  Deac Karns <*****@*****.**> 
  **/
 public static function real_escape($thing)
 {
     // check that a configuration object exists for DB
     try {
         $db = \Rhonda\Config::get('DB')->connections->local;
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
     $mysqli = new \mysqli($db->host, $db->user, $db->password, $db->database, $db->port);
     $mysqli->set_charset("utf8");
     if ($mysqli->connect_errno) {
         echo \Rhonda\Error::handle($mysqli->connect_error);
     }
     // test the thing that is coming in
     switch (gettype($thing)) {
         case 'string':
             $escaped = $mysqli->real_escape_string($thing);
             break;
         case 'object':
             $escaped = self::escape_collection($thing, $mysqli);
             break;
         case 'array':
             $escaped = self::escape_collection($thing, $mysqli);
             break;
         default:
             $escaped = $thing;
             break;
     }
     return $escaped;
 }
 /**
  * Switch pin ON / OFF
  * <pre class="PUT"> PUT [url]/switch/set/:pin/:value/</pre>
  *
  * @param String - pin number (wPi pin)
  * @param String - value (ON/OFF)
  *
  * @example
  * No POST Body
  *
  * @return JSON - **Object** success message
  *
  * @since   2016-02-05
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if values are set correctly
  * @todo    check if pin exists
  **/
 public function set($pin, $value)
 {
     try {
         if (!is_numeric($pin)) {
             throw new \Exception("Pin should be numeric");
         }
         # Load the model
         $set_gpio = new \Models\GPIO();
         $set_gpio->pin = $pin;
         # Decide what to do
         if ($value == 'ON') {
             $set_gpio->mode = 'OUT';
             $set_gpio->status = 0;
         } elseif ($value == 'OFF') {
             $set_gpio->mode = 'IN';
             $set_gpio->status = 1;
         } else {
             throw new \Exception("No valid pin value entered");
         }
         // Execute the commands
         $set_gpio->mode();
         $set_gpio->write();
         // Reload the pin
         echo json_encode($set_gpio->get());
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
 /**
  * Write a pin value
  * <pre class="PUT"> PUT [url]/gpio/write/:pin/:value/</pre>
  *
  * @param String - pin number
  * @param String - value
  *
  * @example
  * No POST Body
  *
  * @return JSON - **Object** success message
  *
  * @since   2016-02-05
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if values are set correctly
  * @todo    check if pin exists
  **/
 public function send($id)
 {
     try {
         $config = \Rhonda\Config::get('config');
         $send = new \Models\RFID();
         $send->id = $id;
         $send->path = $config->RFID_PATH;
         $send->send();
         echo \Rhonda\Success::create();
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
 /**
 * Tell onkyo what setting to change
 *
 * @param String - What source type you wanna change PWR/MVL/AMT/SLI
 *
 * @example
 * <code>
 * {
 *     param: "ID"
 *   , ip: "ip address of device"
 *   , port: "port of device"
 * }
 * </code>
 *
 * @return Return
 *
 * @since   2016-01-01
 * @author  Wesley Dekkers <*****@*****.**> 
 **/
 public function command($type)
 {
     try {
         $body = \Rhonda\RequestBody::get();
         $body->type = $type;
         $onkyo = new \Models\Onkyo();
         $socket = 'tcp://' . $body->ip . ':' . $body->port;
         $fp = stream_socket_client($socket, $errno, $errstr, 30);
         if (!$fp) {
             echo "{$errstr} ({$errno})<br />\n";
         }
         if ($body->type == 'MVL') {
             $body->param = min($body->param, 64);
             $body->param = str_pad($body->param, 2, '0', STR_PAD_LEFT);
         }
         $set = $onkyo->set($fp, $body);
         if (!$set) {
             throw new \Exception("Failed to send request");
         }
         echo json_encode($set);
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
Beispiel #6
0
 public function PDO_packager()
 {
     try {
         if (isset($_GET['q'])) {
             json_decode(urldecode($_GET['q']));
             if (json_last_error() !== JSON_ERROR_NONE) {
                 throw new \Exception("Malformed JSON in query string [q]: " . json_last_error_msg());
             }
         }
         if (isset($_GET)) {
             self::$get = self::sanitize_get_array($_GET);
         }
         $post_body = \Rhonda\RequestBody::get(TRUE);
         if (!empty($post_body)) {
             self::$post = $post_body;
         }
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
         die;
     }
 }
Beispiel #7
0
<?php

echo "<h3>\\Rhonda\\Error</h3>";
// Format an exception the error log and for return
try {
    throw new Exception("Demo Error Exception 1");
} catch (\Exception $e) {
    echo \Rhonda\Error::handle($e);
}
echo "</br>";
try {
    throw new Exception("Demo Error Exception 2");
} catch (\Exception $e) {
    $error = new \Rhonda\Error();
    echo $error->handle($e);
}
\Rhonda\Error::deprecation_warning("message", "http://alternate/route");
echo "</br>";
 /**
  * Set a pin mode
  * <pre class="PUT"> PUT [url]/gpio/mode/:pin/:mode/</pre>
  *
  * @param String - pin number (wPi pin)
  * @param String - mode IN/OUT (or others)
  *
  * @example
  * No POST Body
  *
  * @return JSON - **Object** success message
  *
  * @since   2016-02-05
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if modes are set correctly
  * @todo    check if pin exists
  **/
 public function mode($pin, $mode)
 {
     try {
         if (!is_numeric($pin)) {
             throw new \Exception("Pin should be numeric", 1);
         }
         $mode_gpio = new \Models\GPIO();
         $mode_gpio->pin = $pin;
         $mode_gpio->mode = $mode;
         $mode_gpio->mode();
         echo \Rhonda\Success::create();
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
 /**
  * Get the country of the receiver
  *
  * @param Parameter - String 
  *
  * @return Return - String
  *
  * @since   2016-02-13
  * @author  Wesley Dekkers <*****@*****.**> 
  **/
 public function code_to_country($code)
 {
     try {
         switch ($code) {
             case 'DX':
                 return 'North America';
             case 'XX':
                 return 'Europe/Asia';
             case 'JJ':
                 return 'Japan';
             default:
                 return 'Unknown';
         }
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }