wifiRS21 - no Response

Ok, I now have a small project that all I’m doing is setting up a wifiRS21 module and trying to access a web page. I had a listing awhile ago that had a lot of code in it. This is real simple.

My other project works fine using the EthernetJ11D module but not using the wifiRS21 module. So now I have a real simple program.

And, it still does not work.
I get connected to my wifi and I get a valid IP.
But when I try to access a my web page it is a no go. The web page works as I tested it with a IE.

The program crashes at request.GetResponse()

As I said before, I have tried several examples with no luck.

This is what Debug.Print displayes:

#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message: 
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### WiFiTest.Program::SendData [IP: 0016] ####
#### WiFiTest.Program::ProgramStarted [IP: 0023] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060

A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### WiFiTest.Program::SendData [IP: 0016] ####
#### WiFiTest.Program::ProgramStarted [IP: 0023] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### WiFiTest.Program::SendData [IP: 0016] ####
#### WiFiTest.Program::ProgramStarted [IP: 0023] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll

This is the code:

using System;
using System.Collections;
//using System.Net;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net;

using Toolbox.NETMF.NET;

using Gadgeteer.Networking;
using Gadgeteer.SocketInterfaces;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Networking;


namespace WiFiTest
	{
	public partial class Program
		{
		void ProgramStarted()
			{
			Debug.Print("Program Started");
			SetupWiFi();
			if(wifiRS21.IsNetworkUp)
				{
				SendData("event=yes&TestResponse=WorkingGood");
				wifiRS21.NetworkInterface.Disconnect();
				wifiRS21.NetworkInterface.Close();
				}
			Debug.Print("Going, going -- gone");
			}							// end-of void ProgramStarted()


		private void SendData(string data)
			{
			string content;

			try
				{
				string sdata = "http://www.myWebSite.com/Monitor.php?" + data;

				HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sdata) as HttpWebRequest;
				
            HttpWebResponse response = (HttpWebResponse) request.GetResponse() as HttpWebResponse;
				using (StreamReader reader = new StreamReader(response.GetResponseStream()))
					{
					content = reader.ReadToEnd();
					reader.Close();
					}
				// Did we get the expected response? (a "200 OK")
				if(response.StatusCode != HttpStatusCode.OK)
					{
					Debug.Print("Unexpected HTTP response code: " + response.StatusCode.ToString());
					}					// end-of if(response.StatusCode != HttpStatusCode.OK)

				// Gets the response as a string
				string s = ParseResponse(response.ToString());
				Debug.Print("Response: (" + s + ")");
				}						// end-of try
			catch(Exception e)
				{
				Debug.Print("ERROR updating the web: " + e.Message);
				}						// end-of catch try
			}							// end-of private void SendData(string data)


		private void SetupWiFi()
			{
			if(wifiRS21.NetworkInterface.Opened)
				wifiRS21.NetworkInterface.Close();
			if(!wifiRS21.NetworkInterface.Opened)
				wifiRS21.NetworkInterface.Open();
			if(!wifiRS21.NetworkInterface.IsDhcpEnabled)
				wifiRS21.NetworkInterface.EnableDhcp();

			//wifiRS21.UseDHCP();
			wifiRS21.NetworkInterface.Join("my SSID", "my pass word");

			int esc = 0;
			while(wifiRS21.NetworkSettings.IPAddress == "0.0.0.0")
				{
				Thread.Sleep(200);
				if(++esc > 50)
					break;
				}
			if(esc < 50)
				{
				string ip = wifiRS21.NetworkSettings.IPAddress;
				Debug.Print("IP Address: " + ip);
				}
			else
				{
				Debug.Print("NO IP Address");
				}
			}							// end-of private void SetupWiFi()


		private string ParseResponse(string response)
			{
			string result = "";
			bool doingstring = false;
			bool startedstring = false;

			foreach(char c in response)
				if((c != '\r') && (c != '\n'))
					{
					if(startedstring)
						{
						doingstring = true;
						result += c.ToString();
						}
					}
				else
					{
					if(!startedstring)
						startedstring = true;
					else
						if(doingstring)
							break;
					}

			return (result);
			}							// end-of private string ParseResponse(string response)
		}								// end-of public partial class Program
	}									// end-of namespace WiFiTest

Any ideas ?
Thanks for any help,
Dave

@ dcas - Can you try the WiFi and HTTP examples on https://www.ghielectronics.com/docs/30/networking and see if they work?

Your example shows the following to setup WiFiRS9110:
netif = new WiFiRS9110(SPI.SPI_module.SPI1, Cpu.Pin.GPIO_Pin1, Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3);

Could you tell be how to setup the WiFiRS21 using a Spider bd running on 4.3.

Thanks,
Dave

@ dcas - What socket do you have the RS21 connected to?

It was on 6 but it is now on 9.

@ dcas - You’ll want:


netif = new WiFiRS9110(SPI.SPI_module.SPI1, (Cpu.Pin)15, (Cpu.Pin)46, (Cpu.Pin)6))

Still does not work.
I tried to access “http://google.com” AND my web page and both failed.
I did connect to my network and got a valid IP as the debug output shows.
My network is up and running.
I can access my web page and receive a response using Window’s IE.
I can also access http://google.com and receive a response with Window’s IE.

Following is the Debug.Print ourput:

Waiting for DHCP
Waiting for DHCP
Waiting for DHCP
Waiting for DHCP
Network availability: True
Waiting for DHCP
Waiting for DHCP
Waiting for DHCP
Waiting for DHCP
Waiting for DHCP
Network address changed
IP: 192.168.4.18
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00e1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### WiFiTest.Program::timer500ms_Tick [IP: 0098] ####
#### 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: 001d] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message: host not available
#### System.Net.HttpWebRequest::EstablishConnection [IP: 00f1] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### WiFiTest.Program::timer500ms_Tick [IP: 0098] ####
#### 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: 001d] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### WiFiTest.Program::timer500ms_Tick [IP: 0098] ####
#### 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: 001d] ####
A first chance exception of type ‘System.Net.WebException’ occurred in System.Http.dll
The program ‘[9] Micro Framework application: Managed’ has exited with code 0 (0x0).

Please note:
The first attempts I had all of the code inside void ProgramStarted().
I then moved the code to a timer so that void ProgramStarted() could exit and all lower code could run.
No go on both methods.

Dave

@ dcas - What version of the SDK are you using? Can you post the new code you made to test it outside of Gadgeteer?

I hope this is what you wanted:
Gadgeteer: Runtime=4.0.30319 - version 2.43.1.0
Gadgeteer.Serial Runtime=4.0.30319 - version 2.43.1.0
GHI.Networking: Runtime=v.0.30319 - version 4.3.3.0

all Microsoft.SPOT: runtime=4.030319 - version 4.3.1.0

Target Framework: 4.3 (in Visual Studio Express 2012)

Spider is new (just received last week):
Loader: 4.3.3
TinyCLR: 4.3.3

What do you mean about posting the code outside of Gadgeteer ?

Dave

Just noticed, I’m on 4.3 R2.
Now downloading 4.3 R5.

Will run same test again to see if this helps.
Do I need to do anything in Visual Studio for the program to use this new version ?

Dave

All my fault.
Updating to R5 seems to have fixed the problem.
The test program worked when accessing my web page.

Will now try to put the WiFiRS21 back into my project.

Sorry for taking up so much of your time,
Dave

There is one thing in the example you told me to use that I had to change to get that code to work.
I had to change the line:
using (var stream = res.GetResponseStream())
to
using (var stream = res.GetResponseStream() as System.IO.Stream)

My main project is now running with the WiFiRS21 module running and updating my web page with the current well housing temperature (along with other temperatures).

Again, thanks so very much.
Next time I will try to remember to check the versions.

Dave

@ dcas - We’ll take a look at that example, thanks. Glad to hear you got it working.