Jump to content









Photo

Send Commands


  • Please log in to reply
1 reply to this topic

#1 tstreet_light

tstreet_light

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 February 2014 - 12:48 PM

Hello,

 

I am trying to send commands using Carriots  and I would like to know if it's possible to send commands to a specific device and to receive instant answer with some application information in the same HTTP anwser.

 

The solution that Carriots staff propouse using Rasberry-Pi is to send status stream frames. But when you used that, the answer is HTTP 200 Ok. You don't know if your command was executed or not if you don't check another characterisc in carriots, al least as far as I understood.

 

So, to sum up, Could I send commands and receive extra information inside the HTTP response using Carriots or I need to check other characteristic in Carriots doing polling?

 

 

Thanks in advance



#2 alvaro

alvaro

    Carriots CTO

  • Administrators
  • 72 posts

Posted 11 February 2014 - 08:27 AM

Hi tstreet_light.

 

I'm not confident about understanding your question but I will try to give some answers.

 

Assuming you want to do a communication in Carriots -> device direction using our Raspberry Pi electrovalve example you will see that our PHP code is written to do an action according to very simple parameters and nothing else:

 

<?php

    $gpio_pin = "7";
    exec("gpio mode $gpio_pin out");
    $command = (isset($_GET['status']) && $_GET['status'] == "on") ? "gpio write $gpio_pin 1" : "gpio write $gpio_pin 0";
    exec($command);

 

 If you want to render a response you just have to write plain text closing the PHP tag or manage the response using the HttpResponse class: http://www.php.net/m...ttpresponse.php

 

For example:

 

<?php
    // Your execution command here updating $success to true on sucess or to false otherwise

   if ($success) {

      HttpResponse::status(200);
      HttpResponse::setContentType('text/html');
      HttpResponse::setData('<h1>Sucess</h1>');
      HttpResponse::send();

   } else {

      HttpResponse::status(500);
      HttpResponse::setContentType('text/html');
      HttpResponse::setData('<h1>Something went wrong</h1>');
      HttpResponse::send();

   }

?>

 

or something like:

 

<?php
    // Your execution command here updating $result with the execution result
?>
<h1>Done</h1>
Result was: <?php echo $result ?>

 

If communication must be done in Device->Carriots direction you can use Listeners to perform asynchronous actions, like updating properties or configuration files, and then query again to get the result. Or you can also use the configuration management flow explained in our Status stream documentation page.

 

Hope it helps.

 

Enjoy Carriots!


Alvaro Everlet

Carriots CTO





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users