Hello,
I am attempting to upload a JPEG image from the SD card on my Wireless SD shield: (http://arduino.cc/en/Main/ArduinoWirelessShield)
I have the RN-XV WiFly module attached to this shield, with a high-gain 2.4 GHZ antenna.
My issue is that the image does not upload to a web browser. When I connect to the WiFly module via web browser, the module's LED suggest that it is sending the image to my computer, and the browser's address bar shows that it is receiving data. However, when the file transfer is complete, I get an icon showing a broken image.
Please help! Code below:
#include <SPI.h>
#include <WiFly.h>
#include <SD.h>
WiFlyServer server(80);
WiFlyClient client;
char* ssid = "Wingman007";
char* passphrase = "yellowlab";
const int chipSelect = 4;
int serverPort = 80;
boolean reading = false;
File dataFile;
void setup() {
Serial.begin(9600);
WiFly.setUart(&Serial);
WiFly.begin();
WiFly.join(ssid, passphrase);
Serial.println(WiFly.ip());
server.begin();
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
Serial.println("SD CARD INIITIALIZED");
}
}
void loop()
{
WiFlyClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
dataFile = SD.open("Deer2.jpg");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: image/jpeg");
client.println();
int16_t c;
while ((c = dataFile.read()) >= 0) {
client.print((char)c);
}
dataFile.close();
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
}
else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(10);
client.stop();
}
}