Go Down

Topic: WiFly JPEG Transmission Errors (Read 514 times) previous topic - next topic


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: [Select]

#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() {
  WiFly.join(ssid, passphrase);
  pinMode(10, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:

    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");

          if (myFile) {
            while (myFile.available()) {
            //stopping client


Try sending plain text, or a sequence of bytes from 0 to 255, then in a hex editor you can see the missing byte value ( notepad is no good for binary data ).
Or maybe there is some control codes the wifly library uses, check the documentation.
Forum Mod anyone?


Given that the error can be seen early in the transfer, I suggest you modify your sketch to print a hex representation of the bytes you're writing to the HTTP stream, so that you can compare the byte sequence your sketch supplies against the byte sequence received at the browser. If the two differ, I'd use Wireshark or similar to find whether the 'missing' bytes got as far as the network.

Go Up