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
{
}
}
}
}