RestService.cpp
/**
 * API GET, POST method to configure the power state of the LED controller
 */
API GET, POST method to configure the power state of the LED controller
API GET POST method to configure the power state of the LED controller
static void _handle_power(void){
  String message = "";
  bool set = false;
  int cmd = 0;
  if(server.method() == HTTP_POST){ 
    String power = server.arg("power");
    if(power != ""){
      if(power == "on"){
        state.power = power;
        set = true;
        cmd = LED_ON_CMD;
      }else if(power == "off"){
        state.power = power;
        set = true;
        cmd = LED_OFF_CMD;
      }else{
        message += "error: argument does not match expected";
      }
    }else{
      message += "error: argument expected";
    }
    if(set){
      message += "success";
    }
  }else{ 
    if(server.arg("documentation") == "true"){
      message += "IR Controlled LED Strip Web Service\n\n"
          "Power command expects POST request with a single arguement. "
          "The contents of this argument will be a string enumeration from "
          "table below.\n\n"
          "   String | Behavior\n"
          "   -------|-------------------------------------\n"
          "   on     | Commands LED controller to ON state \n"
          "   off    | Commands LED controller to OFF state\n";
    }else{
      message += "power: " + state.power;
    }
  }
  server.send(200, "text/plain", message);
  state.uri = server.uri();
  if(set){
    led_send_value(cmd);
    state.raw = cmd;
  }
}
static void _handle_power ( void ) { String message = " " ; bool set = false ; int cmd = 0 ; if ( server . method ( ) == HTTP_POST ) { String power = server . arg ( " " ) ; if ( power != " " ) { if ( power == " " ) { state . power = power ; set = true ; cmd = LED_ON_CMD ; } else if ( power == " " ) { state . power = power ; set = true ; cmd = LED_OFF_CMD ; } else { message += " " ; } } else { message += " " ; } if ( set ) { message += " " ; } } else { if ( server . arg ( " " ) == " " ) { message += " \n \n " " " " " " \n \n " " \n " " \n " " \n " " \n " ; } else { message += " " + state . power ; } } server . send ( 200 , " " , message ) ; state . uri = server . uri ( ) ; if ( set ) { led_send_value ( cmd ) ; state . raw = cmd ; } }
API GET, POST method to configure the power state of the LED controller
API GET POST method to configure the power state of the LED controller
// update power state // report power information // Transmit over IR LED