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
pmr_svr3.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 #include "NTPClient.h" 00005 00006 DigitalOut led1(LED1, "led1"); 00007 DigitalOut led2(LED2, "led2"); 00008 DigitalOut led3(LED3, "led3"); 00009 DigitalOut led4(LED4, "led4"); 00010 00011 AnalogIn Voltmeter (p20); 00012 00013 LocalFileSystem fs("webfs"); // this could be any name 00014 00015 EthernetNetIf eth; 00016 HTTPServer svr; 00017 // NTPClient ntp; 00018 00019 int updateVolts(void) 00020 { 00021 FILE *fp = fopen("/webfs/volts.htm", "w"); // Open local filename 00022 // it ignores path and date defaults 1/1/2008 becausse RTC not set 00023 // if I call ithe localfilesystem www rather than 'local' it writes and is seen when drive is refreshed 00024 fprintf(fp, "<title> Volt meter test page </title>\n"); 00025 fprintf(fp,"<h1>Volts of the day from port 1</h1>"); 00026 fprintf(fp, "volts %f V\r\n",Voltmeter.read()); 00027 fclose(fp); 00028 return(0); 00029 } 00030 00031 int loadTime(void) 00032 { 00033 time_t ctTime; 00034 ctTime = time(NULL); 00035 printf("Current time is (UTC): %s\n\r", ctime(&ctTime)); 00036 00037 Host server(IpAddr(192.168.1.4), 123, "0.uk.pool.ntp.org"); // fails here 00038 ntp.setTime(server); 00039 00040 ctTime = time(NULL); 00041 00042 printf("Time is now (UTC): %s\n\r", ctime(&ctTime)); 00043 return 0; 00044 } 00045 00046 00047 int main() { 00048 00049 00050 Base::add_rpc_class<DigitalOut>(); 00051 00052 printf("Setting up...\n"); 00053 EthernetErr ethErr = eth.setup(); 00054 if(ethErr) 00055 { 00056 printf("Error %d in setup.\n", ethErr); 00057 return -1; 00058 } 00059 printf("Setup OK\n"); 00060 00061 // FSHandler::mount("/webfs", "/files"); //Mount /wwww path on /files web path - this has no meaning 00062 FSHandler::mount("/webfs", "/"); //Mount /wwww path on web root path 00063 00064 00065 // svr.addHandler<SimpleHandler>("/"); hard code for Hello world 00066 svr.addHandler<RPCHandler>("/rpc"); // sets up the remote procedure call handler 00067 // svr.addHandler<FSHandler>("/files");// this does not see the subdirectory 00068 svr.addHandler<FSHandler>("/"); //Default handler 00069 svr.bind(80); 00070 00071 printf("Listening...\n\r"); 00072 00073 loadTime(); 00074 Timer tm; 00075 tm.start(); 00076 updateVolts(); 00077 //Listen indefinitely 00078 while(true) 00079 { 00080 Net::poll(); 00081 if(tm.read()>2.0) 00082 { 00083 led1=!led1; //Show that we are alive 00084 // writing to this file continually updates the drive as attached as a usb drive to the host and generates errors so not good 00085 // and even at 2 second interval the auto play continually brings up windows 00086 // updateVolts(); 00087 tm.start(); 00088 } 00089 } 00090 00091 return 0; 00092 00093 }
Generated on Tue Jul 12 2022 22:07:18 by
1.7.2