Help with EthernetNetIf library

01 Nov 2010 . Edited: 01 Nov 2010

 

I'm trying to setup my ethernet connection, but mbed doesn't receive its IP address.

Thats what i get when using eth.setup()...

Setting up...
[..\fwk\if\eth\EthernetNetIf.cpp:setup@86] HW Addr is : 00:02:f7:f0:35:22.
[..\fwk\if\eth\EthernetNetIf.cpp:setup@99] DHCP Started, waiting for IP...

eth.link() always returns 1 when i plug my RJ45 at MagJack if this logic

void ethCheckFunction() {
    if (eth.link()) {
        lcd.locate(5,0);
        lcd.printf("ES: Online ");
        wait(0.5);
    } else {
        lcd.locate(5,0);
        lcd.printf("ES: Offline");
        wait(0.5);
    }
}
And that's what i get using EthernetTesterGood example
mBed Ethernet Tester 1.0
Starting Up...
Configuring device for DHCP...

The DHCP is enabled at my router settings, any ideas why it doesn't work?

01 Nov 2010

Hi Bruno

Have you tried the program here (you should be able to see broadcast packets on your network)? Also have a look here (and there are a couple more test programs lower down). This should prove the ethernet function of the mbed.

Regards
Daniel

01 Nov 2010 . Edited: 01 Nov 2010

Thank you Daniel for your fast reply,

Here it's what i got if you first program suggestion:

 

Source: FF:FF:FF:FF:FF:FF
Destination:  FF:FF:FF:FF:FF:FF
Source: FF:FF:FF:FF:FF:FF
Destination:  FF:FF:FF:FF:FF:FF
Source: FF:FF:FF:FF:FF:FF

if ethsnif and eh spam i've got nothing.

 

I'm using Magjack 08b0-1x1T-36-F

 

PIN2 to TD+ of mbed
PIN3 to TD- of mbed
PIN4 to RD+ of mbed
PIN5 to RD- of mbed

 

 

 

 

Tried inverting green and orange, white/green and white/orange to see if it was a cross cable, but nothing changes.

 

Best regards

01 Nov 2010

Hi Bruno

I'm confused by the test program output - I wouldn't expect to see the broadcast address (all FF) in the source, so that's not good.

With the ethspam program running on the mbed, did you connect it by ethernet to a PC running wireshark, in order to see the ARP requests?

Try this at your own risk, but my mbed is connected to a router without a magjack, I just cut a cable in half and poked the wires into a breadboard.

Regards
Daniel

01 Nov 2010 . Edited: 01 Nov 2010

Daniel,

I've made some progress!

When I connect my crossover cable direct to my pc, running ethsniff i can see some packets

(I'm not sure if the type field right, some packets i've got 2048 [0x0800] which stands for IPv4, so i guess it's ok right?)

 

Destination:  33:33:00:00:00:0c
Source: 00:25:b3:a0:51:59
Type -31232
0000:  33 33 00 00 00 0c 00 25  b3 a0 51 59 86 dd 60 00
0010:  00 00 00 7f 11 01 fe 80  00 00 00 00 00 00 18 c8
0020:  dc 89 bf 16 f2 fe ff 02  00 00 00 00 00 00 00 00
0030:  00 00 00 00 00 0c ed 6a  07 6c 00 7f 93 56 4d 2d
0040:  53 45 41 52 43 48 20 2a  20 48 54 54 50 2f 31 2e
0050:  31 0d 0a 48 6f 73 74 3a  5b 46 46 30 32 3a 3a 43
0060:  5d 3a 31 39 30 30 0d 0a  53 54 3a 75 72 6e 3a 73
0070:  63 68 65 6d 61 73 2d 75  70 6e 70 2d 6f 72 67 3a
0080:  64 65 76 69 63 65 3a 4d  65 64 69 61 52 65 6e 64
0090:  65 72 65 72 3a 31 0d 0a  4d 61 6e 3a 22 73 73 64
00A0:  70 3a 64 69 73 63 6f 76  65 72 22 0d 0a 4d 58 3a
00B0:  33 0d 0a 0d 0a

But, when i connect to a hub with a straight cable, nothing appears.

02 Nov 2010

Hi Bruno

With your crossover cable between mbed and the PC, can you go back to running the first program (the one which prints source/destination) and see what you get - there shouldn't be all the FFs in there now.

(In the Ethernet example above, is 00:25:b3:a0:51:59 the MAC address of your PC)?

If you get sensible results with these tests, then it's likely your mbed ethernet hardware is ok, and problems with picking up an address by DHCP are down to issues elsewhere ie. cables, router etc which you'll have to eliminate by systematic testing.

Regards
Daniel

03 Nov 2010

Hi Daniel,

The problem was with my router, it wasn't sending IP. Everything is working quite well now, thank you very much for helping me.

One last question, what's the difference between EthernetNetIf library and mbed's Ethernet library? When should i use the first and when should i use the second one.

 

03 Nov 2010

Hi Bruno

Glad everything is working.

The mbed Ethernet class is for sending and receiving Ethernet frames. You'd use it if you just want to work with Ethernet and nothing else.

If you want to work with the higher level Internet Protocol (IP) packets then you would use the EthernetNetIf library which provides IP over Ethernet. Donatien also wrote some very useful network services to use the EthernetNetIf library; have a read thru the cookbook here.

Regards
Daniel

04 Nov 2010 . Edited: 04 Nov 2010

Hey Peter,

Yes, I do understand the concepts of Ethernet frames and Datagram encapsulations in it. I read already this page, but i'm still kinda lost with which functions should i use.

All i wanna do is send some data generated by a sensor to another pc via ethernet. If i instantiate an object in Ethernet class, i can use write/send/read/receive methods but i won't use Internet Protocol. Otherwise, if i instantiate an object in EthernetNetIf i can acquire an IP with setup method but how can i write and send an ethernet frame?