11 years, 6 months ago.

creating a static IP with the EthernetInterface

Hello, I would like to give the mbed a static IP because i dont get an IP adres from my DHCP server (see other question). I found i have to : init (const char *ip, const char *mask, const char *gateway) Initialize the interface with a static IP address. I tried:

    eth.init(192.168.0.83,255.255.255.0, 192.168.0.1); 

but this gives errors. i suppose i have to use pointers because of the *? so i tried:

const char IPadrees = 192.168.0.83;
const char NetworkMassk = 255.255.255.0;
const char Gatewayy = 192.168.0.1;

    eth.init(&IPadrees ,&NetworkMassk, &Gatewayy);

but this gives erros as well, the compiler aspects a ';' afther 2 digits (192.168)

Thnx in advance! Best regards! adriaan

2 Answers

11 years, 6 months ago.

The ethernet interface can be initialized with a static IP address using:

init (const char *ip, const char *mask, const char *gateway)

That means you need to provide character strings for the addresses and mask.

Try:

const char * IPaddress = "192.168.0.83";
const char * NetworkMask = "255.255.255.0";
const char * Gateway = "192.168.0.1';

and

eth.init(IPaddress, NetworkMask, Gateway);

Note that there may be a problem with your wiring that causes the failure in getting an IP address from your DHCP server (probably your router). In that case static IPs wont help. Another explanation may be that DHCP is disabled in your router/server.

Accepted Answer
11 years, 6 months ago.

This is the exact question I had yesterday. The answer (I think) is to use IpAddr() and use commas to seperate the octets instead of dots. For example:- EthernetNetIf eth( IpAddr(192,168,0,101), IP Address IpAddr(255,255,255,0), Network mask IpAddr(192,168,0,1), Gateway IpAddr(192,168,0,1) DNS );

This is according to the "Applying the ARM MBED" book.

Note that the mbed book uses the 'old' and now unsupported ethernetlibs.

New libs can be found here http://mbed.org/handbook/Networking

posted by Wim Huiskamp 04 May 2013