Ignore:
Timestamp:
Apr 30, 2016, 11:29:25 PM (8 years ago)
Author:
ertl-honda
Message:

1.7.10のファイルに更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino

    r175 r224  
    11/*
    22
    3  This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
     3 This sketch uses the restserver connector receive rest calls. It allows access to
     4 the analog and digital pin of the board via rest calls.
     5
     6 supported boards: Yun,Tian.
    47
    58 Possible commands to send from the xmpp client:
    69
    7  * "digital/PIN"        -> to read a digital PIN
    8  * "digital/PIN/VALUE"  -> to write a digital PIN (VALUE: 1/0)
    9  * "analog/PIN/VALUE"   -> to write in a PWM PIN(VALUE range: 0 - 255);
    10  * "analog/PIN"         -> to read a analog PIN
    11  * "servo/PIN/VALUE"      -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
    12  * "mode/PIN/VALUE"     -> to set the PIN mode (VALUE: input / output)
    13  * "ledon"              -> turn on led 13
    14  * "ledoff"             -> turn off led 13
    15  * "ciao"               -> random answers in 5 different languages
    16  
    17  NOTE: be sure to activate and configure xmpp connector on Linino OS
    18        http://labs.arduino.org/Ciao
    19    
     10 * "/arduino/digital/PIN"       -> to read a digital PIN
     11 * "/arduino/digital/PIN/VALUE" -> to write a digital PIN (VALUE: 1/0)
     12 * "/arduino/analog/PIN/VALUE"  -> to write in a PWM PIN(VALUE range: 0 - 255);
     13 * "/arduino/analog/PIN"        -> to read a analog PIN
     14 * "/arduino/servo/PIN/VALUE"   -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
     15 * "/arduino/mode/PIN/VALUE"    -> to set the PIN mode (VALUE: input / output)
     16
     17 Example:
     18 "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
     19 "/arduino/digital/13/1"     -> digitalWrite(13, HIGH)
     20
     21
     22 NOTE: be sure to activate and configure restserver connector on Linino OS
     23  http://labs.arduino.org/Ciao
     24
    2025 created September 2015
    2126 by andrea[at]arduino[dot]org
    22  
     27
    2328 */
    24  
     29
    2530#include <Ciao.h>
    2631#include <Servo.h>
     
    3540void loop() {
    3641
    37   CiaoData data = Ciao.read("restserver");   
    38   if(!data.isEmpty()){ 
     42  CiaoData data = Ciao.read("restserver");
     43  if(!data.isEmpty()){
    3944    String id = data.get(0);
    4045    String sender = data.get(1);
    4146    String message = data.get(2);
    42    
     47
    4348    message.toUpperCase();
    44    
     49
    4550    String command[3];
    46          
     51
    4752    splitString(message,"/",command,3);
    4853    execute(command,id);
     
    7176void servoCommand(String cmd[], String id){
    7277   int pin, value;
    73  
     78
    7479  pin = (cmd[1]).toInt();
    75  
     80
    7681  if (cmd[2] != "-1") {
    7782    value = (cmd[2]).toInt();
     
    8590  }
    8691  else
    87     Ciao.writeResponse("restserver",id,"Invalid command"); 
     92    Ciao.writeResponse("restserver",id,"Invalid command");
    8893}
    8994
    9095void digitalCommand(String cmd[], String id) {
    9196  int pin, value;
    92  
     97
    9398  pin = (cmd[1]).toInt();
    94  
     99
    95100  if (cmd[2] != "-1") {
    96101    value = (cmd[2]).toInt();
     
    99104      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" ON");
    100105    else if(value == 0)
    101       Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");   
     106      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");
    102107  }
    103108  else if (cmd[2] == "-1") {
     
    111116
    112117  pin = (cmd[1]).toInt();
    113  
     118
    114119  if (cmd[2] != "-1") {
    115120    value =(cmd[2]).toInt();
     
    127132
    128133  pin = (cmd[1]).toInt();
    129  
     134
    130135  if (cmd[2] == "INPUT") {
    131136    pinMode(pin, INPUT);
Note: See TracChangeset for help on using the changeset viewer.