Yes, the new version of the cellular driver downloaded from bitbucket is much more stable than the older ones. Thanks @ John for that.
I have added a few lines of debug code inside the driver to get some meaningful output.
But the PPP is now on the bench, and I cant figure out whats going wrong for my code:
using Gadgeteer.Modules.GHIElectronics;
using GHI.Networking;
using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;
using System.Net;
using System.Text;
using System.Threading;
using Gadgeteer.Modules.GHIElectronics;
using G120 = GHI.Pins.G120;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules.Module;
namespace PPPTest2
{
public partial class Program
{
void ProgramStarted()
{
this.RegisterExtenderSockets();
this.cellularRadio = new CellularRadio(8);
cellularRadio.DebugPrintEnabled = true;
NetworkChange.NetworkAvailabilityChanged += (a, b) => Debug.Print("Network availability changed: " + b.IsAvailable.ToString());
NetworkChange.NetworkAddressChanged += (a, b) => Debug.Print("Network address changed");
Debug.Print("Now starting cellular..");
this.cellularRadio.PowerOn();
Thread.Sleep(60000);
Debug.Print("Now using cellular..");
cellularRadio_ModuleInitialized(this.cellularRadio);
}
void cellularRadio_ModuleInitialized(CellularRadio sender)
{
Debug.Print("Starting test request code..");
new Thread(() =>
{
Thread.Sleep(1000);
Debug.Print("Now setting up interface..");
this.cellularRadio.UseThisNetworkInterface("internet", "", "", PPPSerialModem.AuthenticationType.Pap);
Debug.Print("Now waiting for IP..");
while (this.cellularRadio.NetworkInterface.IPAddress == "0.0.0.0")
{
Debug.Print("Waiting on DHCP");
Thread.Sleep(1000);
}
Debug.Print("IP:" + this.cellularRadio.NetworkInterface.IPAddress);
using (var req = HttpWebRequest.Create("http://httpbin.org/ip") as HttpWebRequest)
{
req.KeepAlive = false;
req.ContentLength = 0;
using (var res = req.GetResponse() as HttpWebResponse) // HERE IT THROWS CLR_E_FAIL!!
{
using (var stream = res.GetResponseStream())
{
int read = 0, total = 0;
var buffer = new byte[1024];
do
{
read = stream.Read(buffer, 0, buffer.Length);
total += read;
Thread.Sleep(20);
} while (read != 0);
Debug.Print(new string(Encoding.UTF8.GetChars(buffer)));
}
}
}
}).Start();
}
}
}
OUTPUT:
Now starting cellular..
CellularRadio : MODEM:NORMAL POWER DOWN
CellularRadio : MODEM:+CREG: 3
CellularRadio : MODEM:+CGREG: 3
CellularRadio : SEND TO MODEM:AT
CellularRadio : SEND TO MODEM:ATE0
CellularRadio : SEND TO MODEM:AT+CMGF=1
CellularRadio : MODEM:AT
CellularRadio : MODEM:OK
CellularRadio : MODEM:ATE0
CellularRadio : MODEM:OK
CellularRadio : SEND TO MODEM:AT+CSDH=0
CellularRadio : SEND TO MODEM:AT+CPBS="SM"
CellularRadio : SEND TO MODEM:AT+CPMS="SM"
CellularRadio : MODEM:OK
CellularRadio : MODEM:+CREG: 2
CellularRadio : MODEM:OK
CellularRadio : MODEM:OK
CellularRadio : SEND TO MODEM:AT+COLP=1
CellularRadio : SEND TO MODEM:AT+CGREG=1
CellularRadio : MODEM:+CMS ERROR: SMS reserved
CellularRadio : MODEM:OK
CellularRadio : MODEM:OK
CellularRadio : SEND TO MODEM:AT+CREG=1
CellularRadio : MODEM:OK
WARN: Total initialization time exceeds 10 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
CellularRadio : MODEM:+CGREG: 0
CellularRadio : MODEM:+CREG: 1
CellularRadio : MODEM:*PSUTTZ: 2014, 12, 21, 22, 43, 11, "+4", 1
CellularRadio : MODEM:DST: 1
CellularRadio : MODEM:*PSUTTZ: 2014, 12, 21, 22, 43, 14, "+4", 0
CellularRadio : MODEM:DST: 0
CellularRadio : MODEM:+CGREG: 1
WARN: Total initialization time exceeds 20 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
WARN: Total initialization time exceeds 30 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
WARN: Total initialization time exceeds 40 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
WARN: Total initialization time exceeds 50 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
WARN: Total initialization time exceeds 60 seconds.
: ProgramStarted is blocking execution, which means events and timers will not run properly.
: Make sure not to use blocking code such as while(true) - use a GT.Timer instead.
Now using cellular..
Starting test request code..
Now setting up interface..
CellularRadio : SEND TO MODEM:AT+CGDCONT=1,"IP","internet"
CellularRadio : SEND TO MODEM:ATDT*99***1#
CellularRadio : MODEM:OK
CellularRadio : MODEM:CONNECT
The thread '<No Name>' (0x7) has exited with code 0 (0x0).
Now waiting for IP..
Waiting on DHCP
The thread '<No Name>' (0x5) has exited with code 0 (0x0).
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Network address changed
Network availability changed: True
IP:10.160.179.81
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (8) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.NetworkStream::Write [IP: 0051] ####
#### System.Net.InputNetworkStreamWrapper::Write [IP: 000a] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 007d] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### PPPTest2.Program::<cellularRadio_ModuleInitialized>b__4 [IP: 0073] ####
#### SocketException ErrorCode = 10053
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10053
#### SocketException ErrorCode = 10053
#### SocketException ErrorCode = 10053
#### Exception System.Net.WebException - 0x00000000 (8) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### PPPTest2.Program::<cellularRadio_ModuleInitialized>b__4 [IP: 0073] ####
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
An unhandled exception of type 'System.Net.WebException' occurred in System.Http.dll
The program '[15] Micro Framework application: Managed' has exited with code 0 (0x0).