Exemplo n.º 1
0
 /**
  * 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);
     }
 }
 /**
 * 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);
     }
 }
Exemplo n.º 3
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;
     }
 }
Exemplo n.º 4
0
<?php

echo "<h3>\\Rhonda\\RequestBody</h3>";
// Retrieve a provided request body
try {
    echo json_encode(\Rhonda\RequestBody::get());
} catch (Exception $e) {
    echo "No raw POST body.";
}
try {
    $request_body = new \Rhonda\RequestBody();
    echo json_encode($request_body->get());
} catch (Exception $e) {
    echo "No raw POST body.";
}