Pages: [1] 2   Go Down
Author Topic: Serve graphics with Eithernet Uno?  (Read 1520 times)
0 Members and 1 Guest are viewing this topic.
Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Should I be able to serve .jpg files? I can send text no sweat but jpg files just grind and grind and eventually time-out.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 654
Posts: 50956
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Should I be able to serve .jpg files?
But of course. A jpg file is just a binary data file. Nothing magic about it.

Quote
I can send text no sweat but jpg files just grind and grind and eventually time-out.
So, you can store text in SRAM and send it. Where are you storing this jpg file? There is only 2K of SRAM on most Arduinos. Hardly enough to store any data that will take any time at all to send.

Most likely, its a coding issue. Hint, hint.
Logged

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the SD card. No shortage of room.

I send an html header & file and it works fine. Send a jpg header and file and it doesn't work.
« Last Edit: April 11, 2012, 03:20:00 pm by TheNorm » Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Better take PaulS's hint and show your code, huh?
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I snipped out the relevant stuff.

The jpg is 35.5 KB.

Here's the calling code...
 if (strcmp(ext,"jpg")==0){
    sendHeader("jpg.hdr", client;
    sendFile(parameter, client);
    return;
  }


Here's the text from the file jpg.hdr
HTTP/1.1 200 OK
Content-Type: image/jpeg


Code to send header...
void sendHeader(char *fileName, EthernetClient *client){  // no CGI parsing
  DEBUG_PRINTLN("sending header " << fileName << "\n\n" );
  sendFile(fileName,client);
  client->print ("\n\n");  // terminator for http headers
}


Code to actually send...
void sendFile(char *fileName, EthernetClient *client){
  DEBUG_PRINTLN("sending file " << fileName << "\n" );
  File source = openFile(fileName);
  while (source.available()) {
    byte byt = source.read();
    client->write(byt);
  }
  source.close();
}



« Last Edit: April 17, 2012, 02:49:25 am by TheNorm » Logged

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this thread dead for some reason?
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1. What does the debugging show?

2. Can you use code tags to post code? You can do that by hitting the # button above the posting area.

3. After this line:

Code:
 File source = openFile(fileName);

You don't check if the file opened OK. If not (and source is not open) then the program will likely hang.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. What does the debugging show?

2. Can you use code tags to post code? You can do that by hitting the # button above the posting area.

3. After this line:

Code:
 File source = openFile(fileName);

You don't check if the file opened OK. If not (and source is not open) then the program will likely hang.

"openFile(fileName)" has error checking built in. Currently it prints an error msg and loops forever.

Code:
Ok. I'll do this in the future.

As far as I can tell this code is ok and it sends html just fine.

The debug output just says "sending header  htm.hdr" and  "sending file index.htm"  and then when the client asks for the graphics... ""sending header  jpg.hdr" and  "sending file test.jpg"  but the graphics never arrive.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm- are you base64 encoding the graphics file?
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You might be sending too fast and overflowing the buffer. Try putting in a delay inside the client write loop.
Logged

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm- are you base64 encoding the graphics file?

It's just a jpg file created in Photoshop that I copied to the SD card. I didn't do anything to it. I don't understand the question. It sounds like I may be missing a whole topic here. What's base64 encoding? Why would anyone do anything in base 64? Is there something I should have read?

Logged

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might be sending too fast and overflowing the buffer. Try putting in a delay inside the client write loop.

Tried that.
Thanks
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What's base64 encoding? Why would anyone do anything in base 64? Is there something I should have read?

Yesss.

http://en.wikipedia.org/wiki/Base64

Your original question:

Quote
Should I be able to serve .jpg files?

... was perhaps a bit vaguely worded. You can send any file you like, but the HTTP transfer protocol is basically text. You can send other things, but they are usually base-64 encoded, which effectively turns them into text.

I suppose we assumed that since you are generating HTML pages you might know that. Ah well.

Basically you run the file (in batches) through the base64-encoder, which makes it 4/3 times larger. I think you usually do the data in batches of around 57 bytes which become 76 bytes when encoded (ie. the length of a line in an email message).

You will also need to look at the header, I think you need to tell the browser that the text is base64-encoded.

Something like this line in addition to what you have:

Code:
Content-Transfer-Encoding: base64

An example, from an email I got:

Code:
Content-Type: image/png;
name="image001.png"
Content-Transfer-Encoding: base64
Content-ID: <image001.png@01CD20C6.92DC0A80>

iVBORw0KGgoAAAANSUhEUgAAAoAAAAPACAYAAACl4sj7AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA/45JREFU
eF7sfQWYXdW5dv7/v6XtvXWlSItDaYFCW2rU/daNGhUoUqS4exIsBEhCQoQQd3d318lkfDIT9yBB

Something roughly along those lines. Look it up, there will be lots of references. And you should find a base-64 encoding function easily enough.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Santa Cruz California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
"When I hear of Schrödinger's cat, I reach for my gun " (Stephen Hawking)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick.

Sigh. I think I'll just eliminate graphics from my server. It's not critical and the thing is already too fat. More code is not the way to go and I don't care for the idea of pre-converting the files.
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, image files are not base64 encoded in normal HTTP transmissions. Mail messages with MIME attachments are a completely different animal.

Example for a random 1x1 pixel image on yahoo.com; the image data is on the last line and the "GIF89a" header present in any gif image is clearly visible, unencoded.

root@zygot:~# telnet l.yimg.com 80
Trying 98.137.80.49...
Connected to fo-anyycs-l.ay1.b.yahoodns.net.
Escape character is '^]'.
GET /a/i/mntl/ww/events/p.gif HTTP/1.0
Host: l.yimg.com

HTTP/1.0 200 OK
Date: Wed, 25 Apr 2012 19:02:39 GMT
Cache-Control: max-age=315360000
Expires: Sat, 23 Apr 2022 19:02:39 GMT
Last-Modified: Tue, 05 Oct 2010 18:34:21 GMT
Accept-Ranges: bytes
Content-Length: 43
Content-Type: image/gif
Age: 14636
Server: YTS/1.20.14

GIF89aÀÀÀ!ù,D;
Logged

Pages: [1] 2   Go Up
Jump to: