ArduCAM / ArduCAM_ESP8266_UNO

This Arduino IDE for ArduCAM ESP8266 UNO Board with Integrated ArduCAM Library and Examples
GNU Lesser General Public License v2.1
82 stars 45 forks source link

Post Image to Server #4

Open ghost opened 7 years ago

ghost commented 7 years ago

Description

How to send capture image to my server ?

Sketch


void camCapture(ArduCAM myCAM){
  //WiFiClient client = server.client();
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
  }
  size_t len = myCAM.read_fifo_length();
  if (len >= 0x07ffff){
    Serial.println("Over size.");
    return;
  }else if (len == 0 ){
    Serial.println("Size is 0.");
    return;
  }

  myCAM.CS_LOW();
  myCAM.set_fifo_burst();
  #if !(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM))
  SPI.transfer(0xFF);
  #endif
  //if (!client.connected()) return;
  String response = "POST /api/device/image HTTP/1.1\r\n";
  response += "Content-Type: image/jpeg\r\n";
  response += "Content-Length: " + String(len) + "\r\n\r\n";
  //server.sendContent(response);

  Serial.println("conected to the server");
  client.println(response);

  static const size_t bufferSize = 4096;
  static uint8_t buffer[bufferSize] = {0xFF};

  while (len) {
      size_t will_copy = (len < bufferSize) ? len : bufferSize;
      SPI.transferBytes(&buffer[0], &buffer[0], will_copy);
      if (!client.connected()) break;
      client.write(&buffer[0], will_copy);
      len -= will_copy;
  }

  myCAM.CS_HIGH();
}
dprophet commented 7 years ago

if (!client.connect(host, httpPort)) {

to

if (!client.connect("yourserver.com", httpPort)) {