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:
- 3:0133517ba02d
- Parent:
- 2:76f339a1ba9b
- Child:
- 4:d34811deedab
diff -r 76f339a1ba9b -r 0133517ba02d main.cpp --- a/main.cpp Sat Sep 27 09:18:53 2014 +0000 +++ b/main.cpp Sat Dec 20 11:23:20 2014 +0000 @@ -16,7 +16,7 @@ // Do not change the name! It is used within the UIPEthernet library. // Adapt the SPI pin names to your mbed platform/board if not present yet. #if defined(TARGET_LPC1768) -UIPEthernetClass UIPEthernet(p11, p12, p13, p8); // mosi, miso, sck, cs +UIPEthernetClass UIPEthernet(p11, p12, p13, p8); // mosi, miso, sck, cs #elif defined(TARGET_LPC1114) UIPEthernetClass UIPEthernet(dp2, dp1, dp6, dp25); // mosi, miso, sck, cs #elif defined(TARGET_LPC11U68) @@ -27,7 +27,7 @@ // MAC number must be unique within the connected network. Modify as appropriate. -const uint8_t MY_MAC[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; +const uint8_t MY_MAC[6] = {0x00,0x01,0x02,0x03,0x04,0x06}; // IP address must be also unique and compatible with your network. Change as appropriate. const IPAddress MY_IP(192,168,1,181); const uint16_t MY_PORT = 80; // for HTTP connection @@ -131,7 +131,7 @@ int main() { - Ethernet.begin(MY_MAC,MY_IP); + UIPEthernet.begin(MY_MAC,MY_IP); myServer.begin(); while(1) { EthernetClient client = myServer.available(); @@ -190,3 +190,4 @@ } } +