Dumb newbie question. How do I print my mbed's IP address?
If I do something along these lines:
struct IpAddr myip;
myip = eth.getIp();
pc.printf("Interface is up, local IP is %s\n", inet_ntoa(myip));
I get compiler errors about the unknown function inet_ntoa.
What's the easiest way of printing out the mbed's IP address?
Take a look at the HTTP server example on the Cookbook.
It shows in there how to print IP
Couldn't find anything in the cookbook I must admit. Although there was a mention that the IP addr is printed out the console.
Anyway, I discovered that putting this:
allowed the inet_ntoa() function to work, which was perfect.
yeah the IP is printed to console there is a getip() function
IpAddr ethIp = eth.getIp();
printf("Connected ok, IP : %d.%d.%d.%d\n", ethIp, ethIp, ethIp, ethIp);
const char* hwAddr = eth.getHwAddr();
printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n",
hwAddr, hwAddr, hwAddr,
hwAddr, hwAddr, hwAddr);
How do I print my mbed's IP address?
You can also use the getIPAddress method:
eth.init(); //Use DHCP
printf("IP Address is %s\n", eth.getIPAddress());
See the Ethernet Interface documentation.
Please log in to post a reply.
mbed, the fastest way to prototype with ARM based microcontrollers.
^ back to top