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.
main.cpp
00001 // server v3 ou version 3 modified LRSD 00002 // for mbed with TestBed card from Electronik laden 00003 // Example of HTTPServer 00004 // * SNTP Client (Simple NTP) 00005 // * Link status indication (LED4 or RJ45 socket LED on MBED-BoB2-mod) 00006 // * Local file system 00007 // * SD-based WebServer , sd card 128meg only **.htm 8.3 00008 // * Static HTM page 00009 // LRSD evolution from pub-iva2k-ethsntp project 00010 // i am not a so programmer 00011 // Instructions: 00012 // 1 Plug ETH connector into your network (with a switch beetwen pc) 00013 // 3 Plug MBED tu pc using USB cable 00014 // 4 need to have Installed MBED serial driver (http://mbed.org/handbook/SerialPC) 00015 // 5 Copy compiled .bin to your MBED (make sure target device selected in the compiler is correct) 00016 // 6 Open terminal on the mbed serial port 00017 // 7 Push MBED reset button 00018 // 8 Terminal will display info message with mac address, followed by IP address 00019 // in the following items, i put 192.168.1.77 00020 // 9 Open browser and enter the following URL: http://192,168,1,77/ !! ( sd card site) 00021 // 14 The browser will show the web page (htm) in the sd card 00022 // 16 if you clic on Led ( in browser) led5 from testbed light on ou off 00023 // led change , and ad da possibiliti is offered ( 1/s) 00024 // dans lxip/HHTPServer/testbed.h description des adresses a decoder pour les actions dans loop 00025 00026 00027 // global usefull things 00028 int aip4,aip3,aip2,aip1; 00029 int pon4,pon3,pon2,pon1; 00030 int gDebug=1; 00031 int var = 0; 00032 int adc = 0; 00033 char rr; 00034 float ana = 1.0; 00035 float gWait = 0.05; // Main loop wait timeout 00036 char *url = "0123 "; 00037 char *add = "0000 "; 00038 00039 #include "mbed.h" 00040 #include "NewTextLCD.h" 00041 #include "SDFileSystem.h" 00042 #include "HTTPRPC.h" 00043 #include "HTTPServer.h" 00044 #include "HTTPFS.h" 00045 #include "HTTPStaticPage.h" 00046 #include "HTTPLinkStatus.h" 00047 #include "SNTPClient.h" 00048 #define CLS "\033[2J" 00049 00050 00051 // E/S sur la carte mbed 005.1 00052 DigitalOut led1(LED1, "led1"); // mbed 00053 DigitalOut led2(LED2, "led2"); 00054 DigitalOut led3(LED3, "led3"); 00055 DigitalOut led4(LED4, "led4"); 00056 // E/S hors carte mbed sur la carte TestBed 00057 DigitalIn sw1(p8, "sw1"); // testbed bt1 ( bt2 on sd card !!) 00058 DigitalOut led5(p6, "led5"); // 2 led on testbed 00059 DigitalOut led6(p5, "led6"); 00060 AnalogIn Potm(p15); //potentiometre carte testbed 00061 TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4); // testbed LCD 00062 LocalFileSystem local("local"); 00063 SDFileSystem sd(p11, p12, p13, p14, "sd"); //test bed sd card 00064 00065 extern Ethernet eth; // eth is defined elsewhere, avoid compiler error. 00066 Serial pc(USBTX, USBRX); // usb sur la Mbed 00067 00068 00069 //*******************************************MAIN*************************** 00070 //**************************************************************************** 00071 int main(void) 00072 { 00073 lcd.cls(); 00074 pc.baud(115200); 00075 lcd.printf("LRSD Webserverv3 \n"); 00076 printf("LRSD debout !!\n"); 00077 00078 char mac[6]; 00079 bool use_sd = false; 00080 char res[10]= "1234000"; // resultat conv an 00081 led1=1; led2=1; led3=1; led4=1; led5 = 0; //led off 00082 00083 // Start RTC 00084 time_t seconds = time(NULL); 00085 if (seconds == (unsigned)-1 || seconds == 0) { 00086 seconds = 1256729737; // Set RTC time to Wed, 28 Oct 2009 11:35:37 00087 set_time(seconds); 00088 printf("RTC initialized, start time %d seconds\r\n", seconds); 00089 } 00090 00091 aip4 = 192; aip3 = 168 ; aip2 = 1 ; aip1 = 77; 00092 pon4 = 192; pon3 = 168 ; pon2 = 1 ; pon1 = 0; 00093 lcd.locate(0,1); 00094 lcd.printf("IP:%hhu.%hhu.%hhu.%hhu\n", 00095 aip4, aip3, aip2, aip1); 00096 HTTPServer http("mbed", // static IP address and domain name. 00097 IPv4(aip4,aip3,aip2,aip1), // IPv4 is a helper function which allows to rtype ipaddresses direct 00098 IPv4(255,255,0,0), 00099 IPv4(pon4,pon3,pon2,pon1), 00100 IPv4(pon4,pon3,pon2,pon1), 00101 80); // port 80 souvent 00102 char *hostname = "mbed"; 00103 // HTTPServer http(hostname); // Use DHCP 00104 http.timeout(10000); // Sets the timout for a HTTP request. The timout is the time which is allowed to spent between two incomming TCP packets. If the time is passed the connection will be closed. 00105 00106 eth.address(mac); 00107 pc.printf(CLS "\r\n\r\nHTTPServer \"%s\" started\r\nMAC %02X:%02X:%02X:%02X:%02X:%02X\r\n%s", 00108 hostname, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], 00109 gDebug?"Debug is ON\r\n":"" 00110 ); 00111 00112 // Check if we can use SD card for the web server 00113 FILE *fp = fopen("/sd/index.htm", "r"); 00114 if (fp == NULL) { 00115 if (gDebug) printf("DEBUG: No SD card found or no index.htm file - using LocalFilesystem for WebServer.\r\n"); 00116 } else { 00117 use_sd = true; 00118 fclose(fp); 00119 if (gDebug) printf("DEBUG: Found SD card with index.htm file - using SD for WebServer.\r\n"); 00120 } 00121 00122 if (0 != SNTPReadIniFile("/sd/sntp.ini") ) 00123 SNTPReadIniFile("/local/sntp.ini"); 00124 SNTPWriteIniFile(stdout); 00125 00126 http.addHandler(new HTTPLinkStatus("/", 00127 #if MBED_BOB2 00128 p25, p26, // MBED-BoB2-mods 00129 #else 00130 LED3, LED4, 00131 #endif 00132 0.1, // ici ??? 00133 /*do_urlfile*/ true, /*do_link_printf*/ true, /*do_log_printf*/ false, 00134 /*log_file*/ ( (gDebug>1) ? (use_sd ? "/sd/httpd.log" : "/local/httpd.log") : NULL) 00135 )); // Should be the first handler to get a preview of all requests 00136 // fin du ici ?? 00137 00138 http.addHandler(new HTTPFileSystemHandler("/", use_sd ? "/sd/" : "/local/")); 00139 led3=0; 00140 00141 // FIXME: BUG If eth is not plugged, http.bind() hangs! 00142 http.bind(); 00143 SNTPClientInit(); 00144 led4 = 0; 00145 // pc.printf("\r"); // Add linefeed for stupid Hyperterminal 00146 00147 while(1) { //BOUCLE POLL 00148 http.poll(); // Have to call this method at least every 250ms to let the http server run. 00149 wait(gWait); 00150 00151 ana = Potm.read(); // travail en temps reel like ( gWait) 00152 lcd.locate(0,2); //ligne 2 lcd 00153 ana = 3.2*ana; // mise au niveau 3v2 00154 lcd.printf("Value: %1.2f", ana); 00155 sprintf(res, "%f", ana); // met ana en chaine dans res[] 00156 00157 if ( adc == 1) 00158 { 00159 FILE *fp = fopen("/sd/texte.txt", "w"); 00160 fprintf( fp,res ); 00161 fclose(fp); 00162 00163 adc = 0; 00164 } 00165 00166 lcd.locate(0,3); 00167 lcd.printf(url); 00168 if ( var == 1) {led6 = 1 ;} // dans serveur on scrute et on force var 00169 else { led6 = 0;} 00170 } 00171 } 00172 00173 //END
Generated on Tue Jul 12 2022 16:12:21 by
1.7.2