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:
- 9:6f63abd61de8
- Parent:
- 8:3bd85b731cca
--- a/main.cpp Fri Jun 30 20:07:32 2017 +0000 +++ b/main.cpp Tue Feb 05 14:15:05 2019 +0000 @@ -9,7 +9,6 @@ //#define TARGET_STM32F103C8T6 1 // uncomment this line when using STM32F103C8T6 boards! #if defined(TARGET_STM32F103C8T6) -#include "stm32f103c8t6.h" #define LED_PIN PC_13 const int OFF = 1; const int ON = 0; @@ -27,33 +26,13 @@ using namespace std; -Serial pc(USBTX, USBRX); +Serial pc(PA_2, PA_3); -#define DHCP 1 // if you'd like to use static IP address comment out this line +//#define DHCP 1 // if you'd like to use static IP address comment out this line // uIPEthernet is the name of a global instance of UIPEthernet. // Do not change the name! It is used within the UIPEthernet library. -#if defined(TARGET_LPC1768) -UIPEthernet uIPEthernet(p11, p12, p13, p8); // mosi, miso, sck, cs -#elif defined(TARGET_LPC1114) -UIPEthernet uIPEthernet(dp2, dp1, dp6, dp25); // mosi, miso, sck, cs -#elif defined(TARGET_LPC11U68) -UIPEthernet uIPEthernet(P0_9, P0_8, P1_29, P0_2); // mosi, miso, sck, cs -#elif defined(TARGET_NUCLEO_F103RB) || defined(TARGET_NUCLEO_L152RE) || defined(TARGET_NUCLEO_F030R8) \ - || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_L053R8) \ - || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_F072RB) \ - || defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F070RB) -//UIPEthernet uIPEthernet(D4, D5, D3, D2); // mosi, miso, sck, cs -//UIPEthernet uIPEthernet(D11, D12, D13, D10); // mosi, miso, sck, cs -UIPEthernet uIPEthernet(PA_7, PA_6, PA_5, PB_6); // mosi, miso, sck, cs - -// If your board/plaform is not present yet then uncomment -// the following two lines and replace TARGET_YOUR_BOARD as appropriate. - -//#elif defined(TARGET_YOUR_BOARD) -//UIPEthernet uIPEthernet(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS); // mosi, miso, sck, cs - -#endif +UIPEthernet uIPEthernet(PB_5, PB_4, PB_3, PA_10); // mosi, miso, sck, cs // Note: // If it happends that any of the SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS pins collide with LED1 pin @@ -213,7 +192,7 @@ uIPEthernet.begin(MY_MAC, MY_IP); #endif IPAddress localIP = uIPEthernet.localIP(); - pc.printf("Type %s secret/ into your web browser and hit ENTER\r\n", localIP.toString()); + pc.printf("Type %s/secret/ into your web browser and hit ENTER\r\n", localIP.toString()); myServer.begin(); while(1) { EthernetClient client = myServer.available();