I am having trouble getting the RN171 with a Raptor board to work. I have tried the suggested source module but cannot get it to function. It will connect to my Android phone (however the ConnectionEstabilshed event does not fire) and Chrome is not able to find the website and get the expected reply at the IP address 192.168.1.11 which is what the phone shows as the IP address. I cannot find a way to get the module itself to report its IP address. LocalIP always reports “0.0.0.0”.
My Win8.1 laptop can see the hotspot, but cannot connect to it at all.
I have modified the suggested code as follows below, in order to learn how connect to my local wireless network, but am not successful. Initialize reports failure, IsReady reports false, and looking at the driver code suggests that IsReady is never referenced.
The debug windows shows:
Using mainboard GHI Electronics FEZRaptor version 1.0
Program Started
RN171 Rebooted
Initialize FAILED
171 shows not ready
HTTP server enabled
DHCP enabled
Network NOT joined
Network NOT joined
Network NOT joined
…
Here is the code. I will greatly appreciate any suggestions.
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Namespace GadgeteerApp1
Partial Public Class Program
Dim WithEvents StartupTimer As GT.Timer = New GT.Timer(3000)
Dim WithEvents PollingTimer As GT.Timer = New GT.Timer(30000)
' This is run when the mainboard is powered up or reset.
Public Sub ProgramStarted()
Debug.Print("Program Started")
char_Display.PrintString("Program Started")
StartupTimer.Behavior = Gadgeteer.Timer.BehaviorType.RunOnce
StartupTimer.Start()
AddHandler wifi_RN171.HttpRequestReceived, AddressOf wifi_RN171_HttpRequestReceived
End Sub
Private Sub StartupTimer_Tick(timer As Gadgeteer.Timer) Handles StartupTimer.Tick
Dim b As Boolean = wifi_RN171.Reboot
If b Then Debug.Print("RN171 Rebooted") Else Debug.Print("RN171 Reboot FAILED")
b = wifi_RN171.Initialize(GTM.GHIElectronics.WiFi_RN171.SocketProtocol.TCP_Server) ' //Init as TCP Server
If b Then Debug.Print("RN171 initialized") Else Debug.Print("Initialize FAILED")
If wifi_RN171.IsReady = True Then Debug.Print("171 shows READY") Else Debug.Print("171 shows not ready")
' this seems defined but NEVER referenced
wifi_RN171.SetDebugLevel(Gadgeteer.Modules.GHIElectronics.WiFi_RN171.DebugLevel.DebugAll)
If wifi_RN171.EnableHttpServer() = True Then Debug.Print("HTTP server enabled") Else Debug.Print("HTTP servcer NOT ENABLED") ' sets to port 80
If wifi_RN171.EnableDHCP("192.168.250.1", , "192.168.250.1") Then Debug.Print("DHCP enabled") Else Debug.Print("DHCP returned false")
PollingTimer.Behavior = Gadgeteer.Timer.BehaviorType.RunContinuously
PollingTimer.Start()
End Sub
Private Sub wifi_RN171_HttpRequestReceived(request As GTM.GHIElectronics.HttpStream)
Dim requestedURL As String = request.Request.URL
If requestedURL = "/index.html" Then
request.Response.HeaderData("Content-type") = "text/html"
request.Response.HeaderData("Connection") = "close"
request.Response.HeaderData("Cache-Control") = "no-cache"
request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK
'All you have to do is send the document data through the response object.
'Header data is automatically applied for you when you chose to send.
Dim myData As String = "This is send from the FEZ Raptor"
request.Response.Send(System.Text.Encoding.UTF8.GetBytes("<html><head></head><body>" & myData & "</body></html>"))
End If
End Sub
Dim counter As Integer = 1
Private Sub Polling_Tick(timer As Gadgeteer.Timer) Handles PollingTimer.Tick
Dim b As Boolean = wifi_RN171.JoinWirelessNetwork("xxxxx", "yyyyy", , Gadgeteer.Modules.GHIElectronics.WiFi_RN171.WirelessEncryptionMode.WPA2_PSK)
If b Then Debug.Print("Network joined") Else Debug.Print("Network NOT joined")
Dim s As String = counter.ToString & ":" & wifi_RN171.LocalIP.ToString & ":"
char_Display.SetCursor(0, 0)
char_Display.PrintString(s)
counter += 1
End Sub
Private Sub wifi_RN171_ConnectionEstablished() Handles wifi_RN171.ConnectionEstablished
char_Display.SetCursor(1, 0)
char_Display.PrintString("connected!")
End Sub
End Class
End Namespace
@ rockybooth - As distributed, the RN-171 module is geared and configured to act in a WiFi HotSpot mode. In this mode, the module will not be able to connect to another network. The enabling of DHCP in your code below is probably the reason the Win8 laptop can not connect as the RN-171 is configured as the DHCP server. If you want to change this behaviour, it will need to be reconfigured.
For the LocalIP, I will check into this but I think this would also be related to the DHCP issue. The module is pre-configured to hold the IP address 192.168.1.1, as most hotspot providers are. When DHCP is set, the chip is most likely releasing the previous static assignment.
@ James:
Thanks for the response. I have modified the code dropping the DHCP and JoinNetwork lines, which should put it back to the original intent. On my android device I can connect, and by pointing Chrome to 192.168.1.1 I can trigger the HttpRequestReceived event and the requestedURL matches. However, the response is not received by Chrome.
In addition to the .IsReady never returning TRUE, .Initialize also never returns TRUE.
Furthermore, the program seems to stall at the initialize (I gave it 10 minutes), and I must pause then resume the execution to get it to continue. It then indicates that the initialize failed.
Perhaps the debug output will indicate what it happening.
First here is my code, followed by the debug output:
(sorry about the extra line spaces, I do not know how to prevent them on a simple copy/past operation)
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Namespace GadgeteerApp1
Partial Public Class Program
Dim WithEvents StartupTimer As GT.Timer = New GT.Timer(3000)
' This is run when the mainboard is powered up or reset.
Public Sub ProgramStarted()
Debug.Print("Program Started @ " & DateTime.Now.TimeOfDay.ToString)
char_Display.PrintString("Program Started")
Dim b As Boolean = wifi_RN171.Reboot
If b Then Debug.Print("RN171 Rebooted @ " & DateTime.Now.TimeOfDay.ToString) Else Debug.Print("RN171 Reboot FAILED @ " & DateTime.Now.TimeOfDay.ToString)
AddHandler wifi_RN171.HttpRequestReceived, AddressOf wifi_RN171_HttpRequestReceived
AddHandler wifi_RN171.ConnectionEstablished, AddressOf wifi_RN171_ConnectionEstablished
' AddHandler wifi_RN171.DataReceivedHandler, AddressOf wifi_RN171_DataReceived
StartupTimer.Behavior = Gadgeteer.Timer.BehaviorType.RunOnce
StartupTimer.Start()
Debug.Print("Timers Started @ " & DateTime.Now.TimeOfDay.ToString)
End Sub
Private Sub StartupTimer_Tick(timer As Gadgeteer.Timer) Handles StartupTimer.Tick
Debug.Print("Startup timer fired @ " & DateTime.Now.TimeOfDay.ToString)
Dim b As Boolean
b = wifi_RN171.Initialize(GTM.GHIElectronics.WiFi_RN171.SocketProtocol.TCP_Server) ' //Init as TCP Server
If b Then Debug.Print("RN171 initialized TRUE @ " & DateTime.Now.TimeOfDay.ToString) Else Debug.Print("RN171 Initialize FAILED @ " & DateTime.Now.TimeOfDay.ToString)
If wifi_RN171.IsReady = True Then Debug.Print("171 shows READY @ " & DateTime.Now.TimeOfDay.ToString) Else Debug.Print("171 shows not ready @ " & DateTime.Now.TimeOfDay.ToString)
' this seems defined but NEVER referenced
wifi_RN171.SetDebugLevel(Gadgeteer.Modules.GHIElectronics.WiFi_RN171.DebugLevel.DebugAll) ' not sure what it does, but hopefully provides more info
If wifi_RN171.EnableHttpServer() = True Then Debug.Print("HTTP server enabled @ " & DateTime.Now.TimeOfDay.ToString) Else Debug.Print("HTTP servcer NOT ENABLED @ " & DateTime.Now.TimeOfDay.ToString) ' sets to port 80
End Sub
Private Sub wifi_RN171_HttpRequestReceived(request As GTM.GHIElectronics.HttpStream)
Dim requestedURL As String = request.Request.URL
Debug.Print("HTTP request received - " & request.Request.URL.ToString & "@ " & DateTime.Now.TimeOfDay.ToString)
If requestedURL = "/index.html" Then
request.Response.HeaderData("Content-type") = "text/html"
request.Response.HeaderData("Connection") = "close"
request.Response.HeaderData("Cache-Control") = "no-cache"
request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK
Debug.Print("Header data response: " & request.Response.HeaderData.ToString)
Debug.Print("Header data request: " & request.Request.HeaderData.ToString)
'All you have to do is send the document data through the response object.
'Header data is automatically applied for you when you chose to send.
Dim myData As String = "This is sent from the FEZ Raptor"
request.Response.Send(System.Text.Encoding.UTF8.GetBytes("<html><head>" & "GHI HOTSPOT" & "</head><body>" & myData & "</body></html>"))
Debug.Print("After response.Send @ " & DateTime.Now.TimeOfDay.ToString)
End If
End Sub
Private Sub wifi_RN171_ConnectionEstablished() Handles wifi_RN171.ConnectionEstablished
char_Display.SetCursor(1, 0)
char_Display.PrintString("connected! @ " & DateTime.Now.TimeOfDay.ToString)
Debug.Print("Connection Established @ " & DateTime.Now.TimeOfDay.ToString)
End Sub
Private Sub wifi_RN171_DataReceived(data As String) Handles wifi_RN171.DataReceived
Debug.Print("Data received @ " & DateTime.Now.TimeOfDay.ToString & " | " & data.ToString)
End Sub
End Class
End Namespace
Since my last message, I combined my second posted code with the source for the driver and find that the Initialize is returning false because it is timing out.
I also loaded the GHI example C# code and tried it using a FEZ Cerberus, but get the same results. I can connect to an Andriod pad, phone, iPad, and send a query to the 192.168.1.1 and this triggers the HttpRequestReveived event is triggered. No device gets the reply (“Hello”) in the example code, not the slightly longer response I posted above.
When I try with a WIn8.1 laptop, I can connect to the hotspot, but cannot get Chrome to trigger the interrupt, nor receive the reply. IE suggests I am not connected to a network.
So, it is functioning as a hotspot for non WIN8.1 machines and will generate an interrupt, but will not cannot receive the “HELLO” reply in a browser (Chrome or Safari).
Not sure what to do next, other than possibly order a different WiFi module, or bypass the driver and figure out how to reconfigure the RN171.
From your PC, check you have an IP address and it’s on the expected range from the DHCP server. Make sure it’s not connected to any other network as well, eg wired Ethernet. That seems to me to be the failure mode you’re experiencing, it doesn’t know how to route your packets to the web server.
@ rockybooth - Try init in ProgramStarted() and avoid the Reboot(), this is not needed as the same instructions get called at the beginning of Initialize()