![](/media/cache/group/logo.jpg.50x50_q85.jpg)
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
- SSID: "SSID"
- 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:
Diff: Formatter.cpp
- Revision:
- 12:eca9b56155c7
- Parent:
- 10:8b4c3d605bf0
- Child:
- 13:f3d681e5b6c6
--- a/Formatter.cpp Wed Sep 16 02:43:42 2015 +0000 +++ b/Formatter.cpp Wed Sep 23 03:08:49 2015 +0000 @@ -54,7 +54,7 @@ </script>\ </head> \ <body>"; - + const char* INTERACTIVE_HTML_CODE_2 = "<h3>Create Object :</h3>\ <form>\ Type: <select id=\"type\">\ @@ -78,28 +78,71 @@ </body> \ </html>"; +const char* DELRA_WIFI_SETTING_HTML_CODE_0 = "<!DOCTYPE html> \ +<html>\ +<head>\ +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\ +<title>NNN40 Wifi Module Setting</title>\ +<style>\ +#background {\ +background: -moz-linear-gradient(top,#ffffff,#0099FF);\ +border-width: 3px;\ +border-style: ridge;\ +width: 500px;\ +height: 700px;\ +border-color: #000055;\ +padding: 20px\ +}#title {color: #444444;}#input {margin: 10px;}\ +</style><script type=\"application/javascript\">\ +function reset() {\ +document.getElementById(\"defaultchs\").checked = true;\ +document.getElementById(\"ssid\").value = \"\";\ +document.getElementById(\"password\").value = \"\";\ +}function send() {var ip = \"192.168.2.1/WebSetting/\";\ +var ssid = document.getElementById(\"ssid\").value;\ +var pwd = document.getElementById(\"password\").value;\ +location.href = \"http://\"+ip+ssid +\"_\"+pwd;}\ +</script></head><body>"; + + const char* DELRA_WIFI_SETTING_HTML_CODE_1 = "<div id=\"background\">\ +<div align=\"center\">\ +<img src=\"https://upload.wikimedia.org/wikipedia/commons/8/8c/DELTA_Electronics_Logo.png\" width=\"354\" height=\"109\";\>\ +</div><h1 id=\"title\"align=\"center\">WIFI SETTING</h1>\ +<HR align=\"center\" width=\"90%\"><form id=\"input\" method=\"get\">\ +<font size=\"6\" class=\"font\">Security:</font>\ +<br><input id=\"defaultchs\" type=\"radio\" name=\"security\" value=\"NONE\" checked>\ +NONE<input type=\"radio\" name=\"security\" value=\"WEP\">\ +WEP<input type=\"radio\" name=\"security\" value=\"WPA\">\ +WPA<input type=\"radio\" name=\"security\" value=\"WPA2\">\ +WPA2<br> <br><font size=\"6\" class=\"font\">SSID:</font>\ +<br><input id=\"ssid\" size=\"20\" type=\"text\" name=\"ssid\">\ +<br><br><font size=\"6\" class=\"font\">Password:</font>\ +<br><input type=\"text\" id=\"password\" name=\"pwd\">\ +<div align=\"center\"><input class=\"font\" type=\"button\" style=\"width: 160px; height: 80px; margin: 50px 40px 0px 0px; font-size: 25px\" value=\"Confirm\" onclick=\"send()\" />\ +<input class=\"font\" type=\"button\" style=\"width: 160px; height: 80px; margin: 50px 40px 0px 0px; font-size: 25px\" value=\"Reset\" onclick=\"reset()\" />\ +</div></form><div style=\"margin-top: 100px\"><font size=\"2\" style=\"color: #ffffff\">Copyright by Lester Lee.</font>\ +</div></div></body></html>" ; + static char chunk[1024]; - + Formatter::Formatter(int nb): -currentChunk(0), -nbChunk(nb) + currentChunk(0), + nbChunk(nb) { -} +} char* Formatter::get_page(char *reply) { chunk[0] = '\0'; - if(currentChunk < nbChunk) - { + if(currentChunk < nbChunk) { get_chunk(currentChunk, reply); currentChunk++; - } - else + } else currentChunk = 0; - + return chunk; -} +} void Formatter::get_chunk(const int c, char *reply) { @@ -107,39 +150,35 @@ } SimpleHTMLFormatter::SimpleHTMLFormatter(): -Formatter() + Formatter() { } void SimpleHTMLFormatter::get_chunk(const int c, char* reply) { strcat(chunk, SIMPLE_HTML_CODE); - - if(reply != NULL && strlen(reply) != 0) - { + + if(reply != NULL && strlen(reply) != 0) { strcat(chunk, "RPC reply : "); strcat(chunk, reply); } - - if(!RPCObjectManager::instance().is_empty()) - { + + if(!RPCObjectManager::instance().is_empty()) { strcat(chunk, "<ul>"); for(std::list<char*>::iterator itor = RPCObjectManager::instance().begin(); - itor != RPCObjectManager::instance().end(); - ++itor) - { + itor != RPCObjectManager::instance().end(); + ++itor) { strcat(chunk, "<li>"); strcat(chunk, *itor); strcat(chunk, "</li>"); } strcat(chunk, "</ul>"); } - strcat(chunk, "</body></html>"); } InteractiveHTMLFormatter::InteractiveHTMLFormatter(): -Formatter(3) + Formatter(3) { } @@ -148,22 +187,18 @@ if(c == 0) sprintf(chunk, INTERACTIVE_HTML_CODE_1, EthernetInterface::getIPAddress()); - else if(c == 1) - { - if(reply != NULL && strlen(reply) != 0) - { + else if(c == 1) { + if(reply != NULL && strlen(reply) != 0) { strcat(chunk, "RPC reply : "); strcat(chunk, reply); } - if(!RPCObjectManager::instance().is_empty()) - { + if(!RPCObjectManager::instance().is_empty()) { strcat(chunk, "<p>Objects created :</p>"); strcat(chunk, "<ul>"); for(std::list<char*>::iterator itor = RPCObjectManager::instance().begin(); - itor != RPCObjectManager::instance().end(); - ++itor) - { + itor != RPCObjectManager::instance().end(); + ++itor) { strcat(chunk, "<li>"); strcat(chunk, *itor); strcat(chunk, " (<a href=\"http://"); @@ -176,9 +211,22 @@ strcat(chunk, "</ul>"); } strcat(chunk, " "); - } - else if(c == 2) + } else if(c == 2) strcat(chunk, INTERACTIVE_HTML_CODE_2); } +DeltaWifiSettingHTMLFormatter::DeltaWifiSettingHTMLFormatter(): + Formatter(2) +{ +} +void DeltaWifiSettingHTMLFormatter::get_chunk(const int c, char *reply) +{ + if(c == 0) + strcat(chunk, DELRA_WIFI_SETTING_HTML_CODE_0); + + else if(c == 1) { + strcat(chunk,DELRA_WIFI_SETTING_HTML_CODE_1); + + } +}