I am trying to upload a JPEG image stored on a Wireless SD card shield to a web browser using a WiFly module with the XBEE footprint. The module sends the image data, however it seems to be missing some <space> or NULL characters (see image below). The file "HYPNO" is the original JPEG file (opened as a text file to visualize), then the "TRANSFERRED HYPNO" is what the WiFly sent to the web browser (I used text/html to get these characters). When I use content-type "image/jpeg" the browser says "error in the image file", and you can clearly see spaces missing in the file.
How do I get the WiFly to send these missing "spaces"? Am I setting up my WiFly serial correctly? I have seen many examples online that work for people, so I have a feeling I am missing something simple.
Any help is greatly appreciated!
Code:
#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;
void setup() {
Serial.begin(9600);
WiFly.setUart(&Serial);
WiFly.begin();
WiFly.join(ssid, passphrase);
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) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n'){
File myFile = SD.open("HYPNO.JPG");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: image/jpeg");
client.println();
if (myFile) {
while (myFile.available()) {
client.write(myFile.read());
}
myFile.close();
}
delay(1);
//stopping client
client.stop();
}
}
}
}
}