src/httpd.cpp
/**
 * @brief Handles tank control x and y axis and generates PWM output on the motors
 *
 * @param req
 * @return esp_err_t
 */
@brief Handles tank control x and y axis and generates PWM output on the motors
@param req
@return esp_err_t
@brief Handles tank control x and y axis and generates PWM output on the motors @param req @return esp_err_t
static esp_err_t cmd_handler(httpd_req_t *req)
{
    char *buf; 
    size_t buf_len;
    char r_x[5] = {'\0'}; 
    char r_y[5] = {'\0'}; 
    buf_len = httpd_req_get_url_query_len(req) + 1;
    if (buf_len > 1)
    {
        buf = (char *)malloc(buf_len);
        if (!buf)
        {
            httpd_resp_send_500(req);
            return ESP_FAIL;
        }
        if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK &&
            httpd_query_key_value(buf, "x", r_x, sizeof(r_x)) == ESP_OK &&
            httpd_query_key_value(buf, "y", r_y, sizeof(r_y)) == ESP_OK)
        {
            last_control_request = esp_timer_get_time();
            int x = atoi(r_x);
            int y = atoi(r_y);
            mc_motor_set_speed(&motor_l, y + x);
            mc_motor_set_speed(&motor_r, y - x);
        }
        else
        {
            free(buf);
            httpd_resp_send_404(req);
            return ESP_FAIL;
        }
        free(buf);
    }
    else
    {
        httpd_resp_send_404(req);
        return ESP_FAIL;
    }
    httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
    return httpd_resp_send(req, NULL, 0);
}
static esp_err_t cmd_handler ( httpd_req_t * req ) { char * buf ; size_t buf_len ; char r_x [ 5 ] = { ' \0 ' } ; char r_y [ 5 ] = { ' \0 ' } ; buf_len = httpd_req_get_url_query_len ( req ) + 1 ; if ( buf_len > 1 ) { buf = ( char * ) malloc ( buf_len ) ; if ( ! buf ) { httpd_resp_send_500 ( req ) ; return ESP_FAIL ; } if ( httpd_req_get_url_query_str ( req , buf , buf_len ) == ESP_OK && httpd_query_key_value ( buf , " " , r_x , sizeof ( r_x ) ) == ESP_OK && httpd_query_key_value ( buf , " " , r_y , sizeof ( r_y ) ) == ESP_OK ) { last_control_request = esp_timer_get_time ( ) ; int x = atoi ( r_x ) ; int y = atoi ( r_y ) ; mc_motor_set_speed ( & motor_l , y + x ) ; mc_motor_set_speed ( & motor_r , y - x ) ; } else { free ( buf ) ; httpd_resp_send_404 ( req ) ; return ESP_FAIL ; } free ( buf ) ; } else { httpd_resp_send_404 ( req ) ; return ESP_FAIL ; } httpd_resp_set_hdr ( req , " " , " " ) ; return httpd_resp_send ( req , NULL , 0 ) ; }
@brief Handles tank control x and y axis and generates PWM output on the motors
 @param req
 @return esp_err_t
@brief Handles tank control x and y axis and generates PWM output on the motors @param req @return esp_err_t
// buffer to save the query string // Received joystick value for tank X axis // Received joystick value for tank Y axis // Serial.printf("Received x: %d, y: %d, l: %d, r: %d\n", x, y, y + x, y - x);