HTTP Server serving a simple webpage which enables to remotely turn a digital output on/off. Compile, download, run and type 'IP_address/secret/' (don't forget the last '/') into your web browser and hit ENTER.
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. An inexpensive ENC28J60 Ethernet module is used to assure connection between the mbed board and the Ethernet network (Internet). The ENC28J60 Ethernet module is driven by the UIPEthernet library.
Needed parts:
- mbed board
- ENC28J60 Ethernet module
- Wires
- Web browser (Internet Explorer, Safari, Firefox, Chrome ...) running on Windows, Mac, Linux, iPhone or Android device.
Notice that DHCP is turned on by default. If you prefer to use static IP address then uncomment line 234
The IP address assigned to the WebSwitch server along with an instruction how to use it is printed in the connected PC's serial terminal window during program start up.
Warning
Please notice that the 3.3V power supply chip (RT8183-B) installed on an STM32F103C8T6 board is not rated to power also the ENC28J60 board.
The project was inspired by the Tuxgraphics Web Switch. Thank you Guido!
NOTE:
- For a Web Switch using a WIZ550io or W5500 Ethernet module see WebSwitch_Wiz550io.
- For a Web Switch using mbed's built in Ethernet PHY see WebSwitch_mbed-dev or WebSwitch_mbed-os .
Diff: main.cpp
- Revision:
- 12:7c46dcf6f7e2
- Parent:
- 11:6c0b20227ca2
- Child:
- 14:810ac368dd6e
diff -r 6c0b20227ca2 -r 7c46dcf6f7e2 main.cpp --- a/main.cpp Tue Aug 27 22:10:13 2019 +0000 +++ b/main.cpp Fri Aug 30 08:23:46 2019 +0000 @@ -8,18 +8,14 @@ //#define DEBUG -// To be used when a static IP is needed #define IP "192.168.1.35" #define GATEWAY "192.168.1.1" #define NETMASK "255.255.255.0" #define PORT 80 -// The ENC28J60 chip doesn't have a built-in MAC address. -// It's up to us to provide one which is unique within the connected network. -// So modify the one below accordingly. const uint8_t MAC[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06 }; UipEthernet net(MAC, D11, D12, D13, D10); // mosi, miso, sck, cs -TcpServer server; +TcpServer server; // Ethernet server TcpClient* client; char receiveBuf[1024]; const int OFF = 0; @@ -220,7 +216,7 @@ printf("Starting ...\r\n"); // IP address must be unique and compatible with your network. - //net->set_network(IP, NETMASK, GATEWAY); // include this for using static IP address + //net.set_network(IP, NETMASK, GATEWAY); // include this for using static IP address net.connect(); // Show the network address