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.
Fork of WebSwitch_mbed-os by
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/off by using a web browser.
Notice that DHCP is turned on by default. The IP address assigned to the WebSwitch server along with an instruction how to use it is printed to the connected PC's serial terminal window during program start up.
To use static IP address uncomment and adjust line #221 in main.cpp.
The project was inspired by the Tuxgraphics Web Switch. Thank you Guido!
For a Web Switch using
- mbed OS 2 see WebSwitch_mbed-dev
- ENC28J60 Ethernet module see WebSwitch_ENC28J60
- WIZ550io or W5500 Ethernet module see WebSwitch_Wiz550io.
Revision 12:138b2b3d041a, committed 2020-10-27
- Comitter:
- hudakz
- Date:
- Tue Oct 27 16:43:25 2020 +0000
- Parent:
- 11:101be77aa5db
- Commit message:
- Tiny HTTP server switching LED1 (or other DigitalOut) on/off.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 27 16:39:39 2020 +0000 +++ b/main.cpp Tue Oct 27 16:43:25 2020 +0000 @@ -264,12 +264,12 @@ /* Listen for clients */ server.listen(); - //listening for http GET request + printf("=========================================\r\n"); + printf("Ready to serve clients.\r\n"); + net->get_ip_address(&addr); + printf("Usage: Type http:\/\/%s\/%s\/ into your web browser and hit ENTER\r\n", addr.get_ip_address(), PASSWORD); while (true) { - printf("=========================================\r\n"); - printf("Ready to serve clients.\r\n"); - net->get_ip_address(&addr); - printf("Usage: Type http:\/\/%s\/%s\/ into your web browser and hit ENTER\r\n", addr.get_ip_address(), PASSWORD); + //listening for http GET request client = server.accept(); if (client) { client->getpeername(&addr);