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:   mbed UIPEthernet

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.
/media/uploads/hudakz/webswitch_enc.jpg/media/uploads/hudakz/webswitch_mobile01.jpg

Notice that DHCP is turned on by default. If you prefer to use static IP address then comment out the line
#define DHCP 1

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.

Check main.cpp for the list of supported mbed platforms.
If you'd like to use an STM32F103C8T6 board then uncomment the line
#define TARGET_STM32F103C8T6 1
and select NUCLEO-F103RB as target for the online compiler.

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:

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Tue Feb 05 14:15:05 2019 +0000
Parent:
8:3bd85b731cca
Commit message:
Updated.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-STM32F103C8T6.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- 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();
--- a/mbed-STM32F103C8T6.lib	Fri Jun 30 20:07:32 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/hudakz/code/mbed-STM32F103C8T6/#727468adfd1d
--- a/mbed.bld	Fri Jun 30 20:07:32 2017 +0000
+++ b/mbed.bld	Tue Feb 05 14:15:05 2019 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file