Page 1 of 1

Add Another Command to arduino-esp32 CameraWebServer Example

Posted: Mon Feb 04, 2019 9:42 pm
by xgarbxgarb
I've added another url to listen for to the startCameraServer function from here:

https://github.com/espressif/arduino-es ... _httpd.cpp

The code that is called with the URL looks like this:

Code: Select all

static esp_err_t servo_handler(httpd_req_t *req) {

  panServo.attach(12);  // attaches the servo on pin xx to the servo object
  tiltServo.attach(13);

  char*  buf;
  size_t buf_len;
  char panDegrees[32] = {0,};
  char tiltDegrees[32] = {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) {
      if (httpd_query_key_value(buf, "pan", panDegrees, sizeof(panDegrees)) == ESP_OK &&
          httpd_query_key_value(buf, "tilt", tiltDegrees, sizeof(tiltDegrees)) == ESP_OK) {
      } else {
        free(buf);
        httpd_resp_send_404(req);
        return ESP_FAIL;
      }
    } else {
      free(buf);
      httpd_resp_send_404(req);
      return ESP_FAIL;
    }
    free(buf);
  } else {
    httpd_resp_send_404(req);
    return ESP_FAIL;
  }

  int panValue = atoi(panDegrees);
  int tiltValue = atoi(tiltDegrees);
  panServo.write(panValue + 90);
  tiltServo.write(tiltValue + 90);

  Serial.print("Pan: ");
  Serial.println(panValue);
  Serial.print("Tilt: ");
  Serial.println(tiltValue);

  return httpd_resp_send(req, NULL, 0);
}
When I try a URL like /update-position?pan=10&tilt=20 the video stream crashes

It works when I comment out attach(xx) lines. Is this because I'm using pins that are assigned in the hardware for the SD card reader?
ai-thinkerpins.jpg
ai-thinkerpins.jpg (64.06 KiB) Viewed 3068 times
There aren't any pins on the board that aren't assigned to the camera or SD card except the TX and RX pins.