WIZnet Developer Forum

Does the HTTP webserver example actually work?

I do love this chip - add Ethernet without dictating choice of microcontroller. Opens up the low pin count / cost micros to Ethernet. Big plus.
But… I’m struggling with the code that comes with it. I keep on fixing things, each time I ask myself, surely I’m not the only one!

So, Where did I get the code from? - The W5500 product page:
http://www.wiznet.io/product-item/w5500/
Links to this code here:
https://github.com/Wiznet/ioLibrary_Driver/tree/master[details=Summary]

As way of example – it the first ‘issue’ I came across…
“The webserver will not serve out binary files - such as images”

There seems to be a problem in httpServer.c
The function :
Essentially, it reads information from the file system and passes out data as part of the HTTP response (body). It uses “web_content” - a table of files previously registered with reg_httpServer_WebContent.

uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size)
{
	uint16_t ret = 0;
	uint8_t * ptr;

	if(content_num > total_content_cnt) return 0;

	ptr = web_content[content_num].content;
	if(offset) ptr += offset;

	strncpy((char *)buf, (char *)ptr, size);
	*(buf+size) = 0; // Insert '/0' for indicates the 'End of String' (null terminated)

	ret = strlen((void *)buf);
	return ret;
}

The problem seems to be here… This statement aborts the copy if the .content buffer contains ‘\0’. Binary files have lots of these!
strncpy((char *)buf, (char *)ptr, size);
This line inserts a ‘\0’ char into the stream when reading a binary file outch
*(buf+size) = 0;

Once patched with this:

    uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size)
    {
    	uint16_t ret = 0;
    	uint8_t * ptr;
    	if(content_num > total_content_cnt) return 0;

    	ptr = web_content[content_num].content;
    	if(offset) ptr += offset;

    	memcpy (buf, ptr, size); // Do it properly.. *face palm*
    	return size; // this is a guess
    }

Hey presto, images come through…
Rather worried, I pressed on and carried on fixing / patching to the point where my page loads 4/5 times when I hit the refresh button. Works better on Chrome than IE. The cause of this is not so easy to find. Now I’m left having to digest long logic analyser SPI trace streams to start to find this one. Not something I really want to do…
So, before I do this, I thought I’d ask other members - why is it just me who is having these kinds of problems?? Have I gone to the wrong party? Can someone tell me where I’m supposed to be?? I’m not having a good time here…

Repository digging. There seems to different revisions of files used in different project… I’ve got very confused…
Just take httpServer.c I’m using for example:
https://github.com/Wiznet/ioLibrary_Driver/blob/master/Internet/httpServer/httpServer.c [link only]
Seems to be a different version from (committed on Mar 9)
https://github.com/Wiznet/WIZ550S2E/blob/master/WIZ550S2E_App/src/Internet/httpServer/httpServer.c [link only]
or from (committed 23 days ago)
https://github.com/Wiznet/WIZ550web/blob/master/WIZ550web_Firmware/WIZ550web_HW_Rev1.1/WIZ550web_App/src/Internet/httpServer/httpServer.c [link only]

That’s just main branch – is the party in a dev branch? I just don’t know anymore…
Clarification welcome…

On an additional note, I tried the mbed example. For me it just kept on getting stuck in polling loops buried in the http server code. This occurs when dealing with rapid page refreshes / ajax traffic. (Continuously polling status register not a good idea in event driven systems, especially when you poll for a state that will never occurs!)
As the mbed code is a bit more involved, after a few patches / fixes - I though id use the ioLibrary_Driver for a simpler solution. Now I’m here…
Note: Please keep this post to ioLibrary_Driver - I have abandoned mbed for now…
Thanks.

1 Like

Hello.


First of all, I apologize for making you confused.
You seem to have referred to three repositories.

You said that all three sources are different, but ioLibrary and WIZ550S2E use the same httpServer.c file.
I just recently made a commit because of other problems.

But the Web is clearly different.
This is because Web is a source written to operate as a WebServer.

As you say, ioLibrary’s functions are not made for images.
Therefore you should refer to WIZ550web.

For reference, please refer to the send_http_response_body () function in the link above.

I also think the Topic below will help.


And since you have been confused by ioLibary, I will discuss ioLibrary with my colleagues :slight_smile:

If you have any additional questions, please ask.


Thanks!
Best regard,
Kei.

1 Like

A follow up from my post…
WIZ550web has #defines to support filesystems - SD card, Dataflash and CODE FLASH.
Only the SD card option seems to be fully implemented.
In my implementation of CODEFLASH file server, in send_http_response_body() I was taking the file name from ‘uri_name’ and not from the HTTPSock_Status[get_seqnum].file_name.
I fixed this and it started working… (as was done when opening SD card files)

The bug report in the post above did not apply, because I re-wrote the HTTPSock_Status[get_seqnum].file_name to be a pointer to the filename in my table (not a memory buffer - thus saving 128 bytes RAM per file!)
See MAX_CONTENT_NAME_LEN

Yes.
Unfortunately, Only the SD card option is fully implemented.

You used a pointer approach.
I agree with your method for this part.
We will test it on our own and discuss whether to apply it to the next release.


Thank you for your feedback.

1 Like

We will test it on our own and discuss whether to apply it to the next release

Be careful, this works well when only using a static file system in CODE FLASH.
It will add complexity when mixing SD or DATA FLASH file because you need to ‘cache’ the filename.

2 Likes

Thank you for your advice.

As we go through the tests, I will refer to your topic.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.