Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / WiFly JPEG Transmission Errors on: January 22, 2013, 09:07:47 am
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:

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();
         }
      }
    }
  }
}
2  Using Arduino / Programming Questions / Re: WiFly Wireless SD Shield Upload JPEG to Browser Issue on: January 21, 2013, 08:43:18 am
Thank you for the code Zoomkat! Still no success, however I did try it using the text/html content type which allowed me to see the JPEG characters. I compared them to the characters in the actual JPEG file (converted the .jpg to a .txt) and noticed that some spaces were missing from the transferred file. All of the characters where there in the correct order, however it looks like some <spaces>? were not correctly transferred (see attached image). The browser states "image contains errors".

Any additional information would be greatly appreciated. From what I have seen, the process after connecting to a client (web browser) should be:

  • Send new page header (HTTP OK)
  • Send content type (image/jpeg)
  • Open file on SD card
  • Print content of file to browser until the file is no longer available
  • Close file, close connection to client
3  Using Arduino / Programming Questions / Re: WiFly Wireless SD Shield Upload JPEG to Browser Issue on: January 20, 2013, 08:42:50 pm
Thank you for the code recommendations, I will include them in the future.

As far as the "Content-Length", I am not seeing success with that and I think I am not implementing it correctly. Here is the updated code:

Code:
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"); //open the JPEG image file on the SD card

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Length: 4656"); //future improvement to determine file length of any file. For now, I        know the size of this image file to be 4656 bytes.
          client.println("Content-Type: image/jpeg");
          client.println();
         
         //more header info here?

          while (dataFile.available()){ //future improvement to include reading 32 bytes at once
            client.print(dataFile.read());
          }
          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();
  }
}

Am I still missing header info? Am I placing the "Content-Length" in the wrong position?

Again, I simply want to open a JPEG file on the SD card through a web browser. I am able to get the WiFly to begin sending the file, and the browser begins to load it, but in the end I get a broken-image icon/"errors in the file". I can open and view this file directly through the SD card on my computer, so the file is not corrupt.

Thank you for the assistance!
4  Using Arduino / Programming Questions / Re: WiFly Wireless SD Shield Upload JPEG to Browser Issue on: January 20, 2013, 05:11:59 pm
Thank you for the reply PaulS.

Could you please elaborate on methods regarding the first issue (sending larger packets)? Any hints?

Regarding your second point, here is another method I have tried that yields the same results (no image in the web browser):

NEW METHOD:
while (dataFile.available()){
            client.print(dataFile.read());
          }

OLD METHOD:
int16_t c;
          while ((c = dataFile.read()) >= 0) {
            client.print((char)c);
          }

The NEW METHOD should read the information from the JPEG file until the file is not longer "available". Correct?

Is there anything wrong with this part of the code? Am I missing any header information?
  client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: image/jpeg");
          client.println();
5  Using Arduino / Programming Questions / WiFly Wireless SD Shield Upload JPEG to Browser Issue on: January 20, 2013, 04:50:58 pm
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();
  }
}
Pages: [1]