WiFi RN171 Example project
At the time of writing this blog, this project needs the patch for WiFiRN171 in order to work. The current unpatched version does not work due to incorrect baudrate settings in the driver.

The initialization of the module is quite easy: In ProgramStarted a one-time-timer is started that sets up the wifi_RN171 module to act as a HttpServer. After the initialization, the webserver listens at http://192.168.1.1 and requests are handled in wifi_RN171_HttpRequestReceived

void ProgramStarted() { string methodName = "ProgramStarted"; LogEnterMethod(methodName); wifi_RN171.Reboot(); GT.Timer wifiInitializationTimer = new GT.Timer(1000); wifiInitializationTimer.Behavior = GT.Timer.BehaviorType.RunOnce; wifiInitializationTimer.Tick += initializeWifi; wifiInitializationTimer.Start(); LogLeaveMethod(methodName); } void initializeWifi(GT.Timer timer) { string methodName = "initializeWifi"; LogEnterMethod(methodName); wifi_RN171.SetDebugLevel(GTM.GHIElectronics.WiFi_RN171.DebugLevel.DebugAll); wifi_RN171.Initialize(GTM.GHIElectronics.WiFi_RN171.SocketProtocol.TCP_Server); wifi_RN171.EnableHttpServer(); //Enable HTTP Parsing wifi_RN171.HttpRequestReceived += new GTM.GHIElectronics.WiFi_RN171.HttpRequestReceivedHandler(wifi_RN171_HttpRequestReceived); LogLeaveMethod(methodName); }

In wifi_RN171_HttpRequestReceived there's determined whether this is a normal request or a ajax request. All ajax request must be prefixed with '_'. The normal request returns html with buttons and mark-up:

private static void HandleHttpRequest(GTM.GHIElectronics.HttpStream request, string requestedURL) { string methodName = "HandleHttpRequest"; LogEnterMethod(methodName); string action = "Unkown action"; if (requestedURL == "/index.html") { action = "Welcome"; } else { action = "Unknown action"; } request.Response.HeaderData["Content-type"] = "text/html; charset=utf-8"; request.Response.HeaderData["Connection"] = "close"; request.Response.HeaderData["Cache-Control"] = "no-cache"; request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK; request.Response.Send( HERE IS A LONG LINE OF HTML ); LogLeaveMethod(methodName); }
WiFi RN171 at work
WiFi RN171 at work

The second method determines which action was send:

private static void HandleAjaxHttpRequest(GTM.GHIElectronics.HttpStream request, string requestedURL) { string methodName = "HandleAjaxHttpRequest"; LogEnterMethod(methodName); string action = ""; switch (requestedURL) { case "/_index.html": action = "Welcome"; break; case "/_northwest.html": action += "north west"; break; case "/_north.html": action += "north"; break; case "/_northeast.html": action += "north east"; break; case "/_west.html": action += "west"; break; case "/_center.html": action += "home"; break; case "/_east.html": action += "east"; break; case "/_southwest.html": action += "south west"; break; case "/_south.html": action = "We're going down south"; break; case "/_southeast.html": action += "south east"; break; case "/_start.html": action = "Let's go"; break; case "/_stop.html": action = "Hold it, right there!"; break; case "/_fire.html": action = "Cease fire!"; break; case "/_getposition.html": action = "interval example position[x,y]"; break; default: action = "Unknown action"; break; } //request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK; request.Response.HeaderData["Content-type"] = "text/html; charset=utf-8"; request.Response.HeaderData["Connection"] = "close"; request.Response.HeaderData["Cache-Control"] = "no-cache"; request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK; request.Response.Send(action); LogLeaveMethod(methodName); }

The complete solution can be downloaded here
On 2013-07-16, Eeuwe Vandyke wrote:

comment=-+The+baudrate+will+be+fixed+in+the+next+version+of+the+SDK%0D%0A-+The+problem+with+the+multiple+send+issue+can+be+worked+around+by+specifying+the+content+length+at+the+client+software.%0D%0A%0D%0ASee+also%3A+https%3A%2F%2Fwww.ghielectronics.com%2Fcommunity%2Fforum%2Ftopic%3Fid%3D12286%26page%3D2%23msg128993

On 2013-08-14, Kevin wrote:

comment=Thank+you+for+resolving+the+above+baud+speed+problem.+I+am+using+your+upload+code+in+my+project.+Being+able+to+step+through+the+code+is+most+helpful.+Do+you+know+how+I+may+obtain+a+reference+manual+for+the+commands+used+in+RN171%3F

On 2013-08-15, Eeuwe Vandyke wrote:

comment=Can+you+explain+your+question+a+little+bit+more%3F%0D%0ADo+you+need+information+about+the+methods+that+the+class+%22WiFi_RN171%22+exposes+or+do+you+need+information+about+the+GTI.Serial+class+(short+name+for+Gadgeteer.Intefaces.Serial)+that+is+used+for+the+communication%3F+%0D%0A%0D%0AFor+the+first+I+am+not+aware+of+a+reference+manual+and+if+I+were+you+I+would+post+a+question+at+the+GHI+forum.+For+the+latter+you+I+think+that+the+parameter+description+of+the+Serial+constructor+is+quite+self-explanatory.%0D%0A%0D%0ASo+can+you+specify+what+parts+of+the+code+you+need+a+clarification+for%3F%0D%0AJust+send+me+the+method+names+or+highlight+the+code+you+need+more+info+about.%0D%0A%0D%0AHopefully+I+can+help+you+with+that.%0D%0ARegards%2C%0D%0AErwin+van+Dijk.

On 2013-08-15, Eeuwe Vandyke wrote:

comment=%3EThank+you+for+your+reply.+I+was+asking+about+commands+such+as+"if(!_Command_Execute('set+comm+remote+0'))".+However+I+looked+through+many+manuals+at+the+Roving+Networks+website+and+found+rn-wiflycr-ug-v1.2r.pdf+which+lists+the+commands+used+in+WiFi_RN171_42.cs+such+as+%E2%80%9Cset+comm+remote+0%E2%80%9D.%0D%0A%0D%0AFor+completeness%2C+the+document+can+be+found+at:http://www.rovingnetworks.com/resources/download/93/WiFly_User_Manual

Back to List

All form fields are required.
A confirmation mail for the comments will be send to you.