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
- Committer:
- geiineuville
- Date:
- 2011-09-08
- Revision:
- 0:9cf1d79ebe04
File content as of revision 0:9cf1d79ebe04:
// server v3 ou version 3 modified LRSD // for mbed with TestBed card from Electronik laden // Example of HTTPServer // * SNTP Client (Simple NTP) // * Link status indication (LED4 or RJ45 socket LED on MBED-BoB2-mod) // * Local file system // * SD-based WebServer , sd card 128meg only **.htm 8.3 // * Static HTM page // LRSD evolution from pub-iva2k-ethsntp project // i am not a so programmer // Instructions: // 1 Plug ETH connector into your network (with a switch beetwen pc) // 3 Plug MBED tu pc using USB cable // 4 need to have Installed MBED serial driver (http://mbed.org/handbook/SerialPC) // 5 Copy compiled .bin to your MBED (make sure target device selected in the compiler is correct) // 6 Open terminal on the mbed serial port // 7 Push MBED reset button // 8 Terminal will display info message with mac address, followed by IP address // in the following items, i put 192.168.1.77 // 9 Open browser and enter the following URL: http://192,168,1,77/ !! ( sd card site) // 14 The browser will show the web page (htm) in the sd card // 16 if you clic on Led ( in browser) led5 from testbed light on ou off // led change , and ad da possibiliti is offered ( 1/s) // dans lxip/HHTPServer/testbed.h description des adresses a decoder pour les actions dans loop // global usefull things int aip4,aip3,aip2,aip1; int pon4,pon3,pon2,pon1; int gDebug=1; int var = 0; int adc = 0; char rr; float ana = 1.0; float gWait = 0.05; // Main loop wait timeout char *url = "0123 "; char *add = "0000 "; #include "mbed.h" #include "NewTextLCD.h" #include "SDFileSystem.h" #include "HTTPRPC.h" #include "HTTPServer.h" #include "HTTPFS.h" #include "HTTPStaticPage.h" #include "HTTPLinkStatus.h" #include "SNTPClient.h" #define CLS "\033[2J" // E/S sur la carte mbed 005.1 DigitalOut led1(LED1, "led1"); // mbed DigitalOut led2(LED2, "led2"); DigitalOut led3(LED3, "led3"); DigitalOut led4(LED4, "led4"); // E/S hors carte mbed sur la carte TestBed DigitalIn sw1(p8, "sw1"); // testbed bt1 ( bt2 on sd card !!) DigitalOut led5(p6, "led5"); // 2 led on testbed DigitalOut led6(p5, "led6"); AnalogIn Potm(p15); //potentiometre carte testbed TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4); // testbed LCD LocalFileSystem local("local"); SDFileSystem sd(p11, p12, p13, p14, "sd"); //test bed sd card extern Ethernet eth; // eth is defined elsewhere, avoid compiler error. Serial pc(USBTX, USBRX); // usb sur la Mbed //*******************************************MAIN*************************** //**************************************************************************** int main(void) { lcd.cls(); pc.baud(115200); lcd.printf("LRSD Webserverv3 \n"); printf("LRSD debout !!\n"); char mac[6]; bool use_sd = false; char res[10]= "1234000"; // resultat conv an led1=1; led2=1; led3=1; led4=1; led5 = 0; //led off // Start RTC time_t seconds = time(NULL); if (seconds == (unsigned)-1 || seconds == 0) { seconds = 1256729737; // Set RTC time to Wed, 28 Oct 2009 11:35:37 set_time(seconds); printf("RTC initialized, start time %d seconds\r\n", seconds); } aip4 = 192; aip3 = 168 ; aip2 = 1 ; aip1 = 77; pon4 = 192; pon3 = 168 ; pon2 = 1 ; pon1 = 0; lcd.locate(0,1); lcd.printf("IP:%hhu.%hhu.%hhu.%hhu\n", aip4, aip3, aip2, aip1); HTTPServer http("mbed", // static IP address and domain name. IPv4(aip4,aip3,aip2,aip1), // IPv4 is a helper function which allows to rtype ipaddresses direct IPv4(255,255,0,0), IPv4(pon4,pon3,pon2,pon1), IPv4(pon4,pon3,pon2,pon1), 80); // port 80 souvent char *hostname = "mbed"; // HTTPServer http(hostname); // Use DHCP 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. eth.address(mac); pc.printf(CLS "\r\n\r\nHTTPServer \"%s\" started\r\nMAC %02X:%02X:%02X:%02X:%02X:%02X\r\n%s", hostname, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], gDebug?"Debug is ON\r\n":"" ); // Check if we can use SD card for the web server FILE *fp = fopen("/sd/index.htm", "r"); if (fp == NULL) { if (gDebug) printf("DEBUG: No SD card found or no index.htm file - using LocalFilesystem for WebServer.\r\n"); } else { use_sd = true; fclose(fp); if (gDebug) printf("DEBUG: Found SD card with index.htm file - using SD for WebServer.\r\n"); } if (0 != SNTPReadIniFile("/sd/sntp.ini") ) SNTPReadIniFile("/local/sntp.ini"); SNTPWriteIniFile(stdout); http.addHandler(new HTTPLinkStatus("/", #if MBED_BOB2 p25, p26, // MBED-BoB2-mods #else LED3, LED4, #endif 0.1, // ici ??? /*do_urlfile*/ true, /*do_link_printf*/ true, /*do_log_printf*/ false, /*log_file*/ ( (gDebug>1) ? (use_sd ? "/sd/httpd.log" : "/local/httpd.log") : NULL) )); // Should be the first handler to get a preview of all requests // fin du ici ?? http.addHandler(new HTTPFileSystemHandler("/", use_sd ? "/sd/" : "/local/")); led3=0; // FIXME: BUG If eth is not plugged, http.bind() hangs! http.bind(); SNTPClientInit(); led4 = 0; // pc.printf("\r"); // Add linefeed for stupid Hyperterminal while(1) { //BOUCLE POLL http.poll(); // Have to call this method at least every 250ms to let the http server run. wait(gWait); ana = Potm.read(); // travail en temps reel like ( gWait) lcd.locate(0,2); //ligne 2 lcd ana = 3.2*ana; // mise au niveau 3v2 lcd.printf("Value: %1.2f", ana); sprintf(res, "%f", ana); // met ana en chaine dans res[] if ( adc == 1) { FILE *fp = fopen("/sd/texte.txt", "w"); fprintf( fp,res ); fclose(fp); adc = 0; } lcd.locate(0,3); lcd.printf(url); if ( var == 1) {led6 = 1 ;} // dans serveur on scrute et on force var else { led6 = 0;} } } //END