ProjetoBB

Dependencies:   F7_Ethernet WebSocketClient mbed mcp3008

Fork of Nucleo_F746ZG_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sat Jun 18 10:49:12 2016 +0000
Revision:
0:f9b6112278fe
Child:
3:0fc17139f828
Ethernet for the NUCLEO STM32F746 Board Testprogram uses DHCP and NTP to set the clock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:f9b6112278fe 1 #include "mbed.h"
DieterGraef 0:f9b6112278fe 2 #include "rtos.h"
DieterGraef 0:f9b6112278fe 3 #include "EthernetInterface.h"
DieterGraef 0:f9b6112278fe 4 #include "NTPClient.h"
DieterGraef 0:f9b6112278fe 5 #include <stdio.h>
DieterGraef 0:f9b6112278fe 6
DieterGraef 0:f9b6112278fe 7 EthernetInterface eth;
DieterGraef 0:f9b6112278fe 8
DieterGraef 0:f9b6112278fe 9 DigitalOut led1(LED1);
DieterGraef 0:f9b6112278fe 10
DieterGraef 0:f9b6112278fe 11 int main()
DieterGraef 0:f9b6112278fe 12 {
DieterGraef 0:f9b6112278fe 13 NTPClient ntp;
DieterGraef 0:f9b6112278fe 14 char buff[64];
DieterGraef 0:f9b6112278fe 15 printf("\n\n*** Ethernet Demo uses NTP to set the clock ***\r\n");
DieterGraef 0:f9b6112278fe 16
DieterGraef 0:f9b6112278fe 17 if(eth.init()!=0) //for DHCP Server
DieterGraef 0:f9b6112278fe 18 {
DieterGraef 0:f9b6112278fe 19 //if(eth.init(IP,MASK,GATEWAY)!=0) { //for Static IP Address
DieterGraef 0:f9b6112278fe 20 printf("EthernetInterface Initialize Error \r\n");
DieterGraef 0:f9b6112278fe 21
DieterGraef 0:f9b6112278fe 22 while (1)
DieterGraef 0:f9b6112278fe 23 {
DieterGraef 0:f9b6112278fe 24 }
DieterGraef 0:f9b6112278fe 25 }
DieterGraef 0:f9b6112278fe 26 if(eth.connect()!=0)
DieterGraef 0:f9b6112278fe 27 {
DieterGraef 0:f9b6112278fe 28 printf("EthernetInterface Connect Error \r\n");
DieterGraef 0:f9b6112278fe 29 while (1)
DieterGraef 0:f9b6112278fe 30 {
DieterGraef 0:f9b6112278fe 31 }
DieterGraef 0:f9b6112278fe 32 }
DieterGraef 0:f9b6112278fe 33 printf("IP Address is %s\r\n", eth.getIPAddress());
DieterGraef 0:f9b6112278fe 34 printf("NetMask is %s\r\n", eth.getNetworkMask());
DieterGraef 0:f9b6112278fe 35 printf("Gateway Address is %s\r\n", eth.getGateway());
DieterGraef 0:f9b6112278fe 36 printf("Ethernet Setup OK\r\n");
DieterGraef 0:f9b6112278fe 37 printf("Getting time, 10s timeout. \r\n");
DieterGraef 0:f9b6112278fe 38
DieterGraef 0:f9b6112278fe 39 if (ntp.setTime("0.uk.pool.ntp.org") == 0)
DieterGraef 0:f9b6112278fe 40 {
DieterGraef 0:f9b6112278fe 41 time_t ctTime;
DieterGraef 0:f9b6112278fe 42 ctTime = time(NULL);
DieterGraef 0:f9b6112278fe 43 printf("Time is set to : %s \r\n", ctime(&ctTime));
DieterGraef 0:f9b6112278fe 44 }
DieterGraef 0:f9b6112278fe 45 else
DieterGraef 0:f9b6112278fe 46 {
DieterGraef 0:f9b6112278fe 47 printf("Error getting time \r\n");
DieterGraef 0:f9b6112278fe 48 }
DieterGraef 0:f9b6112278fe 49
DieterGraef 0:f9b6112278fe 50 printf("end of programm\r\n");
DieterGraef 0:f9b6112278fe 51 while (true) {
DieterGraef 0:f9b6112278fe 52 led1 = !led1;
DieterGraef 0:f9b6112278fe 53 Thread::wait(500);
DieterGraef 0:f9b6112278fe 54 }
DieterGraef 0:f9b6112278fe 55 }