The WiFi RS21 module from GHI Electronics is an excellent and easy to use module for settup at WiFi connection. However, it’s a little tricky setting up a server application. You need to get the IP address assigned to the module from the dhcp server. This is done in the NetworkAddressChanged event before you join the network.
I’ve uploaded the example to my Gadgeteer GitHub repository. You can find out more information about the module on the Gadgeteer Page.
Creating a Gadgeteer Wifi RS21 server
This is the standard way to open and enable the wifi_RS21 interface.
if (!wifi_RS21.Interface.IsOpen)
{
wifi_RS21.Interface.Open();
}
if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)
{
wifi_RS21.Interface.NetworkInterface.EnableDhcp();
}
You must subscribe the NetworkAddressChanged event to get IP address
wifi_RS21.Interface.NetworkAddressChanged +=
new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
This method will catch the IP Address
void Interface_NetworkAddressChanged(object sender, EventArgs e)
{
ipAddress = wifi_RS21.Interface.NetworkInterface.IPAddress;
}
Running the server is easy at this point.
public void RunServer()
{
WebEvent GetValueEvent = WebServer.SetupWebEvent("GetValue");
GetValueEvent.WebEventReceived += new WebEvent.ReceivedWebEventHandler(GetValueEvent_WebEventReceived);
WebServer.StartLocalServer(ipAddress, 80);
}
The web event received can return any data you desire
void GetValueEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
{
responder.Respond("testing");
}