Sending file/image from SD to server via Wifi Shield

Hi, guys I have a problem that I seeked answers for a couple of weeks and could not find some some concrete answers except one but did not work for me.

Here's what I want to do:

  • Capture an image from and ArduCAM (done)
  • Save it to SD Card(done)
  • Send the image taken to the database via Wifi with the Wifi Shield CC3000
  • Receive the data and save it to a temporary folder thru PHP

I have found this thread on the forums and tried it but failed.

http://forum.arduino.cc/index.php?topic=348012.0

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include<stdlib.h>
#include <SD.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10

// WiFi network (change with your settings !)
#define WLAN_SSID "mywirelessnetwork"
#define WLAN_PASS "mypassword"
#define WLAN_SECURITY WLAN_SEC_WPA2


// Create CC3000 instances
// WIFi setup
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIV2);
Adafruit_CC3000_Client client;

char filename[14] = "CAM1.jpg";
int i = 0;
int keyIndex = 1;
int port = 80; //Server Port
uint32_t MANip = 0;

void setup() {

  Serial.begin(115200);

  // Initialise the module
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin()){
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }


  // Connect to WiFi network
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected!"));

  // Display connection details
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP()){
    delay(100);
  }
  Serial.println("Ready");
 Serial.println("-------");

 //Get MAN IP address

  getMANip();


  // Prepare HTTP request
  String start_request = "";
  String end_request = "";
  start_request = start_request + "\n" + "--AaB03x" + "\n" + "Content-Disposition: form-data; name=\"fileToUpload\"; filename="+filename+"\n" + "Content-Type: file" + "\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n";
  end_request = end_request + "\n" + "--AaB03x--" + "\n";



  //Initialise SD Card
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization of SD done.");
 
 File myFile = SD.open("CAM1.jpg");
  uint16_t jpglen = myFile.size();
  uint16_t extra_length;
  extra_length = start_request.length() + end_request.length();
  uint16_t len = jpglen + extra_length;

  // Set up TCP connection with web server
  client = cc3000.connectTCP(MANip, port);


 
  if (client.connected()) {
    Serial.println("Start uploading...");

    client.println(F("POST /~modelavi/plugins/upload.php HTTP/1.1"));

    client.println(F("Host: www.modelaviationnorthland.co.nz"));
    client.println(F("Content-Type: multipart/form-data; boundary=AaB03x"));
    client.print(F("Content-Length: "));
    client.println(len);
    client.println(start_request);

    Serial.println(F("Host: www.modelaviationnorthland.co.nz"));
    Serial.println(F("Content-Type: multipart/form-data; boundary=AaB03x"));
    Serial.print(F("Content-Length: "));
    Serial.println(len);
    Serial.println(start_request);
 
 if (myFile) {
  byte clientBuf[32];
  int clientCount = 0;

  while(myFile.available())
  {
    clientBuf[clientCount] = myFile.read();
    clientCount++;

    if(clientCount > 31)
    {
      client.write(clientBuf,32);
      clientCount = 0;
    }
  }
  if(clientCount > 0) client.write(clientBuf,clientCount);

  client.print(end_request);
  client.println();
  }
  else{
       Serial.println("File not found");
      }
  }   
  else{
    Serial.println("Web server connection failed");
  }
 
  myFile.close(); 
  client.close();
 
  Serial.println("done...");

 
}

void loop() {



delay(10000);

}


void getMANip(){
#ifndef CC3000_TINY_DRIVER
  /* Try looking up www.modelaviationnorthland.co.nz */
    //Serial.print(F("www.modelaviationnorthland.co.nz -> "));
  while  (MANip  ==  0)  {
    if  (!  cc3000.getHostByName("www.modelaviationnorthland.co.nz", &MANip))  {
      //Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  } 
  //cc3000.printIPdotsRev(MANip);
#endif
}

Here's the code but I got stuck on "Start uploading..." as I check on the Serial monitor.

  • Anybody has a solution on this?
  • Or anybody has some other way to send the image taken to the server?

The below code is for use with the w5100 ethernet shield, but you might trry incorporating some of its actions into your code.

//zoomkat 4-1-12
//Simple browser file upload from the SD card
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of " 
//click in the below LAN url to test
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  digitalWrite(10,HIGH);

  //delay(2000);
  server.begin();
  Serial.println("Ready");

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: image/jpeg");
          client.println();

          File myFile = SD.open("HYPNO.JPG");
          if (myFile) {
            //Serial.println("test.txt:");
            // read from the file until there's nothing else in it:
            while (myFile.available()) {
              client.write(myFile.read());
            }
            // close the file:
            myFile.close();

          }
            delay(1);
            //stopping client
            client.stop();
            readString="";
          //}
        }
      }
    }
  } 
}

how can i receive the from when it is sent to the webserver? is it the same as on the link above for the php code? if not can you post some sample codes for me to try? thanks btw for the answer

hello! macoy-marc
Are you done yet
can you send code for me?
thanhks you verry much

hello! macoy-marc
Capture an image from and ArduCAM (done)
Save it to SD Card(done)
SEND CODE FOR ME?PLEASE ...THANKS YOU

Hi team, can somebody share a working code for this? I haven't been able to make it work....