I just posted Ported CellularDriver_43 for Pure NETMF on Codeshare. Feel free to discuss and make suggestions here.
Great driver! I am trying to reuse it with the SIM808 on a fona board. I am able to establish a ppp connection, send http data to a website, and then close the connection. The problem is that I can only do it once, the second time the UseThisNetworkInterface is called it does not succeed. Here is the code:
public static void Main()
{
gsmModem = new CellularRadio("COM3", 115200);
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.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
int count = 0;
while (count < 5)
{
count++;
gsmModem.PowerOn(true);
gsmModem.SendATCommand("AT+CSCS=\"GSM\"");
gsmModem.SendATCommand("AT+CMGD=1,3"); // Delete all read message from the modem
gsmModem.RequestImei();
gsmModem.UseThisNetworkInterface("blue");
// http call to send data to a website
SendErrorLog(DateTime.Now, 596);
// wait and then disconnect
Thread.Sleep(500);
gsmModem.DisconnectPPP();
// simulate a wait for the next connection
Thread.Sleep(60000);
}
Thread.Sleep(1000);
}
After sending the first http update, CellularRadio method DisconnectPPP is called. It sets the PPPSerialModem networkInterface value to null. The gsmmodem is then in AT mode, thus the gsmModem SendATCommand methods still works.
So, then when the gsmModem.UseThisNetworkInterface(âblueâ); method is called the second time. The CellularRadio method this.networkInterface.Connect(authenticationType, username, password); fails. (it worked the first time and if I step through the code it sometimes works as well), but when I run the attached code the following exception is always displayed.
#### Exception GHI.Networking.PPPSerialModem+ConnectionFailedException - 0x00000000 (1) ####
#### Message:
#### GHI.Networking.PPPSerialModem::Connect [IP: 00a6] ####
#### GHI.Networking.PPPSerialModem::Connect [IP: 000b] ####
#### CellularDriver.CellularRadio::UseThisNetworkInterface [IP: 012a] ####
#### CellularDriver.CellularRadio::UseThisNetworkInterface [IP: 0037] ####
#### CellularDriver.CellularRadio::UseThisNetworkInterface [IP: 000d] ####
#### Fona808Sample.Program::Main [IP: 00d7] ####
A first chance exception of type âGHI.Networking.PPPSerialModem.ConnectionFailedExceptionâ occurred in GHI.Networking.dll
what happens if you donât do a PPP disconnect? Why do you want to do that, anyway?
I need to send a small amout of data once a day. In order to reduce power usage and data usage I would like to connect send the data and disconnect.
When I disconnect the serial reply is no carrier. The when I send the at commas to connect again I receive a connect Responce. The problem is the PPP connection fails to connect. Is their way to tell if it was closed properly??
@ elissard - are you sure you supply power enough to the cellular module?
I suspect this is due to timing as you said it sometimes works if you step into it. I run this without fail on a G400. What module are you using?
Look in the UseNetworkInterface function call and look for this code;
if (pppConnected) // Only try to connect if we got a connect from the modem?
{
this.running = false; // Shutdown the worker thread
this.worker.Join();
this.worker = null;
//
// Start the PPP process.
// Call IsNetworkConnected to know if this succeeded
//
this.networkInterface = new PPPSerialModem(this.serial);
this.networkInterface.Open();
Insert a Thread.Sleep(100); after the this.worker=null; call. The worker thread may not be cleanly exited. Possible!!
Or insert a breakpoint on this line and when it breaks, hit RUN again and see if you connect. If it does, insert the Thread.Sleep as above.
concerning power, I ran it again this morning the and added the gsmModem.SendATCommand(âAT+CBCâ); command it returned LineReceived - +CBC: 0,59,3874. It is odd that the battery reads 3.8 volts at 59%. However, I have dc power connected to the usb interface board to the spider and have a battery connected to the fona. Also the fona blue led plinks blue every 3 seconds and then when a connection is made it blinks twice a second. So I think I am providing enough power.
Dave, I am using a spider and am only testing the fona. I think your observation is correct, I just canât figure out how to solve it. I have put sleep statements and I have added pppEvent Resets for âNO CARRIERâ, thinking the dirver didnât close out the previous connection. Nothing seems to work. Even when stepping through the code it rarely is succesful. If you have another suggestion Ill give it a try the sleep statement didnât work for me.