Jump to content


Send Commands

  • Please log in to reply
1 reply to this topic

#1 tstreet_light



  • Members
  • Pip
  • 1 posts

Posted 07 February 2014 - 12:48 PM



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


    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:



    $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";


 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:


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

   if ($success) {


   } else {

      HttpResponse::setData('<h1>Something went wrong</h1>');




or something like:


    // Your execution command here updating $result with the execution result
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