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