PPP error when trying out tutorial

I get this when trying to use PPP from the tutorial
Using LTE IoT 2 click

Code:
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Uart;
using GHIElectronics.TinyCLR.Pins;
using System;
using System.Collections;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading;

namespace TinyCLRApplication4
{
    class Program
    {
        static bool linkReady = false;

        static void Main()
        {
            var reset = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD13);
            reset.SetDriveMode(GpioPinDriveMode.Output);

            var button = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE3);
            button.SetDriveMode(GpioPinDriveMode.InputPullUp);
            button.ValueChanged += Reset_ValueChanged;

            reset.Write(GpioPinValue.High);
            Thread.Sleep(200);

            reset.Write(GpioPinValue.Low);
            Thread.Sleep(7000); //Wait for modem to initialize.

            InitSimCard();
            //TestPPP();

            //TestHttp();

            Thread.Sleep(Timeout.Infinite);
        }

        private static void Reset_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            if (e.Edge == GpioPinEdge.RisingEdge) {
                TestPPP();
                TestHttp();
            }
        }

        static void InitSimCard()
        {
            var serial = UartController.FromName(SC20100.UartPort.Uart4);

            var settings = new UartSetting() { BaudRate = 115200, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None };
            serial.SetActiveSettings(settings);

            serial.Enable();

            while (!SendAT(serial, "AT")) { }

            SendAT(serial, "AT+CGDCONT=1,\"IPV4V6\",\"OLIVIA\"");
            SendAT(serial, "ATDT*99***1#");

            Debug.WriteLine("OK to start PPP....");
        }

        static void TestPPP()
        {
            var networkController = NetworkController.FromName("NativeApis.Ppp.NetworkController");

            PppNetworkInterfaceSettings networkInterfaceSetting = new PppNetworkInterfaceSettings()
            {
                AuthenticationType = PppAuthenticationType.Pap,

                Username = "",
                Password = "",
            };

            UartNetworkCommunicationInterfaceSettings networkCommunicationInterfaceSettings = new UartNetworkCommunicationInterfaceSettings()
            {
                ApiName = SC20100.UartPort.Uart4,
                BaudRate = 115200,
                DataBits = 8,
                Parity = UartParity.None,
                StopBits = UartStopBitCount.One,
                Handshaking = UartHandshake.None,
            };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;

            networkController.Enable();

            while (linkReady == false) { }
            //Network is now ready to use.
        }

        private static void NetworkController_NetworkLinkConnectedChanged
            (NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
        {
            //Raise event connect/disconnect
        }

        private static void NetworkController_NetworkAddressChanged
            (NetworkController sender, NetworkAddressChangedEventArgs e)
        {

            var ipProperties = sender.GetIPProperties();
            var address = ipProperties.Address.GetAddressBytes();

            Debug.WriteLine("IP Address: " + address[0] + "." + address[1]
                + "." + address[2] + "." + address[3]);

            linkReady = address[0] != 0;
        }

        static bool SendAT(UartController port, string command)
        {

            command += "\r";

            var sendBuffer = Encoding.UTF8.GetBytes(command);
            var readBuffer = new byte[256];
            var read = 0;
            var count = 10;

            port.Write(sendBuffer, 0, sendBuffer.Length);

            while (count-- > 0)
            {
                Thread.Sleep(100);

                read += port.Read(readBuffer, read, readBuffer.Length - read);

                var response = new string
                    (Encoding.UTF8.GetChars(readBuffer, 0, read));

                if (response.IndexOf("OK") != -1 || response.IndexOf("CONNECT") != -1)
                {
                    Debug.WriteLine(" " + response);
                    return true;
                }
            }
            return false;
        }

        static void TestHttp() {
            var url = "http://www.bing.com/robots.txt";

            int read = 0, total = 0;
            byte[] result = new byte[512];

            try
            {
                using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
                {
                    req.KeepAlive = false;
                    req.ReadWriteTimeout = 2000;

                    using (var res = req.GetResponse() as HttpWebResponse)
                    {
                        using (var stream = res.GetResponseStream())
                        {
                            do
                            {
                                read = stream.Read(result, 0, result.Length);
                                total += read;

                                Debug.WriteLine("read : " + read);
                                Debug.WriteLine("total : " + total);

                                String page = "";

                                page = new String(System.Text.Encoding.UTF8.GetChars
                                    (result, 0, read));

                                Debug.WriteLine("Response : " + page);
                            }

                            while (read != 0);
                        }
                    }
                }
            }
            catch
            {
            }
        }
    }
}

This does not work, anyone tried using the module?

I can confirm my SIM card is working, ive tried with a phone, and i can confirm the module is working ive connected as a modem to windows 10, and its working.

Tried everything from PPP aplication note, nothing works
I can also connect to the module with QNavigator and issue AT commands with no problem

We will be looking into this

We have tested again PPP and it is still working fine.

Also, the string

"NativeApis.Ppp.NetworkController" 

is wrong, it has to be:

"GHIElectronics.TinyCLR.NativeApis.Ppp.NetworkController"

Is the tutorial wrong?

Can you send me your test code?

Try to change “NativeApis.Ppp.NetworkController”
by
“GHIElectronics.TinyCLR.NativeApis.Ppp.NetworkController”

  1. Check your reset pin, it may different with us when low or high for reseting.

Yeah i know all of that, the UART port is also different.
Ill try to change the network controller name, but now i cant seem to get past

while (!SendAT(serial, "AT")) { }

in the screenshot you can see i got past that, the AT commands worked yesterday, i think i messed something up with the module.
ive tried factory reset, now i dont know whats wrong.

ill try with the dev boards

Is this running in your own custom board? What current do you have available on the supply for the click board? Modems often require at least 2A surge protection. I found that I had to add 3 x 100uF tant caps to prevent the modem failing.

Its not returning anything from the AT commands, why is this so hard :-(, its working ok in Qnavigator but nothing works anymore in tinyclr

there are commands try to use
https://www.quectel.com/UploadImage/Downlad/Quectel_BG96_AT_Commands_Manual_V2.1.pdf

2.10. AT&F Set All Current Parameters to Manufacturer Defaults

AT&F[0] - The command resets AT command settings to their factory default values.

Did that, if i type

AT&F[0]
[2020-12-30 15:00:03:904_S:] AT&F[0]
[2020-12-30 15:00:03:957_R:] AT&F[0]
[2020-12-30 15:00:03:957_R:] ERROR

AT&F0
[2020-12-30 15:01:26:229_S:] AT&F0
[2020-12-30 15:01:26:287_R:] AT&F0
[2020-12-30 15:01:26:287_R:] OK

so that means its gone through
still not working, when i try with the dev baord just to issue “AT”, its not returning anything

EDIT: ill try all of the commands that go with qnavigator initialization to see if it will work

The tutorial code is flawed in several places

I managed to get it working, but not in TinyCLR.
There is a proper procedure to enable and terminate PPP mode and needs to be followed else it will not reenable AT mode. But still i cant get it to work in TinyCLR

var networkController = NetworkController.FromName("NativeApis.Ppp.NetworkController"); //wrong
var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.Ppp.NetworkController");

SendAT(serial, "ATDT*99***1#"); // wrong
SendAT(serial, "ATD*99#");

When i enable PPP debugger crashes and module restarts several times (i think 3 times), possibly windows reads 3 ports

Screenshot 2020-12-31 122203

what am i doing wrong??

Isn’t the IoT click connected via the UART for control of the modem?

On the PC, this appears to be connected via USB which would indeed appear as 3 or more UARTS. This one of the reasons for the request to GHI for USB UART support.

After you connect to PPP with TinyCLR, are you attempting to do any AT commands?

No, after

SendAT(serial, "ATD*99#");
Debug.WriteLine("OK to start PPP....");

i just TestPPP, and it crashes then

@Dat_Tran, can you send me a sample of your test code?

I can send of course, it is same as doc. But I am sure it won’t help. Reason is, you are having problem with sending AT command, string connection which has nothing to do with PPP yet. It just gives you more confuse.

From our experience, make sure send AT command and get response OK first.

Reset, send AT command, get Reponse…

Until you know exactly the sequence of resetting, get response 100% every time after reset.

Sometime it response because you are lucky, then try again it doesn’t work… happened when we are first time trying with some PPP module.

  1. After that, you have to make sure the configuration of the module is in proper config. Some modules allow you to store couples config string from different network provider, but maybe just one of them is active at the same time. You may need to active the right config first. If so there is a AT command to do that, it depends on your module.

Just hangs here:

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
reset
wait
done wait
 AT

OK

 AT+CGDCONT=1,"IP","OLIVIA"

OK

 ATDT*99***1#

CONNECT 150000000

OK to start PPP....

code:

 class Program
    {
        static bool linkReady = false;

        static GpioPin reset = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD13);
        static GpioPin button = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE3);

        static UartController serial = UartController.FromName(SC20100.UartPort.Uart4);

        static void Main()
        {
            reset.SetDriveMode(GpioPinDriveMode.Output);

            button.SetDriveMode(GpioPinDriveMode.InputPullUp);
            button.ValueChanged += Button_ValueChanged;

            Debug.WriteLine("reset");
            reset.Write(GpioPinValue.High);
            Thread.Sleep(200);
            Debug.WriteLine("wait");
            reset.Write(GpioPinValue.Low);
            Thread.Sleep(7000); //Wait for modem to initialize.
            Debug.WriteLine("done wait");

            var settings = new UartSetting() { BaudRate = 115200, DataBits = 8, Parity = UartParity.None, StopBits = UartStopBitCount.One, Handshaking = UartHandshake.None };
            serial.SetActiveSettings(settings);

            serial.Enable();

            Thread.Sleep(Timeout.Infinite);
        }

        private static void Button_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            if (e.Edge == GpioPinEdge.RisingEdge)
            {
                SendAT(serial, "AT");
                SendAT(serial, "AT+CGDCONT=1,\"IP\",\"OLIVIA\"");
                //SendAT(serial, "ATD*99#");

                SendAT(serial, "ATDT*99***1#");

                Debug.WriteLine("OK to start PPP....");

                TestPPP();


            }
        }

        static void TestPPP()
        {
            var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.Ppp.NetworkController");

            PppNetworkInterfaceSettings networkInterfaceSetting = new PppNetworkInterfaceSettings()
            {
                AuthenticationType = PppAuthenticationType.Pap,

                Username = "",
                Password = "",
            };

            UartNetworkCommunicationInterfaceSettings networkCommunicationInterfaceSettings = new UartNetworkCommunicationInterfaceSettings()
            {
                ApiName = SC20100.UartPort.Uart4,
                BaudRate = 115200,
                DataBits = 8,
                Parity = UartParity.None,
                StopBits = UartStopBitCount.One,
                Handshaking = UartHandshake.None,
            };

            networkController.SetInterfaceSettings(networkInterfaceSetting);
            networkController.SetCommunicationInterfaceSettings
                (networkCommunicationInterfaceSettings);

            networkController.SetAsDefaultController();

            networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
            networkController.NetworkLinkConnectedChanged +=
                NetworkController_NetworkLinkConnectedChanged;

            networkController.Enable();

            while (linkReady == false) { }
            //Network is now ready to use.
            Debug.WriteLine("Network is ready to use");
        }

        private static void NetworkController_NetworkLinkConnectedChanged
            (NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
        {
            //Raise event connect/disconnect
        }

        private static void NetworkController_NetworkAddressChanged
            (NetworkController sender, NetworkAddressChangedEventArgs e)
        {

            var ipProperties = sender.GetIPProperties();
            var address = ipProperties.Address.GetAddressBytes();

            Debug.WriteLine("IP Address: " + address[0] + "." + address[1]
                + "." + address[2] + "." + address[3]);

            linkReady = address[0] != 0;
        }


        static bool SendAT(UartController port, string command)
        {

            command += "\r";

            var sendBuffer = Encoding.UTF8.GetBytes(command);
            var readBuffer = new byte[256];
            var read = 0;
            var count = 10;

            port.Write(sendBuffer, 0, sendBuffer.Length);

            while (count-- > 0)
            {
                Thread.Sleep(100);

                read += port.Read(readBuffer, read, readBuffer.Length - read);

                var response = new string
                    (Encoding.UTF8.GetChars(readBuffer, 0, read));

                if (response.IndexOf("OK") != -1 || response.IndexOf("CONNECT") != -1)
                {
                    Debug.WriteLine(" " + response);
                    return true;
                }
            }
            return false;
        }
    }

I should get this when its working?

Debug.WriteLine(“Network is ready to use”);

I don’t remember the AT commands but I would poll the signal strength and connection status until they are valid before I try to start the PPP connection.