HTTP Server serving a simple webpage which enables to remotely turn LED1 on/off. Compile, download, run and type 'IP_address/secret/' (don't forget the last '/') into your web browser and hit ENTER.
Dependencies: W5500Interface mbed
Turn LED1, or other digital output, on/off using a web browser.
In this example we create a HTTP server that will serve a simple Web page to remotely turn LED1, or other digital output on the mbed board, on/off by using a web browser. A WIZ550io module or W5500 Network-Shielld is used to assure connection between the mbed module and the Ethernet network (Internet).
Needed parts:
- mbed board
- WIZ550io module or W5500 Network-Shield
- Wires
- Web browser (Internet Explorer, Safari, Firefox, Chrome ...) running on Windows, Mac, Linux, iPhone or Android device.
The project was inspired by the Tuxgraphics Web Switch. Thank you Guido!
NOTE:
- For a Web Switch using an ENC28J60 Ethernet module see WebSwitch_ENC28J60
- For a Web Switch using mbed's built in Ethernet PHY see WebSwitch_mbed-dev or WebSwitch_mbed-os
Diff: main.cpp
- Revision:
- 1:343d3c7e13b8
- Parent:
- 0:5c8e08cf3b33
- Child:
- 2:3803ea61daa1
diff -r 5c8e08cf3b33 -r 343d3c7e13b8 main.cpp --- a/main.cpp Sun Mar 15 22:47:37 2015 +0000 +++ b/main.cpp Mon Mar 16 09:24:23 2015 +0000 @@ -1,4 +1,5 @@ -/* In this example LED1 on the mbed board is switched on/off using a web browser. +/* In this project LED1 on the mbed board is switched on/off using a web browser. + * However, you can easily modify the project to remotely switch on/off any external device. * The HTTP server is built from an mbed board and a WIZ550io board. * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>. */ @@ -10,41 +11,30 @@ Serial serial(USBTX, USBRX); -// Do not change the name! It is used within the UIPEthernet library. #if defined(TARGET_LPC1768) -SPI spi(p11, p12, p13); // MOSI, MISO, SCK -EthernetInterface eth(&spi, p8, p14); // SPI, CS, RESET +EthernetInterface eth(p11, p12, p13, p8, p14); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_FRDM_KL25Z) -SPI spi(PTD2, PTD3, PTD1); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PTD0, PTD5); // SPI, CS, RESET +EthernetInterface eth(PTD2, PTD3, PTD1, PTD0, PTD5); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_FRDM_KL46Z) -SPI spi(PTD2, PTD3, PTD1); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PTD0, PTD5); // SPI, CS, RESET +EthernetInterface eth(PTD2, PTD3, PTD1, PTD0, PTD5); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_LPC11U24) -SPI spi(P16, P15, P13); // MOSI, MISO, SCK -EthernetInterface eth(&spi, P17, P18); // SPI, CS, RESET +EthernetInterface eth(P16, P15, P13, P17, P18); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_NUCLEO_F030R8) -SPI spi(PB_5, PB_4, PB_3); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PB_10, PA_8); // SPI, CS, RESET +EthernetInterface eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_NUCLEO_F072RB) -SPI spi(PB_5, PB_4, PB_3); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PB_10, PA_8); // SPI, CS, RESET +EthernetInterface eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_NUCLEO_F103RB) -SPI spi(PB_5, PB_4, PB_3); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PB_10, PA_8); // SPI, CS, RESET +EthernetInterface eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_NUCLEO_F401RE) -SPI spi(PB_5, PB_4, PB_3); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PB_10, PA_8); // SPI, CS, RESET +EthernetInterface eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET #elif defined(TARGET_NUCLEO_F411RE) -SPI spi(PB_5, PB_4, PB_3); // MOSI, MISO, SCK -EthernetInterface eth(&spi, PB_10, PA_8); // SPI, CS, RESET +EthernetInterface eth(PB_5, PB_4, PB_3, PB_10, PA_8); // MOSI, MISO, SCK, CS, RESET // If your board/plaform is not present yet then uncomment -// the following three lines and replace modify as appropriate. +// the following two lines and replace modify as appropriate. //#elif defined(TARGET_YOUR_BOARD) -//SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // MOSI, MISO, SCK -//EthernetInterface eth(&spi, SPI_CS, RESET); // SPI, CS, RESET +//EthernetInterface eth(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, RESET); // MOSI, MISO, SCK, CS, RESET #endif // Note: @@ -66,7 +56,6 @@ DigitalOut sw(LED1); // Change LED1 to a pin of your choice. // However, make sure that it does not collide with any of the SPI pins - // already used in the UIPEthernet(...) constructor above! const string PASSWORD = "secret"; // change as you like const string HTTP_OK = "HTTP/1.0 200 OK";