Main Site Documentation

PPP trials


#1

Hi, I am trying to hook up my rig with PPP in the brand new 4.3.6 firmware. No luck so far, but it feels close.

Tried the barebone PPP example in the catalogue, not working either…

Cobra II with extender class, and cellular modem 1.1.

The below errors comes from code which is basically clean based on the example.


The thread '<No Name>' (0x3) has exited with code 0 (0x0).
The thread '<No Name>' (0x6) has exited with code 0 (0x0).
    #### Exception System.Threading.ThreadAbortException - 0x00000000 (5) ####
    #### Message: 
    #### System.Threading.Thread::Sleep [IP: 0000] ####
    #### Gadgeteer.Modules.GHIElectronics.CellularRadio::DoWork [IP: 0012] ####
Waiting on DHCP
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
The thread '<No Name>' (0x5) has exited with code 0 (0x0).
Waiting on DHCP
Network address changed
Network availability changed: False
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP
Waiting on DHCP

It never finds an IP…


#2

@ njbuch - how long did you let it run trying to find an IP?


#3

2-5 min


#4

Are you use this 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;

namespace your_namespace
{
     public partial class Program
     {
         void ProgramStarted()
         {
             NetworkChange.NetworkAvailabilityChanged += (a, b) => Debug.Print("Network availability changed: " + b.IsAvailable.ToString());
             NetworkChange.NetworkAddressChanged += (a, b) => Debug.Print("Network address changed");

             this.cellularRadio.ModuleInitialized += this.cellularRadio_ModuleInitialized;

             this.cellularRadio.PowerOn(30);
         }

         void cellularRadio_ModuleInitialized(CellularRadio sender)
         {
             new Thread(() =>
             {
                 Thread.Sleep(15000);

                 this.cellularRadio.UseThisNetworkInterface("Your APN", "Your username", "Your password", PPPSerialModem.AuthenticationType.Pap);

                 while (this.cellularRadio.NetworkInterface.IPAddress == "0.0.0.0")
                 {
                     Debug.Print("Waiting on DHCP");
                     Thread.Sleep(250);
                 }

                 using (var req = HttpWebRequest.Create("http://www.ghielectronics.com/") as HttpWebRequest)
                 {
                     req.KeepAlive = false;
                     req.ContentLength = 0;

                     using (var res = req.GetResponse() as HttpWebResponse)
                     {
                         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();
         }
     }
}

Is it?


#5

Yes, despite that I am using Cobra II with the helper class, so there is some slight changes in the begiining, and I added my APN stuff from other setups that I know is working.


#6

And one more question:
What’s the phone number you are using for data connection for your cellular operator? Method “UseThisNetworkInterface(string apn, string username, string password, PPPSerialModem.AuthenticationType authenticationType)” is used phone number: 99**2# for init data conection. Is this phone number right for you? In my case if I dial wrong number and after that call ppp.Connect(…) then ppp.Connect(…) doesn’t throws anything, but connection is not established, and IP always be “0.0.0.0”.

Here’s the code of “fixed” UseThisNetworkInterface(…)


        public void UseThisNetworkInterface(string phoneNumber, string apn, string username, string password, PPPSerialModem.AuthenticationType authenticationType)
        {
            if (this.networkInterface != null && this.networkInterface.get_Opened())
            {
                return;
            }
            this.serial.DiscardInBuffer();
            this.serial.DiscardOutBuffer();
            this.SendATCommand(string.Concat("AT+CGDCONT=2,\"IP\",\"", apn, "\""));
            this.SendATCommand("ATDT" + phoneNumber);
            Thread.Sleep(2500);
            this.worker.Abort();
            this.networkInterface = new PPPSerialModem(this.serial);
            this.networkInterface.Open();
            this.networkInterface.Connect(authenticationType, username, password);
            base.set_NetworkSettings(this.networkInterface.get_NetworkInterface());
        }

PS Sorry for my bad English… I’m working on it :slight_smile:


#7

The number needs to use the PDP context you setup with the AT+CGDCONT command.

This is normally 1 so use 99**1# as the dialing command. The 1 indicates the PDP context.

Eg.

AT+CGDCONTR=1,“IP”,“INTERNET”

sets the PDP context to 1 and requests IP packets and the APN is INTERNET.

I am not sure if your driver or the PPP driver for that matter sets the AT+CGDCONT command so if not, make sure this is done manually before dialing or PPP will fail.

EDIT: I just noticed your code uses the context number 2. Ooops. Sorry.


#8

One thing I do notice is that your code is not waiting or checking for the CONNECT after the dial?

Are you sue that your modem is connecting before you pass the serial port to the PPP driver?


#9

Thanks guys, will try tonight :slight_smile:

Not sure why this is not in the documentation, nor the sample…?


#10

Exactly !!!

            
this.SendATCommand(string.Concat("AT+CGDCONT=2,\"IP\",\"", apn, "\""));
this.SendATCommand("ATDT*99***2#");
Thread.Sleep(2500);
this.worker.Abort();
this.networkInterface = new PPPSerialModem(this.serial);
this.networkInterface.Open();
this.networkInterface.Connect(authenticationType, username, password);

Looks not so good :slight_smile:

PS: This code is reflected from GTM.GHIElectronics.CellularRadio.dll…


#11

Good luck :slight_smile:

I think GHI will correct the CellularRadio driver very fast…


#12

@ 4egod - Improving how the CellularRadio driver handles responses is definitely something on our list of things to improve. We cleaned up a few things in the last SDK but there are still numerous race conditions that require a lot of rework to fix.


#13

@ njbuch - After you call UseThisNetworkInterface, do you see the green status LED blink quickly on the module? If you let the program run for awhile trying to get an IP, does it eventually blink slowly?


#14

@ John - I now have an IP! ::slight_smile:

I did the change from @ 4egod and changed the dial-code to an argument, in Denmark “*99#” is the norm, and you have hardcoded another one. So now there is a connection I think.

Tried http://httpbin.org/ip which is really small, and it works. Now to some more testing.

Thanks


#15

Congratulations!
By the way… I have two weeks of stable work of G120 + PPP. And i’m very happy :slight_smile:


#16

And The strange exception?


#17

The *99# will work if you set PDP context 1, which is most likely what most drivers do (even the Android driver I have uses 1). With 4egod’s code, he uses PDP context 2 so the *99# wouldn’t work. When you don’t specify the context number with ***1 or ***2 etc, it defaults to 1.


#18

@ Dave McLaughlin

I agree, my fault, “*98#” doesn’t work with PDP context 2. But in our modems/cellular operators was used dial command “#777” for init data connection… and i don’t know it is operator’s settings or modem’s internal settings…


#19

@ All - We would like to provide a way for the module to just work for most users without them having to figure out detailed initialization strings, so that’s why we added those initialization strings. Though we will switch to PDP context 1 in the next SDK.

We can also add another overload that accepts an array of initialization strings and expected responses if our built in ones do not work for you so that you can utilize the existing request/response system of the driver.


#20

Not sure about the consequences of working in different contexts?