DHCP Client example

Dependencies:   WIZnetInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 
00004 DigitalOut myled(LED1);
00005 
00006 // Initialize the Ethernet client library
00007 EthernetInterface eth;
00008 
00009 int main() {
00010     // Enter a MAC address for your controller below.
00011     uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; 
00012     
00013     // initializing MAC address
00014     eth.init(mac_addr);
00015 
00016     // Check Ethenret Link
00017     if(eth.link() == true)
00018         printf("- Ethernet PHY Link-Done \r\n");
00019     else
00020         printf("- Ethernet PHY Link- Fail\r\n");
00021 
00022     // Start Ethernet connecting
00023     if ( eth.connect() < 0 )
00024         printf("Fail - Ethernet Connecing");
00025     else
00026     {
00027         // Print your local IP address:
00028         printf("IP=%s\n\r",eth.getIPAddress());
00029         printf("MASK=%s\n\r",eth.getNetworkMask());
00030         printf("GW=%s\n\r",eth.getGateway());
00031     }        
00032 
00033     while(1) {
00034         myled = 1;
00035         wait(0.2);
00036         myled = 0;
00037         wait(0.2);
00038     }
00039 }