Page 1 of 1

ENC28J60 WEBserver and FAT SD card

Posted: Fri Dec 02, 2016 12:09 pm
by radist73
Hi all,
I am trying to start a WEB server with graphical objects stored into SD card.
Web server works fine, SD card initialized and jpg file opened (return 0) but what is the way to jpg file in html code?
img src=file.jpg not working

Thanks!

Re: ENC28J60 WEBserver and FAT SD card

Posted: Tue Dec 06, 2016 12:51 pm
by radist73
Could any help?
How I can make in HTML code link to picture stored in SD card?

Re: ENC28J60 WEBserver and FAT SD card

Posted: Tue Dec 06, 2016 1:13 pm
by Benj
Hello,

I believe a html web server works like this.

First the client requests the webpage html code using a GET command.

Code: Select all

GET index.htm
The HTML code may contain a reference to an image but first all the HTML code is transferred to the client.

Code: Select all

<img src="pics/image.jpg" />
The client then requests all the associated files referenced in the HTML e.g. the image file using more GET commands.

Code: Select all

GET pics/image.jpg
So you basically have to look out for the GET command and then action the get request by going to the right directory on the SD card, opening the file specified and then streaming back the contents of the file.

Re: ENC28J60 WEBserver and FAT SD card

Posted: Tue Dec 06, 2016 8:55 pm
by radist73
Benj wrote:

Code: Select all

GET pics/image.jpg
So you basically have to look out for the GET command and then action the get request by going to the right directory on the SD card, opening the file specified and then streaming back the contents of the file.
But what is the right directory?
For example, in Windows Android phone sd card directory is F:/, but the same directory in Android is /SDCARD/

In this case, index.htm file is saved in pic internal memory, and pictures saved in external memory (sd card)

Attached example is edited example from Wiki

Thanks!

Re: ENC28J60 WEBserver and FAT SD card

Posted: Wed Dec 07, 2016 10:46 am
by Benj
I would do it so that everything is saved on the SD card HTML files and all. This is how a webserver works. I've been meaning to generate something like this for a while.

The actual directory doesn't matter as long as the files and folders can be fetched from that directory.

For example I would create a folder on the SD card say called website and in here I would place all the various files.

On a PC this would look like this. "F:/Website/Index.htm"

On an Android phone it might look like this. "/SDCARD/Website/Index.htm"

The GET request would probably look like this. GET index.htm and it's the webserver that knows which folder the files live in.

For simplicity remember to keep your filenames to within the 8.3 simple filename format or you'll run into issues of not being able to find the files you need.

This article may be useful. http://www.matrixtsl.com/article.php?a=672

Re: ENC28J60 WEBserver and FAT SD card

Posted: Wed Dec 07, 2016 3:22 pm
by radist73
Thanks, I try to check it.
But next problem for me, if I make index.htm and put it into SD card, how I can insert values of variables from pic flowchart to index.htm text? For example "System voltage = 24,52 Volts", where 20,52 is value of variable.

Re: ENC28J60 WEBserver and FAT SD card

Posted: Wed Dec 07, 2016 3:27 pm
by Benj
Good question. The way we do this in the current webserver examples is to use the % character.

The code that is taking bytes from the FAT file and sending them to the comms network should be on the lookout for the '%' character. If it finds it then the character after the symbol will be the index of the variable to send out.

If you actually need to send a % symbol in the HTML then put two next to each other in the HTML code %%.

Code: Select all

byte = ReadByteFromFile
if (byte = '%')
{
	byte2 = ReadByteFromFile
	if (byte2 = '0')
	{
 		str = ToString$(Var0)
		CommsSendString (str)
	}
	if (byte2 = '1')
	{
 		str = ToString$(Var1)
 		CommsSendString (str)
	}
	if (byte2 = '%')
	{
		CommsSendByte ('%')
	}
}
else
{
	CommsSendByte (byte)
}