As some of you may know, I have been working on getting a stable PPP connection for the least few weeks since the latest SDK was released.
My progress up until last week was looking good until I decided the leave the unit working over night. I woke to find that the modem was no longer responding to AT commands or at least it appeared to not be. On checking the TXD line from the modem with a scope, I could see that the modem was indeed sending out replies but the code was not seeing them. My debug output in OnLineReceived was not being fired.
I have spent the last few days tracking this down and I appear to have this now working. It does require code outside of the Cellular Driver to recover from this and I have also done some changes to the Cellular Driver to add extra handling to give additional features that assist with this. It basically comes down to the fact that when the modem drops the connection, you need to run a few tasks to close the PPP connection and re-start the background serial handler. Something I was not doing and sometimes due to the way the code runs, especially if the PPP connection does not connect when called. This is now fixed in the driver.
I woke this morning to find that after approx 24 hours running, it is still connecting to PPP and after a short time the GSM network sees that I am not sending so drops the connection and then my code recovers from this and restarts the connection after a short time. Itās been doing this with success on every reconnect now.
Just in time too as I have to deliver 2 demo units next week. Talk about cutting it close
Iāll be leaving this on test over the weekend so if all goes to plan I will release the modified driver to Codeshare but please note that this is targeted for Pure NETMF and not Gadgeteer. Using the original driver will allow you to port this to Gadgeteer with ease. My version allows you to set the baud rate and I have been testing with 115200 with good success and using hardware handshaking.
That could well be. I do occasionally get the exception but it gets handled and continues on. Your fix would stop this happening. Iāll implement this and test and then update the codeshare.
Thanks for testing it
PSā¦ I just shipped the first 2 prototypes to the client today so fingers crossed the drive behaves itself.
Would it be possible for you to extend your sample code to show the steps to initiate a 2.5/3G data connection? I want to make an HttpWebRequest but I donāt ever see a NetworkChange.NetworkAvailabilityChanged event, is that expected?
I can see my device looping on startup, then then registering on the GSM & GPRS networks. I then call gsmModem.UseThisNetworkInterface(āinternetā) but Iām not certain this is the right spot.
I think the reason for the fact that the NetworkAvailabilityChanged is never called is that you are not actually getting a PPP connection to your network.
I check the IsNetworkConnected to know if the network is alive or not. If not and I need a connection, I make this call:
Are you using the correct APN for your network? Is āinternetā correct? Does it need a username and password etc. Which phone network are you trying to connect to?
@ Dave McLaughlin - Got stuck in debugging another issue in an Azure application, back on NetMF this evening
First I wait for the network to sort itself out, then initiate the connection but it never connects
while (gsmState != CellularRadio.NetworkRegistrationState.Registered && gsmState != CellularRadio.NetworkRegistrationState.Roaming)
{
gsmModem.RequestNetState();
gsmModem.RequestSignalStrength();
gsmModem.SendATCommand("AT+CREG?"); // Get the registration state
Attempts++;
if (Attempts > 60) // We should wait 60 seconds for GSM attach
{
Attempts = 0;
gsmModem.PowerOn(true); // Try to power up again
}
Thread.Sleep(1000);
}
...
gsmModem.UseThisNetworkInterface("internet");
...
while (!gsmModem.IsNetworkConnected)
{
Status.Write(!Status.Read());
Thread.Sleep(250);
}
In the output window I see (send logging off as too much noise)
We may need GHI to look at this again seeing as you are using a different modem. It has been tested with SIM5230 and SIM900 so there might be something in the PPP packet negotiation that is different with your SIM5216. Wish we could enable debug output from the PPP driver so we could see what it is doing.
If anyone from GHI is reading this and knows about the PPP connection, how are you handling the magic number negotiation? Iāve found that can be an issue and having a way to disable or enable this often means PPP negotiates or doesnāt.
The simplest example I could create. The only mod to your cellular driver code is changing the GPIO port number to work with my shield.
gsmModem = new CellularRadio("COM1", 19200);
int Attempts = 0;
gsmModem.GsmNetworkRegistrationChanged += gsmModem_GsmNetworkRegistrationChanged;
gsmModem.SmsListReceived += gsmModem_SmsListReceived;
gsmModem.SignalStrengthRequested += gsmModem_SignalStrengthRequested;
gsmModem.GprsNetworkRegistrationChanged += gsmModem_GprsNetworkRegistrationChanged;
gsmModem.ClockRequested += gsmModem_ClockRequested;
gsmModem.NetStateRequested += gsmModem_NetStateRequested;
gsmModem.ImeiRequested += gsmModem_ImeiRequested;
gsmModem.LineReceived += gsmModem_LineReceived;
gsmModem.LineSent += gsmModem_LineSent;
NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
gsmModem.PowerOn(false);
//
// We need to wait until the modem is ready and registered on the network
// We can go around and around in here forever because if no modem, no
// point going past this point.
//
while (gsmState != CellularRadio.NetworkRegistrationState.Registered && gsmState != CellularRadio.NetworkRegistrationState.Roaming)
{
gsmModem.RequestNetState();
gsmModem.RequestSignalStrength();
gsmModem.SendATCommand("AT+CREG?"); // Get the registration state
Attempts++;
if (Attempts > 60) // We should wait 60 seconds for GSM attach
{
Attempts = 0;
gsmModem.PowerOn(true); // Try to power up again
}
Thread.Sleep(1000);
}
gsmModem.UseThisNetworkInterface("vodafone");
while (!gsmModem.IsNetworkConnected )
{
Status.Write(!Status.Read());
Thread.Sleep(250);
}
try
{
using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.co.nz"))
{
request.Method = "GET";
request.ContentType = "text/csv";
request.KeepAlive = false;
request.Timeout = 5000;
request.ReadWriteTimeout = 5000;
using (var response = (HttpWebResponse)request.GetResponse())
{
Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
}
}
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
Thread.Sleep(Timeout.Infinite);
I get this output
ā¦
gsmModem_LineReceived AT+CSQ
gsmModem_LineReceived +CSQ: 13,0
gsmModem_SignalStrengthRequested 13
gsmModem_LineReceived OK
gsmModem_LineReceived AT+CREG?
gsmModem_LineReceived +CREG: 1,2
gsmModem_GsmNetworkRegistrationChanged 2
Gsm Network Registration Changed - Searching
gsmModem_LineReceived OK
gsmModem_LineReceived +CREG: 1
gsmModem_GsmNetworkRegistrationChanged 1
Gsm Network Registration Changed - Registered
gsmModem_LineReceived +CGREG: 0
gsmModem_GprsNetworkRegistrationChanged 0
Gprs Network Registration Changed - Not Searching
gsmModem_LineSent AT+CGDCONT=1,āIPā,āvodafoneā
gsmModem_LineReceived AT+CGDCONT=1,āIPā,āvodafoneā
gsmModem_LineReceived OK
gsmModem_LineSent ATD991#
gsmModem_LineReceived ATD99**1#
gsmModem_LineReceived CONNECT
The thread āā (0x3) has exited with code 0 (0x0).
Wait for a while (30secs or a minute maybe )
NetworkChange_NetworkAddressChanged
NetworkChange_NetworkAvailabilityChanged False
Dave, any suggestions?
If someone from GHI is watching any hints on debugging?
@ Bryn Lewis - Unfortunately there is no debug output from the native PPP driver. The best route at this point is to monitor the two serial lines, capture the traffic, and decode the PPP communication to see what error is happening.