University of Essex CE713
Dependencies: mbed HTTPServer EthernetNetIf TextLCD
Fork of HTTPServerHelloWorld by
Diff: main.cpp
- Revision:
- 7:7f4d940077bd
- Parent:
- 6:7929de136a42
- Child:
- 8:b6a76cc9c872
diff -r 7929de136a42 -r 7f4d940077bd main.cpp --- a/main.cpp Thu Nov 30 15:30:41 2017 +0000 +++ b/main.cpp Thu Nov 30 15:51:11 2017 +0000 @@ -16,17 +16,17 @@ DigitalIn In2(p12); // " DigitalIn In3(p11); // " I2C i2c(p9, p10); // I2C: SDA, SCL pins -PwmOut servo1(p21); // Servo 1 PWM pin -PwmOut servo2(p22); // Servo 2 PWM pin -DigitalOut Trigger(p28); // Ultrasonic rangefinder trigger pin -DigitalIn Echo(p27); // Ultrasonic rangefinder echo pin -Timer Sonar; // Ultrasonic timer -DigitalOut led1(LED1); // -Serial out(USBTX, USBRX); // -LocalFileSystem fs("webfs"); // +PwmOut servo1(p21); // servo 1 PWM pin +PwmOut servo2(p22); // servo 2 PWM pin +DigitalOut Trigger(p28); // ultrasonic rangefinder trigger pin +DigitalIn Echo(p27); // ultrasonic rangefinder echo pin +Timer Sonar; // ultrasonic timer +DigitalOut led1(LED1); // web server stay alive indication +Serial out(USBTX, USBRX); // used for wev server +LocalFileSystem fs("webfs"); // web server local file system EthernetNetIf eth; // HTTPServer svr; // -Ticker WebUpdate; // Interrupt timer to update web page +Ticker WebUpdate; // interrupt timer to service web page requests // global variables short LEDbits = 0; // global led status used for readback @@ -40,8 +40,8 @@ extern "C" void mbed_mac_address(char *mac); // void WebServerPoll () { - Net::poll(); - led1=!led1; //Show that we are alive + Net::poll(); // bump web server into action + led1=!led1; // show that we are alive } int InitWebServer() { @@ -49,24 +49,24 @@ if(ethErr) { return -1; } - FILE *fp = fopen("/webfs/index.htm", "w"); // Open "out.txt" on the local file system for writing + FILE *fp = fopen("/webfs/index.htm", "w"); // open "out.txt" on the local file system for writing fprintf(fp, "<html><head><title>Hello World online</title></head><body><h1>Hello World from Mbed NXP LPC1768!</h1></body></html>"); - fclose(fp); // Close file - FSHandler::mount("/webfs", "/files"); // Mount /webfs path on /files web path - FSHandler::mount("/webfs", "/"); // Mount /webfs path on web root path + fclose(fp); // close file + FSHandler::mount("/webfs", "/files"); // mount /webfs path on /files web path + FSHandler::mount("/webfs", "/"); // mount /webfs path on web root path svr.addHandler<SimpleHandler>("/hello"); svr.addHandler<RPCHandler>("/rpc"); svr.addHandler<FSHandler>("/files"); - svr.addHandler<FSHandler>("/"); // Default handler - svr.bind(80); // Example : http://155.245.21.144 + svr.addHandler<FSHandler>("/"); // default handler + svr.bind(80); // example : http://155.245.21.144 WebUpdate.attach(&WebServerPoll, 0.1); // update webserver every 100ms return 0; // return without error } void HTTPText(char t[100]) { - FILE *fp = fopen("/webfs/index.htm", "w"); // Open "out.txt" on the local file system for writing - fprintf(fp, t); - fclose(fp); + FILE *fp = fopen("/webfs/index.htm", "w"); // open "index.htm" on the local file system for writing + fprintf(fp, t); // print to file + fclose(fp); // close file } void Servo1(float s) { // range +-1 @@ -84,8 +84,8 @@ } void InitServos() { - servo1.period(0.02); - servo2.period(0.02); + servo1.period(0.02); // + servo2.period(0.02); // Servo1(0); // initiate servo 1 to centre position Servo2(0); // initiate servo 1 to centre position } @@ -314,7 +314,7 @@ for(int i=0; i<6;i++) { // step through MAC address characters lcd.printf("%02X ", mac[i]); // print MAC address } - printf("\n"); + printf("\n"); // wait(.4); // wait 0.4 second if (spos < 1) { // is servo at upper limit of 1 spos += .1; // increment servo position