NNN40 change mode from AP to STA by HTTP server

Dependencies:   WIFI_API_32kRAM mbed

How to use Demo code

  • Step1: Prepare a router, and set the SSID and Password as follow
  1. SSID: "SSID"
  2. Password: "0123456789"
  • Step2: Burn demo code to NNN40 module.

You can drag and drop the sample code to NNN40 module.

  • Step3: Login module from Http server (192.168.2.1) by PC.

You can set SSID and password by browser. After clicking "confirm" button, the module will change mode from AP to STA, get IP from router

  • DEMO video:
Revision:
4:624527ebc0fa
Parent:
0:9e4bcb10b3e3
Child:
6:d03e189ebbfe
--- a/Formatter.cpp	Wed Jul 17 11:07:06 2013 +0000
+++ b/Formatter.cpp	Wed Jul 17 15:00:24 2013 +0000
@@ -6,74 +6,74 @@
 const char *SIMPLE_HTML_CODE = "\
 <!DOCTYPE html>\
 <html>\
-    <head>\
-        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
-        <title>TCP Server</title>\
-    </head>\
-    <body>";
+<head>\
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
+<title>TCP Server</title>\
+</head>\
+ <body>";
 
 
 const char* INTERACTIVE_HTML_CODE_1 = "\
-<!DOCTYPE html>\
+<!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 submitCreateForm()\
-            {\
-                var list = document.getElementById(\"type\");\
-                var type = list.options[list.selectedIndex].value;\
-                var name = document.getElementById(\"name\").value;\
-                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;\
-                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> \
+<head>\
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\
+<title>TCP Server</title>\
+<script type=\"text/javascript\">\
+var ip = \"%s\";\
+function submitCreateForm()\
+{\
+var list = document.getElementById(\"type\");\
+var type = list.options[list.selectedIndex].value;\
+var name = document.getElementById(\"name\").value;\
+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;\
+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>Create Object :</h3>\
-    <form id=\"create\" method=\"get\">\
-    Type: <select id=\"type\">\
-        <option value=\"/DigitalOut/\">DigitalOut</option>\
-        <option value=\"/DigitalIn/\">DigitalIn</option>\
-        <option value=\"/DigitalInOut/\">DigitalInOut</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 method=\"get\">\
-    Command: <input type= \"text\" id=\"command\"><br>\
-    <input type=\"button\" value=\"Send\" onclick=\"javascript:submitCallFuncForm();\"><br>\
-    </form>\
-    </body> \
+<form id=\"create\" method=\"get\">\
+Type: <select id=\"type\">\
+<option value=\"/DigitalOut/\">DigitalOut</option>\
+<option value=\"/DigitalIn/\">DigitalIn</option>\
+<option value=\"/DigitalInOut/\">DigitalInOut</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 method=\"get\">\
+Command: <input type= \"text\" id=\"command\"><br>\
+<input type=\"button\" value=\"Send\" onclick=\"javascript:submitCallFuncForm();\"><br>\
+</form>\
+</body> \
 </html>";
 
 static char chunk[1024];
@@ -145,6 +145,7 @@
 {
     if(c == 0)
         sprintf(chunk, INTERACTIVE_HTML_CODE_1, EthernetInterface::getIPAddress());
+
     else if(c == 1)
     {
         if(reply != NULL && strlen(reply) != 0)