Ethernet demo for STM32F746NG Discovery

Dependencies:   F7_Ethernet mbed mbed-rtos NTPClient

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "EthernetInterface.h"
00004 #include "NTPClient.h"
00005 #include <stdio.h>
00006 
00007 EthernetInterface eth;
00008 
00009 DigitalOut led1(LED1);
00010 
00011 int main()
00012 {
00013     NTPClient ntp;
00014     char buff[64];
00015     printf("\n\n*** Ethernet Demo uses NTP to set the clock ***\r\n");
00016 
00017     if(eth.init()!=0)                    //for DHCP Server
00018     {
00019         //if(eth.init(IP,MASK,GATEWAY)!=0) { //for Static IP Address
00020         printf("EthernetInterface Initialize Error \r\n");
00021 
00022         while (1)
00023         {
00024         }
00025     }
00026     if(eth.connect()!=0)
00027     {
00028         printf("EthernetInterface Connect Error \r\n");
00029         while (1)
00030         {
00031         }
00032     }
00033     printf("IP Address is %s\r\n", eth.getIPAddress());
00034     printf("NetMask is %s\r\n", eth.getNetworkMask());
00035     printf("Gateway Address is %s\r\n", eth.getGateway());
00036     printf("Ethernet Setup OK\r\n");
00037     printf("Getting time, 10s timeout. \r\n");
00038 
00039     if (ntp.setTime("0.uk.pool.ntp.org") == 0)
00040     {
00041         time_t ctTime;
00042         ctTime = time(NULL);
00043         printf("Time is set to : %s \r\n", ctime(&ctTime));
00044     }
00045     else
00046     {
00047         printf("Error getting time \r\n");
00048     }
00049 
00050     printf("end of programm\r\n");
00051     while (true) {
00052         led1 = !led1;
00053         Thread::wait(500);
00054     }
00055 }