Exemple #1
0
 /**
  * @param string
  * @param array
  * @return HttpRequest
  */
 public function render($template, $context)
 {
     $render = $this->get('render');
     $response = new HttpResponse();
     $response->setData($render->render($template, $context));
     return $response;
 }
Exemple #2
0
 protected function handleRead($read_sock)
 {
     //	read up to 10000 bytes
     // $data = '';
     // while(true)
     // {
     // 	echo "getting line\n";
     // 	socket_set_nonblock($read_sock);
     // 	$line = socket_read($read_sock, 1024, PHP_BINARY_READ);
     // 	echo "type = " . gettype($line) . "\n";
     // 	echo "len = " . strlen($line) . "\n";
     // 	echo "value = $line\n";
     //
     // 	$err = socket_last_error($read_sock);
     // 	if($err)
     // 		echo "error = " . socket_strerror($err) . "\n";
     // 	else
     // 		echo "no error\n";
     //
     // 	if(strlen($line) == 0)
     // 		break;
     // 	$data .= $line;
     // }
     $data = socket_read($read_sock, 1024, PHP_BINARY_READ);
     // if(strlen($data) == 5)
     // 	for($i = 0; $i < strlen($data); $i++)
     // 		echo "the char is = " . ord($data[$i]) . "\n";
     echo "start dumping raw data\n";
     var_dump($data);
     echo "done dumping raw data\n";
     // check if the client is disconnected
     // if ($data === false)
     if (!$data) {
         // remove client for $this->clients array
         $key = array_search($read_sock, $this->clients);
         unset($this->clients[$key]);
         echo "client disconnected.\n";
         // continue to the next client to read from, if any
         return;
     }
     echo "recieving request\n";
     // check if there is any data after trimming off the spaces
     if (!empty($data)) {
         echo "printing raw request content\n";
         echo $data . "\n";
         //
         $message = new HttpMessage($data);
         echo "printing out message object\n";
         print_r($message);
         echo $message->getType() . "\n";
         echo $message->getRequestMethod() . "\n";
         echo $message->getRequestUrl() . "\n";
         HttpResponse::setData("<html><body>asdf</body></html>");
         print_r(HttpResponse::getRequestHeaders());
         // HttpResponse::send();
         // echo "printing the data\n";
         // echo HttpResponse::getData();
     } else {
         echo "received empty request\n";
         sleep(10);
     }
     echo "done receiving request\n\n\n\n";
 }
Exemple #3
0
    $serial = new phpSerial();
    $serial->deviceSet("/dev/ttyACM0");
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->deviceOpen();
    // arduino requires a 2 second delay in order to receive the message
    sleep(2);
    // Si c'est une request hi on allumera la led
    $data = $_GET["hi"];
    $serial->sendMessage($data);
    $read[$cnt] = $serial->readPort();
    while (substr($read[$cnt], -1, 1) != "a") {
        $cnt++;
        $read[$cnt] = $serial->readPort();
    }
    for ($i = 1; $i < $cnt + 1; $i++) {
        $rcv = $rcv . $read[$i];
    }
    $rcv = rtrim($rcv, "a");
    // Si c'est une request temperature on renvoiera la température (voir index.php pour le retour de valeur)
    // afficher température sur le bobox
    // Si c'est une request heure on affiche l'heure sur le bobox (pas besoin sur téléphone
    // Variation de lumière -> quelqun dans la piece ! notification téléphone ? a voir...
    HttpResponse::setCache(true);
    HttpResponse::setContentType('text/plain');
    HttpResponse::setData($rcv);
    HttpResponse::send();
    $serial->deviceClose();
}
 public function actionLongPoller()
 {
     $model = new LongPoller();
     //$request = http_get_request_body();
     $request = json_encode(array("deviceID" => "90:C1:15:BC:97:4F", "orderNo" => "1"));
     $model->decodeStatusRequest($request);
     $model->checkStatus();
     $responseMsg = $model->generateResponse();
     HttpResponse::status(200);
     HttpResponse::setContentType('application/json');
     HttpResponse::setData($responseMsg);
     HttpResponse::send();
 }
<?php

require_once 'HTTP/Request2/Response.php';
//echo "Hello there you are now connected to the canteen web server <br />";
/*HttpResponse::status(200);
HttpResponse::setContentType('json');
//HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData($_POST);
HttpResponse::send();*/
$connection = Yii::app()->db;
$sql_select = 'SELECT *   FROM menu';
$command = $connection->createCommand($sql_select);
$menuData = $command->query();
$row = $menuData->readAll();
$json_string = json_encode(array("updated" => "false", 'menu:' => $row));
$headers = http_get_request_headers();
$result = http_get_request_body();
$decodeResult = json_decode($result);
HttpResponse::status(200);
HttpResponse::setContentType('application/json');
//HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData($json_string);
HttpResponse::send();
flush();