HTTP Server

15 Oct 2009

Hi,

I'm trying to experiment with mbed as a web server and client. I'm using the sample HTTP Server (http://mbed.org/projects/cookbook/wiki/EMAC), but can't get it any response from the my mbed web server. I see the server outputting it's IP address on the serial terminal - 192.168.1.66 - which looks promising and presume this indicates that my ethernet connection is good. I've placed a simple html file 'index.htm' on the mbed flash drive and tried browsing to http://192.168.1.66 the browser eventually times-out. I've also tried:  http://192.168.1.66/rpc/led1/write+1 again the browser times-out and no LEDs change on the board.

Is it possible to look at the source for the lwip library and add debugging code. Any other ideas how I can debug this.

Thanks

Nick

15 Oct 2009

Hi Nick,

You can find the code in the SVN under http://mbed.org/projects/cookbook/svn/EMAC/lwip/trunk.

Just import as a File instead of as a Library.

I really cannot see from your description where the bug is but if I were you I would start in HTTPServer.cpp and HTTPRPC.h.

Let me know if you find anything out.

Regards

Rolf

Hey Nick,

Make sure your router isn't blocking port 80 requests or port-forwarding it to another computer.

Download and install a net packet monitor like ethereal - it will let you see where the packets are going.

Scott

16 Oct 2009 . Edited: 16 Oct 2009

Hi *,

I've used Wireshark (http://www.wireshark.org/) quite a lot. It's really helpful to see what goes over the wire.

But it does not help you to see what really goes through the IP stack.

For this I've wrote a little hex viewer, you can find it here: http://mbed.org/projects/cookbook/wiki/TipsAndTricks

It might not only be useful for network issues ;-)

Regards

Rolf

 

16 Oct 2009

Hi

Thanks for the replies. I will try something like wireshark or the hex viewer - I monitored what was happening with firebug and saw no replies - but I probably need to look at a lower level.

Rolf, I imported the source code as you suggested from: http://mbed.org/projects/cookbook/svn/EMAC/lwip/trunk, but now get linker errors such as:

"Symbol mbed::TCPConnection::TCPConnection_sub_object(ip_addr, unsigned short) multiply defined by (TCPConnection.o and TCPConnetion.o). (EL6200E)"

[BTW I had a manually type that in as copy doesn't appear to work in Safari on the MacOS10.6.1]

I downloaded the source code (export project) and grepped for TCPConnection. Found the constructors, but couldn't see any multiple definitions. I'm probably missing something simple. Any thoughts?

Thanks again

Nick

16 Oct 2009

Hi

Yes, I’ve forgot to tell that you have to delete the lwIP library from your tree view.

My guess is that you have at the moment two times the object file included. First one is in the library and the second one is in the imported files in your project tree view.

By the way, what is your hardware setting? Do you use a router? (Which one?) Is your computer directly connected to the router (wire or wifi)? ...

Have you tried to use <cmd+c> (or whatever the equivalent on Mac for <ctrl+c> is)? If not does it work?

Regards

Rolf

16 Oct 2009

Hi Rolf,

I imported the source into a new project so lwIP library doesn't exist in that project. I'm sure it's something simple, but at the moment I'm mystified.

I plugged the mbed board into my router with is supplied by 02 (not sure who the manufacturer is) and my laptop is connected via wifi.

<cmd+c> <ctrl+c> right click select copy from the menu don't appear to work

Cheers

Nick

16 Oct 2009

Sorry my fault.

The Import Files dialog works different from the Import Library dialog.

I was experimenting with chained includes in the SVN what was not working on import Library. But it seems to be working if you import Files (Good to know). So well, if you go to the HTTPServer and HTTPClient directories and delete the Core Libraries, it should work.

Does the HTTPClient work on your mbed?

Regards

Rolf

19 Oct 2009

Hello again,

I'm making progress. I deleted the Core Libraries from the HTTPServer and HTTPClient and the code compiled and linked. I then scattered printfs in throughout HTTPServer.cpp, without success. Then I placed a printf in the polling loop as:

while(1) { http.poll(); printf("polling\n"); }

and suddenly it began to work. I could browse index.htm and set LEDs on the board. Commenting out the printf line, stopped the server from responding. This was on MacOSX 10.6.1. Another bizarre side-effect was after an http request, the OS reported that the that the MBED flash drive had been unplugged  I then rebooted under Windows and the webserver worked as advertised, with or without the extra printf in the polling loop.

Finally I'm using a different pin-out for my RJ45 connection than that documented at: http://mbed.org/projects/cookbook/wiki/EMAC

I'm using:

1 TX+, 2 TX-, 3 RX+, 6RX-

whereas the MBED cookbook states:

1 RX+, 3RX-, 4TX-, 6TX+

Yours bemused,

Nick

19 Oct 2009

Hi Nick,

Great to hear something is happening, but does sound like there is a little more to investigate. I'll leave the exploration of the HTTPServer to you and rolf (maybe test using different browsers/platforms and identify what stack level/differences the server is not handling well), but as to your other comment:

Nick Ager wrote:
Another bizarre side-effect was after an http request, the OS reported that the that the MBED flash drive had been unplugged

Just to clarify, this may seem bizarre, but actually has a perfectly rational explanation :)

When you request a page, the http server will then go to read that page from the local USB filesystem. When it does this, the mbed interface has to *steal* it from the connected PC as you can't have two masters at once (see http://mbed.org/handbook/LocalFileSystem for more details). The PC will therefore see it as being unplugged.

Assuming you are running the newest firmware, once it has read this file and closed it, the drive should re-appear. If it is older firmware, it'll hang on to it until it exits/you hit reset (see http://mbed.org/handbook/Firmware). Either way, on mac you'll also get a warning message (something like "you've been naughty and taken away a storage basket without tucking it in and saying goodnight"); you can basically ignore that.

Hopefully this makes it more clear what is going on here.

Simon

19 Oct 2009

Nick,

Just a newbie to mBed but I noticed your RJ45 connections. I think that the connections maybe reversed when connecting the mbed to a PC as opposed to a router. That is TX and RX reversed. Not sure which is the right way around but they are different.

 

Regards

Paul

19 Oct 2009 . Edited: 19 Oct 2009

Hey,

Im also having similar issues and cannot connect to the internet. Here is my wiring just to make sure that is not wrong.

I have just imported the twitter example from the cookbook and used my username and password but no message on twitter.

Any ideas what it could be. I have checked the wire and there is internet connected.

19 Oct 2009 . Edited: 19 Oct 2009

d

19 Oct 2009

Hi,

Just to be clear - I'm connecting to a router, so I'm not trying to create a cross-over cable. The connections which work for me are: 1 TX+, 2 TX-, 3 RX+, 6RX-

Vlad, do you see any output on your serial monitor? It should report it's IP address if it manages to obtain it via DHCP - at least that's my understanding of what I'm seeing.

Nick

20 Oct 2009

Nope, no output on the serial monitor, I have tried twitter and the http client examples, but nothing, is there suposto be a index.html file on the mbed?

20 Oct 2009

Hi Vlad,

I haven't tried the http client samples; I'm using the http server sample. In that case it will serve up index.htm when you browse to http://192.168.1.67  or whatever the IP of your mbed device is. Have you put an index.htm on your flash drive? From your photo it looks like you're connecting to pins 1,3,4,6 of your RJ45 lead. This matches the docmentation here http://mbed.org/projects/cookbook/wiki/EMAC, but didn't seem to work for me,

Good luck

Nick

20 Oct 2009 . Edited: 20 Oct 2009

 

Hi all,

The client will give out its IP as well.

Nick, it's interesting that a different pin configuration works for you. What network plug are you using?

Vlad, it looks like you get no IP address. Are you using a  MagJack SI-60002-F? I had some different kinds of network plugs to test it seems that they all are different with the pinout. That’s why I’m explicit described this model. But as soon as you get an IP address, the plug might not be the problem anymore.

Do you all use plugs with included magnetics? I've didn't experiment a lot without magnetics but I’m pretty sure the absence of magnetics does not make the connection better.

Regards

Rolf

 

20 Oct 2009

Hello again,

Unfortunately the mbed file system does only allow access to 8.3 (old dos) file names. Therefore the index page on the mbed is called index.htm and not index.html.

Another which is normally requested by the browser but not necessarily required is favicon.ico. If this file is not found I've send back "HTTP 404 File not Found" what should be enough but maybe there is some space to confuse the browser.

The favicon.ico should be an icon file or a PNG/GIF with 32x32 or 64x64 in size (http://en.wikipedia.org/wiki/Favicon).

Cheers

Rolf

20 Oct 2009

Hi Rolf,

I just desoldered an RJ45 connector from an old ADSL modem. A google search for RJ45 pinout brought me to http://www.nullmodem.com/RJ-45.htm.

Any thoughts on the odd behaviour under MacOSX ie requiring the printf in the polling loop?

Cheers

Nick

20 Oct 2009

Hi Nick,

If you have a look here, you can see that the connector I've used has some internal magnetics (MagJack SI-60002-F). And I've had some others with internal magnetics like tyco 1-6605834-1 which is part of the bob-board and a MagJack SI-60008-F which was not working for me at all, and I didn't find a datasheet.

So there can be internally completely different. I guess your connector is without any magnetics, but it's just a guess.

 

I guess it's a timeout problem. lwIP is counting Timeouts in passes.

A printf is very slow. To verify you can try to put a wait(0.1) instead the printf.

 

Which Browser are you using under Windows?

Do other browsers work as well?

Which mbed Board do you have?

Is there a product number on the connector?

 

Cheers

Rolf

21 Oct 2009

Hi,

It may be worth putting together a simple "sanity check" application to just checks/diagnose ethernet connectivity. I know there are lots of different setups out there e.g. some hubs/switches support internal auto-crossover, some don't.

Would be good to be able to tick off "my h/w connection is correct" vs "my big complicated http/tcp/ip/dhcp stack is working". Think of it as an ethernet "Hello World".

Simon

21 Oct 2009

I have found the data-sheet for my rj45 jack. It is part number - PRT-08534 from sparkfun:

http://www.sparkfun.com/datasheets/Prototyping/MagJack.pdf

It looks as tho the pin configurations are a bit different but I am not sure, can anyone confirm this?

21 Oct 2009

Hi Vlad,

your right the configuration is different. For this part here (SparkFun PRT-08534) your pin configuration is:

                Bottom view
RD+ 	= 1     +----------+
RD- 	= 2     |  2 4 6 8 |
TD- 	= 7     | 1 3 5 7  |
TD+ 	= 8     |+        +|
                |          |
                | Front    |
                | vvvvvvvv |
 

If you have a look here: http://mbed.org/handbook/Ethernet

The example should print you any packet on the wire. This might be usable as a test, if you use for lot of broadcast packets.

On the other hand I have this. It sends out lots of packets. You can detect them with Wireshark or Etherreal.

Regards

Rolf

21 Oct 2009 . Edited: 27 Oct 2009

Hi Everyone,

I was talking to Rolf earlier about how all RJ45 connectors seem to have different pinouts for thier PCB connection, and how it introduces uncertainly for bringing up new experiments.

Then I remembered that in the early days of mbed we were a little more gung-ho with stuff like this, and one preferred method was the (destructive) reuse of cheap off the shelf cables.

In the spirit of Simons suggestion of testing one thing at a time, you could start by testing your conenction without having an RJ45 connector to confuse things.

So, you know what pins are what on the mbed Micrcocontroller, and the actual RJ45 contacts are well defined, as are the colour codes of the cores in CAT5 cable.

So:

1. Cut a perfectly good working CAT5 cable in half.

2. Refer to the pinout/wiring spec for CAT5 cables, or some useful webpage like :

3. Strip back the relevent cores (Green, Green/White, Orange, Orange/White) and stick them in your bread board to connect to the mbed Microcontrollers RD+/-, TD+/- pins as appropriate. Hey presto, the RJ45 socket is out of the equation, and you are now wired for ethernet.

SUGGESTION: keep the length of CAT5 cable form your mbed to you hub/switch/router short, 1m or under.

WARNING: Do not plug into a Power Over Ethernet enable Hub/switch/router, as you now have no magnetics to protect you. Failure to observe this will destroy your mbed. We know this for fact :-)

The bonus is that with every cable hack like this, you get *two* new experiment cables for the price of one.. now that is good value :-)

Cheers,
Chris

27 Oct 2009

Just a quick note, I have noticed that if I plug in my ethernet cable into my router first then the mbed, it will not work, I must have the ethernet connected to the mbed first THEN connect it to the router.

29 Oct 2009

Hi,

After more testing of the mbed http server sample I've found the following:

* I don't get a valid response unless I include serial output within the http polling loop as:

while(1) { http.poll(); printf(".")}

* Contrary to my previous findings on differences between OSes - I now see the same behaviour under Windows and Mac OS.

* Even with the polling loop, the mbed http server doesn't always appear to give a valid response.

See attached Wireshark dump for the tcp stream between my web browser (192.168.1.65) and the mbed web server (192.168.1.66).

Any idea how I can debug this problem?

29 Oct 2009

02 Nov 2009

Hi Nick,

I've noticed this behaviour a view times as well. But I didn't reach it very often.

It seems that Vlad has the same problem with the HTTPClient.

Actually I have no idea where it comes from. But I was browsing the lwip change logs and noticed that they had some similar problems. So I've spent some time on the weekend to port over a newer version of lwip.

Unfortunately the new lwip core is breaking some HTTPServer functions. But I'm working on it.

I'm not fully convinced that this will solve this problem, but everything looks a little bit more stable.

Cheers Rolf

19 Nov 2009

Hi Nick,

I've updated the HTTPServer code. It's now with API documentation ;-)

Maybe you can have a play with it and see if it works now more reliable.

 

Regards

Rolf

19 Nov 2009

Rolf, great!

I have few questions on the update, maybe the answers deserve to get into the documentation:

 

1. How would one program "try DHCP, fallback to a given IP settings" use case?

2. What time units is timeout (both in HTTPClient, HTTPServer)?

3. Does the latest version solve issues around lwIP bug and connection problems? With earlier version I experienced that only Firefox was opening pages from HTTPServer, and other browsers failed (Google chrome on PC, Safari on iPhone). Can't check new version for few days.