Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NTPClient_NetServices mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 #include "RPCFunction.h" 00005 #include "NTPClient.h" 00006 00007 EthernetNetIf eth; 00008 NTPClient ntp; 00009 HTTPServer svr; 00010 00011 DigitalOut led1(LED1, "led1"); 00012 DigitalOut led2(LED2, "led2"); 00013 DigitalOut led3(LED3, "led3"); 00014 DigitalOut led4(LED4, "led4"); 00015 00016 AnalogIn Sensor(p20); // Sensor in 00017 DigitalOut pin15(p15); 00018 DigitalOut pin16(p16); 00019 DigitalOut pin17(p17); 00020 DigitalOut pin18(p18); 00021 DigitalOut pin19(p19); 00022 00023 FILE *file; 00024 00025 int main() 00026 { 00027 00028 /************** Ethernet Setup *****************/ 00029 EthernetErr ethErr; 00030 int count = 0; 00031 do { 00032 printf("Setting up %d...\n\r", ++count); 00033 ethErr = eth.setup(); 00034 if (ethErr) printf("Timeout\n\r", ethErr); 00035 } while (ethErr != ETH_OK); 00036 00037 printf("Connected OK\n\r"); 00038 const char* hwAddr = eth.getHwAddr(); 00039 00040 IpAddr ethIp = eth.getIp(); 00041 printf("IP address : %d.%d.%d.%d\n\r", ethIp[0], ethIp[1], ethIp[2], ethIp[3]); 00042 00043 /***************** FilsSystem ******************/ 00044 LocalFileSystem local("local"); 00045 float waarden[3][800]; 00046 00047 /***************** Handlers *******************/ 00048 svr.addHandler<SimpleHandler>("/hello"); 00049 svr.addHandler<FSHandler>(""); 00050 svr.addHandler<RPCHandler>("/rpc"); 00051 00052 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path 00053 Base::add_rpc_class<DigitalOut>(); 00054 Base::add_rpc_class<AnalogIn>(); 00055 00056 svr.bind(80); 00057 printf("Server listening\n\r"); 00058 00059 /**************** Realtime clock ******************/ 00060 time_t ctTime; 00061 ctTime = time(NULL); 00062 printf("Current time is (UTC): %s\r\n", ctime(&ctTime)); 00063 00064 Host server(IpAddr(), 123, "be.pool.ntp.org"); 00065 //be server: be.pool.ntp.org 00066 ntp.setTime(server); 00067 00068 ctTime = time(NULL); 00069 printf("\nTime is now (UTC): %s\r\n", ctime(&ctTime)); 00070 00071 /***************** Timer ***************/ 00072 Timer tm; 00073 tm.start(); 00074 00075 float sensorWaarde; 00076 00077 00078 while (true) { 00079 Net::poll(); 00080 if (tm.read() > 2) { 00081 file = fopen("/local/test.htm", "a"); //openen bestand. 00082 sensorWaarde = ((Sensor * 3.3 -2.78)*100); //Ijking waarde 00083 ctTime = time(NULL); //Tijd goedzetten 00084 fprintf(file, "%s %5.2f\r\n", ctime(&ctTime), sensorWaarde); 00085 printf("\nTime is now (UTC): %s\r\n", ctime(&ctTime)); 00086 printf("Temperatuur: %5.2f\r\n", sensorWaarde); 00087 fclose(file); 00088 led1 = !led1; 00089 tm.start(); 00090 } 00091 } 00092 }
Generated on Tue Jul 12 2022 19:45:45 by
1.7.2