Webserver only w/o any other functions, single thread. Running on STM32F013+W5500

Dependencies:   NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed

Fork of F103-Serial-to-Ethernet by Chau Vo

Files at this revision

API Documentation at this revision

Comitter:
olympux
Date:
Thu Jun 16 19:22:36 2016 +0000
Parent:
41:a50a534a2fbb
Child:
43:48ca8c6f6f49
Commit message:
Update HTML and add RPC variables for configuration

Changed in this revision

Formatter.cpp Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rpc-nucleo.lib Show annotated file Show diff for this revision Revisions of this file
my_eeprom_funcs.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Formatter.cpp	Thu Jun 16 09:12:20 2016 +0000
+++ b/Formatter.cpp	Thu Jun 16 19:22:36 2016 +0000
@@ -3,6 +3,7 @@
 #include "RPCObjectManager.h"
 #include "EthernetInterface.h"
 
+/*
 const char *SIMPLE_HTML_CODE = "\
 <!DOCTYPE html>\
 <html>\
@@ -78,8 +79,100 @@
 </form>\
 </body> \
 </html>";
+*/
 
-static char chunk[1024];
+
+const char *SIMPLE_HTML_CODE = "\
+<!DOCTYPE html>\
+<html>\
+<head>\
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
+<title>NNIO Server</title>\
+</head>\
+ <body>";
+
+
+const char* INTERACTIVE_HTML_CODE_1 = "\
+<!DOCTYPE html> \
+<html>\
+<head>\
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
+<title>TCP Server</title>\
+<script type=\"text/javascript\">\
+var ip = \"%s\";\
+function submitDeviceConfigurationForm()\
+{\
+return;\
+}\
+function submitCreateForm()\
+{\
+var list = document.getElementById(\"type\");\
+var type = list.options[list.selectedIndex].value;\
+var name = document.getElementById(\"name\").value;\
+if(name === \"\") \
+return;\
+var arg = document.getElementById(\"arg\").value;\
+var url;\
+if(arg === \"\") url = \"http://\" + ip + type + \"new?name=\" + name;\
+else url = \"http://\" + ip + type + \"new?arg=\" + arg + \"&name=\" + name;\
+location.href= url;\
+}\
+function submitCallFuncForm()\
+{\
+var command = document.getElementById(\"command\").value;\
+if(command === \"\") \
+return; \
+var tmp = command.split(\' \');\
+var url = tmp[0];\
+if(tmp.length > 1)\
+url += \"?\";\
+for(var i = 1; i < tmp.length; ++i)\
+{\
+url += \"arg\" + i + \"=\" + tmp[i];\
+if(i+1 < tmp.length)\
+url += \"&\";\
+}\
+location.href = url;\
+}\
+</script>\
+</head> \
+<body>";
+
+const char* INTERACTIVE_HTML_CODE_2 = "<h3>Device Configuration</h3>\
+<form>\
+IP (x.x.x.x): <input type=\"text\" id=\"ipadd\"><br>\
+Subnet (x.x.x.x): <input type=\"text\" id=\"subnet\"><br>\
+Gateway (x.x.x.x): <input type=\"text\" id=\"gateway\"><br>\
+MAC (x.x.x): <input type=\"text\" id=\"mac\">\
+<p><input type=\"button\" value=\"Save\" onclick=\"javascript:submitDeviceConfigurationForm();\"></p>\
+</form> \
+\
+<h3>Create Object</h3>\
+<form>\
+Type: <select id=\"type\">\
+<option value=\"/DigitalOut/\">DigitalOut</option>\
+<option value=\"/DigitalIn/\">DigitalIn</option>\
+<option value=\"/DigitalInOut/\">DigitalInOut</option>\
+<option value=\"/AnalogIn/\">AnalogIn</option>\
+<option value=\"/PwmOut/\">PwmOut</option>\
+<option value=\"/Timer/\">Timer</option>\
+</select><br>\
+name: <input type=\"text\" id=\"name\"><br>\
+arg(optional): <input type=\"text\" id=\"arg\">\
+<p><input type=\"button\" value=\"Create\" onclick=\"javascript:submitCreateForm();\"></p>\
+</form> \
+ \
+<h3>Call a function</h3>\
+<p>Enter an RPC command.</p>\
+<form>\
+Command: <input type= \"text\" id=\"command\" maxlength=127><br>\
+<p><input type=\"button\" value=\"Send\" onclick=\"javascript:submitCallFuncForm();\"></p><br>\
+</form>\
+</body> \
+</html>";
+
+
+static char chunk[2048]; // Need to update according to HTML content
         
 Formatter::Formatter(int nb):
 currentChunk(0),
--- a/README.md	Thu Jun 16 09:12:20 2016 +0000
+++ b/README.md	Thu Jun 16 19:22:36 2016 +0000
@@ -1,12 +1,26 @@
-Forked of RPC over HTTP server
+Forked of NNIO-8822
+Combined with "RPC over HTTP server" and "Improved mbed RPC" projects
 
-------------------
-Modified but not commit yet:
+# Modifications
 
 1. Updated Formatter.c to use eth.getIPAddress()
-2. Added AnalogIn
+2. Added creating RPC object AnalogIn
   - to HTML code in Formatter.c
   - to RPCType.c
-  
-Tested working but creating RPC object AnalogIn at PC_0 caused watchdog resets
--------------------
\ No newline at end of file
+3. Added read/write RPC string variable over HTTP
+
+# Releases
+
+## v1.0.0 (16/06/2016)
+
+Initial version
+
+- Use eeprom for device configuration
+- HTTP server
+- RPC over HTTP:
+  + Support creating objects including AnalogIn
+  + Support RPC string variable
+
+Bug fixes
+
+- Creating RPC object AnalogIn at PC_0 caused watchdog resets. FIXED in rev41
\ No newline at end of file
--- a/main.cpp	Thu Jun 16 09:12:20 2016 +0000
+++ b/main.cpp	Thu Jun 16 19:22:36 2016 +0000
@@ -1,6 +1,3 @@
-/*
- * Firmware supports NNIO and RPC protocols
- */
 #include "mbed.h"
 #include "rtos.h"
 #include "mbed_rpc.h"
@@ -22,8 +19,8 @@
 #define SERVER_PORT 80
 
 
-/** Debug option
- *
+/*
+ * Debug option
  */
 #if 1
 //Enable debug
@@ -56,7 +53,7 @@
                                      0x3212, 0x3313, 0x3414, 0x3515, // IP_Gateway
                                      0x4212, // TCP server port, not used
                                      0x5212, // UDP server port, not used
-                                     0x8888, // 1st run? 0xA5A5 = configured
+                                     0x8888, // 1st run? 0xA5A5 = static IP has been configured
                                      0x6212, 0x6313, 0x6414, // MAC
 
                                      // this section is for the TCP server that this device connects to in TCP client mode
@@ -67,29 +64,42 @@
                                      // this section is for selecting protocol, not used
                                      0xA212, // 0xA5A5 = enable TCP server
                                      0xA313, // 0xA5A5 = eanble TCP client
-                                     0xA414  // 0xA5A5 = enable UDP server
+                                     0xA414  // 0xA5A5 = enable UDP server, always enabled for configuration
                                     };
 
 
 /*
-* Variables for network configuration, TCP server
-*/
-uint8_t u8mac[6], u8ip_addr[4];// keep mac and ip address in 8-bits
-uint16_t u16mac_addr[3], u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4]; // 16-bits, directly loaded from eeprom
-char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16]; // for printf, converted from 16-bits u16ip_xxx
-uint16_t configured_ip = 0;  // static ip configured flag
+ * Variables for network configuration, TCP server
+ */
+// Device configuration
+uint16_t u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4], u16mac_addr[3]; // 16-bits, directly loaded from eeprom
+char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16], str_mac_addr[16]; // for printf and RPC, converted from 16-bits u16ip_xxx
+uint8_t u8ip_addr[4];// keep ip address in 8-bits
+uint16_t configured_ip = 0;  // flag indicates a static ip has been configured 0xA5A5
+uint8_t u8mac[6]; // mac in 8-bits
 
-const uint16_t tcp_server_local_port = 10000; // fixed, change to 7000 if internet required
-const uint16_t udp_server_local_port = 11000; // fixed
+// TCP/UDP server
+uint16_t tcp_server_local_port = 10000; // change to 7000 if internet required
+uint16_t udp_server_local_port = 11000;
 
-// TCP client: this section is used for the TCP server that this device connects to in TCP client mode
-// this device will transmit status every transmit_time_period
+// TCP client
+// this section is used to set the TCP server that this device connects to in TCP client mode.
+// this device will update its status to the server every transmit_time_period.
 uint16_t auto_transmit_flag = 0, transmit_time_period = 1000; // auto transmit status, time period = 1s
 uint16_t u16server_ip_addr[4]; // directly loaded from eeprom
 uint8_t u8server_ip_addr[4]; // server ip address in 8-bits
 char str_server_ip_addr[16];// for printf, converted from 16-bits u16server_ip_addr
 uint16_t u16tcp_server_port; // directly loaded from eeprom
-uint16_t u16enable_tcp_client, u16enable_tcp_server;// flags for enabling TCP client or TCP server
+uint16_t u16enable_tcp_server, u16enable_tcp_client;// flags for enabling TCP client or TCP server
+
+// Corresponding RPC variables
+RPCVariable<char*> rpcIPAddress(str_ip_addr, 16, "ipaddr");
+RPCVariable<char*> rpcSubnet(str_ip_subnet, 16, "subnet");
+RPCVariable<char*> rpcGateway(str_ip_gateway, 16, "gateway");
+RPCVariable<char*> rpcMac(str_mac_addr, 16, "mac");
+RPCVariable<unsigned short> rpcLocalTCPServerPort(&tcp_server_local_port, "localtcpserverport");
+RPCVariable<unsigned short> rpcLocalUDPPort(&udp_server_local_port, "localudpport");
+RPCVariable<unsigned short> rpcEnableTCPServer(&u16enable_tcp_server, "enabletcpserver");
 
 
 // Serial
@@ -97,15 +107,11 @@
 // Watchdog
 Watchdog wdt;
 
-float speed;
-RPCVariable<float> rpcSpeed(&speed, "speed");
-char stripaddr[20];
-RPCVariable<char*> rpcIPAddress(stripaddr, 20, "ipaddr");
 
 
 /*
-* Threads
-*/
+ * Threads
+ */
 // WDT reset
 void wdt_reset_thread(void const* args)
 {
@@ -133,8 +139,8 @@
 // Main code
 int main()
 {
-    int n, ret;
-
+    int ret;
+    
     Thread::wait(500); // turn on delay
 
     /*
@@ -193,8 +199,8 @@
 
 
 /*
-* W5500 Ethernet init
-*/
+ * W5500 Ethernet init
+ */
 int ethernet_init(void)
 {
     int dhcp_ret, ret;
--- a/mbed-rpc-nucleo.lib	Thu Jun 16 09:12:20 2016 +0000
+++ b/mbed-rpc-nucleo.lib	Thu Jun 16 19:22:36 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/olympux/code/mbed-rpc-nucleo/#e65ed29fd4d1
+http://developer.mbed.org/users/olympux/code/mbed-rpc-nucleo/#635b0fd3d1bd
--- a/my_eeprom_funcs.lib	Thu Jun 16 09:12:20 2016 +0000
+++ b/my_eeprom_funcs.lib	Thu Jun 16 19:22:36 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/olympux/code/my_eeprom_funcs/#613ab276bf37
+http://mbed.org/users/olympux/code/my_eeprom_funcs/#7ffbbfe999c5