Hey, guys, I am struggling to use the wifi_rs21 module properly.
I succeeded in using the wifi module to connect to the network and post data to a web service at certain interval. But the socket exception would pop out after the application successfully running for a while. From the exception, according to socket error code description given by Microsoft, the reason might be no buffer space available. How can I solve this problem?
Another thing is after the WiFi_RS21 module connected to the wireless network, NetworkUp event was never triggered.
Here is the description of the exception:
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::socket [IP: 0000] ####
#### System.Net.Sockets.Socket::.ctor [IP: 001f] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 0132] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetRequestStream [IP: 0008] ####
#### GadgeteerLibrary.RESTClient::SendHistoricData [IP: 0038] ####
#### GadgeteerUseCaseOne.Program::sendTimer_Tick [IP: 0054] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in System.Http.dll
#### SocketException ErrorCode = 10055
#### SocketException ErrorCode = 10055
Here is part of my code showing how to connect to the network:
void ProgramStarted()
{
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
this.InitializeNetwork();
this.InitializeSDCard();
this.InitializeSensor();
}
void InitializeNetwork()
{
if (!wifi_RS21.Interface.IsOpen)
wifi_RS21.Interface.Open();
if (!wifi_RS21.Interface.NetworkInterface.IsDhcpEnabled)
wifi_RS21.Interface.NetworkInterface.EnableDhcp();
NetworkInterfaceExtension.AssignNetworkingStackTo(wifi_RS21.Interface);
// use the router's DHCP server to set my network info
wifi_RS21.UseDHCP();
// setup events
wifi_RS21.NetworkDown += wifi_NetworkDown;
wifi_RS21.NetworkUp += wifi_NetworkUp;
wifi_RS21.Interface.NetworkAddressChanged += Interface_NetworkAddressChanged;
wifi_RS21.Interface.WirelessConnectivityChanged += Interface_WirelessConnectivityChanged;
try
{
this.WifiConnect();
if (wifi_RS21.IsNetworkConnected)
{
// after connecting, set up local time and register the sensors.
this.SetLocalTime();
this.RegisterSensor();
}
}
catch (Exception e)
{
Debug.Print(e.Message);
}
}
void WifiConnect()
{
// to use hold the network to connect to
WiFiNetworkInfo[] targetNetwork = wifi_RS21.Interface.Scan(targetSSID);
// connect to the specified network
if (targetNetwork != null && targetNetwork.Length > 0)
{
WiFiNetworkInfo target = targetNetwork[0];
wifi_RS21.Interface.Join(target, password);
Debug.Print("Network joined");
Debug.Print("Up: " + wifi_RS21.IsNetworkUp.ToString());
Debug.Print("IP Address: " + wifi_RS21.NetworkSettings.IPAddress);
}
else
Debug.Print(targetSSID + " wireless network not found");
}
Thank you!