The AT command I used to use was AT+CGREG which returns the connection state. You want this to be registered on the network as it could be searching.
In your code, you have handshaking set to NONE. Iâve not checked the schematic for the dev board but the LTE IoT click has both RTS and CTS. Their use is probably mandatory for the modem.
Its not that @skeller @Dave_McLaughlin, im checking for all of that before PPP.
About handshaking, on dev board its used on UART8 which does not have a dedicated RTS CTS pins.
It now consistently crashes the debugger every time. Then i have to unplug power, because reset does nothing.
Found debugger!
Create TS.
Loading Deployment Assemblies.
Attaching deployed file.
Assembly: mscorlib (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Devices.Network (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Networking (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Devices.Uart (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Devices.Spi (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Native (2.0.0.0) Attaching deployed file.
Assembly: GHIElectronics.TinyCLR.Devices.Gpio (2.0.0.0) Attaching deployed file.
Assembly: TinyCLRApplication4 (1.0.0.0) Resolving.
Ready.
reset
done wait
AT
OK
ATI
Quectel
BG96
Revision: BG96MAR03A06M1G
OK
ATV1
OK
ATE1
OK
AT+CMEE=2
OK
AT+IPR?
+IPR: 115200
OK
ATI
Quectel
BG96
Revision: BG96MAR03A06M1G
OK
AT+GSN
860536047736717
OK
AT+QURCCFG="URCPORT","usbat"
OK
AT+CPIN?
+CPIN: READY
OK
AT+CIMI
234500023606265
OK
AT+QCCID
+QCCID: 8944501103206062652F
OK
AT+CSQ
+CSQ: 16,99
OK
AT+CREG?
+CREG: 0,5
OK
AT+CGREG?
+CGREG: 0,5
OK
AT+COPS?
+COPS: 1,0,"HT HR",3
OK
AT+CEREG?
+CEREG: 0,0
OK
AT+CGDCONT=1,"IP","OLIVIA"
OK
ATD*99#
CONNECT 150000000
OK to start PPP....
I found something interesting that might be at fault. According to a search, the APN is case sensitive and the Olivia Wireless website shows the APN as âoliviaâ and not âOLIVIAâ
Worth a try but if that is the case, something in the PPP driver is at fault here and it should not be crashing or hanging but recover with an error. It would be good to have a debug enable on the PPP code that we can enable to help track down faults like this. Shame all of my kit is boxed for the move as I would be interested to see if this works too.
If GHI remembers a long time ago, this was something we did for the old NETMF PPP driver where I was unable to make a connection due to the magic number in the PPP protocol not being implemented. I also did the same with Netburner before that. Same issue.
Shouldnât the response from CEREG? be 0,1 instead of 0,0?
CREG? and CGREG? of 0,5 indicate it is roaming on a non-home network.
https://itectec.com/spec/10-1-22-eps-network-registration-status-cereg/
Ok, ill try case sensitive and look if there is a setting on the module to allow data roaming.
Nope, still crashesâŚ
Tried both things, as you can see in roamservice
AT
OK
ATI
Quectel
BG96
Revision: BG96MAR03A06M1G
OK
ATV1
OK
ATE1
OK
AT+CMEE=2
OK
AT+IPR?
+IPR: 115200
OK
ATI
Quectel
BG96
Revision: BG96MAR03A06M1G
OK
AT+GSN
860536047736717
OK
AT+QURCCFG="URCPORT","usbat"
OK
AT+CPIN?
+CPIN: READY
OK
AT+CIMI
234500023606265
OK
AT+QCCID
+QCCID: 8944501103206062652F
OK
AT+QCFG="roamservice"
+QCFG: "roamservice",1
OK
AT+QCFG="roamservice",2,1
OK
AT+QCFG="roamservice"
+QCFG: "roamservice",2
OK
AT+CSQ
+CSQ: 14,99
OK
AT+CREG?
+CREG: 0,5
OK
AT+CGREG?
+CGREG: 0,5
OK
AT+COPS?
+COPS: 1,0,"HT HR",3
OK
AT+CEREG?
+CEREG: 0,0
OK
AT+CGDCONT=1,"IP","olivia"
OK
ATD*99#
CONNECT 150000000
OK to start PPP....
Does your cellular provider support LTE CAT1 or NB1 on the frequency bands your modem supports. Those are newer protocols and not fully deployed everywhere.
Regardless, the system shouldnât be crashing.
The VS crash is probably a separate issue. There is a problem with the debuggerâs stack walking when debugging call stacks that include a traversal into native code. This is what is causing VS to crash. It happens more often when you have a breakpoint in a function that is downstream of a callback from native code, but I have also seen it happen in stack overflowâs and other cases. I have been trying to narrow it down, but am having limited success.
So, if I am understanding your description correctly, the VS crashes are likely due to something other than the PPP issues. WriteLine-debugging with TinyCLR Config is a potential alternative to breakpoints downstream of callbacks. And yes, I understand how painful that is, but if the goal is to solve the PPP issue, it may be your best bet.
The SIM provider (Olivia wireless) does not support either (because NB1/CAT1 dont support roaming) but the modem has a 2G fallback, im not sure if i need to disable them or explicitly just enable GPRS. Idiots from my telecom provider can not provide me with a SIM so i ended up just ordering from Olivia wireless.
My last bet is to somehow get them to sell me a NB IoT sim card, which is harder than you might think it is.
But i dont think any of this is relevant because i can connect with application
AT+CGDCONT=1,âIPâ,âoliviaâ
try âIPv4â instead of âIPâ
Any chance you have a logic analyzer? You could connect to the TX and RX and monitor the actual comms between SitCor and modem and compare it to your software on the computer.
Is connection to PC with USB or UART serial port? Could there be a difference between how the modem responds with a USB connection vs UART? Is it possible to make the connections to through a USB to UART converter with only TX and RX with no handshaking?
here is what we used to test PPP
We donât need
SendAT(serial, "AT+CGDCONT=1,\"IP\",\"h2g2\"");
because we already set that command and needs to do just once.
using System.Net;
using System.Text;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Uart;
using GHIElectronics.TinyCLR.Pins;
namespace Ethernet_App
{
class Program
{
const int LED1 = 1 * 16 + 0;
const int LDR1 = 1 * 16 + 7;
const string PPP_API_NAME = "GHIElectronics.TinyCLR.NativeApis.Ppp.NetworkController";
const string UART_API_NAME = "GHIElectronics.TinyCLR.NativeApis.STM32H7.UartController\\7";
static GpioPin led1;
static GpioPin ldr1;
static void Main()
{
var controller = GpioController.GetDefault();
led1 = controller.OpenPin(LED1);
ldr1 = controller.OpenPin(LDR1);
led1.SetDriveMode(GpioPinDriveMode.Output);
ldr1.SetDriveMode(GpioPinDriveMode.InputPullUp);
int cnt = 0;
while (ldr1.Read() == GpioPinValue.High)
{
led1.Write(led1.Read() == GpioPinValue.Low ? GpioPinValue.High : GpioPinValue.Low);
if (cnt % 10 == 0)
{
System.Diagnostics.Debug.WriteLine("Waiting for pressing LDR1:" + (cnt / 10) + " seconds.");
}
Thread.Sleep(51);
cnt++;
}
InitSimCard();
var networkController = NetworkController.FromName(PPP_API_NAME);
PppNetworkInterfaceSettings networkInterfaceSetting = new PppNetworkInterfaceSettings()
{
AuthenticationType = PppAuthenticationType.Pap,
Username = "",
Password = "",
};
UartNetworkCommunicationInterfaceSettings networkCommunicationInterfaceSettings = new UartNetworkCommunicationInterfaceSettings()
{
ApiName = UART_API_NAME,
BaudRate = 115200,
DataBits = 8,
Parity = UartParity.None,
StopBits = UartStopBitCount.One,
Handshaking = UartHandshake.None,
};
networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 1 });
networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[] { 0, 0, 0, 0 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };
networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 };
networkInterfaceSetting.DhcpEnable = true;
networkInterfaceSetting.DynamicDnsEnable = true;
networkInterfaceSetting.MulticastDnsEnable = true;
networkInterfaceSetting.TlsEntropy = new byte[] { 0, 1, 2, 3 };
networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings);
networkController.SetInterfaceSettings(networkInterfaceSetting);
networkController.SetAsDefaultController();
networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;
networkController.Enable();
while (linkReady == false)
{
led1.Write(led1.Read() == GpioPinValue.Low ? GpioPinValue.High : GpioPinValue.Low);
if (cnt % 10 == 0)
System.Diagnostics.Debug.WriteLine("Wait for connecting.... " + cnt);
Thread.Sleep(125);
cnt++;
}
System.Diagnostics.Debug.WriteLine("Network is ready to use.");
Thread.Sleep(-1);
}
static bool SendAT(UartController port, string command)
{
return SendAT(port, command, true);
}
static bool SendAT(UartController port, string command, bool addcr)
{
if (addcr)
command += "\r";
var sendBuffer = Encoding.UTF8.GetBytes(command);
var readBuffer = new byte[256];
var read = 0;
port.Write(sendBuffer, 0, sendBuffer.Length);
int timeout = 10;
while (timeout-- > 0)
{
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)
{
System.Diagnostics.Debug.WriteLine(" " + response);
break;
}
else
{
System.Diagnostics.Debug.WriteLine(" " + response);
}
Thread.Sleep(1000);
}
return timeout > 0;
}
static void InitSimCard()
{
var controller = GpioController.GetDefault();
const int POWERKEY_PIN = SC20260.GpioPin.PI8;
const int CTS_PIN = SC20260.GpioPin.PG6;
const int RTS_PIN = SC20260.GpioPin.PG12;
var powerkeyPin = controller.OpenPin(POWERKEY_PIN);
var ctsPin = controller.OpenPin(CTS_PIN);
var rtsPin = controller.OpenPin(RTS_PIN);
powerkeyPin.SetDriveMode(GpioPinDriveMode.Output);
ctsPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
rtsPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
powerkeyPin.Write(GpioPinValue.High);
Thread.Sleep(1200);
powerkeyPin.Write(GpioPinValue.Low);
Thread.Sleep(3000);
var serial = GHIElectronics.TinyCLR.Devices.Uart.UartController.FromName(SC20260.UartPort.Uart8);
var serialSetting = new UartSetting()
{
BaudRate = 115200,
DataBits = 8,
};
serial.SetActiveSettings(serialSetting);
serial.Enable();
System.Diagnostics.Debug.WriteLine("Try to comunicate to modem");
while (SendAT(serial, "AT") == false)
{
}
while (SendAT(serial, "ATD*99#") == false) ;
var count = 1;
while (count-- > 0)
{
Thread.Sleep(1000);
System.Diagnostics.Debug.WriteLine("Wait for connection setup " + count);
}
System.Diagnostics.Debug.WriteLine("OK to start PPP....");
}
static bool phyReady = false;
static bool linkReady = false;
private static void NetworkController_NetworkLinkConnectedChanged(NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
{
phyReady = e.Connected;
System.Diagnostics.Debug.WriteLine("Phy staus " + phyReady);
}
private static void NetworkController_NetworkAddressChanged(NetworkController sender, NetworkAddressChangedEventArgs e)
{
var ipProperties = sender.GetIPProperties();
var address = ipProperties.Address.GetAddressBytes();
var subnet = ipProperties.SubnetMask.GetAddressBytes();
var gw = ipProperties.GatewayAddress.GetAddressBytes();
var interfaceProperties = sender.GetInterfaceProperties();
System.Diagnostics.Debug.WriteLine("Mac: " + interfaceProperties.MacAddress[0].ToString("x") + ":" + interfaceProperties.MacAddress[1].ToString("x") + ":" + interfaceProperties.MacAddress[2].ToString("x") + ":" + interfaceProperties.MacAddress[3].ToString("x") + ":" + interfaceProperties.MacAddress[4].ToString("x") + ":" + interfaceProperties.MacAddress[5].ToString("x"));
System.Diagnostics.Debug.WriteLine("ip address :" + address[0] + "." + address[1] + "." + address[2] + "." + address[3]);
System.Diagnostics.Debug.WriteLine("subnetmask :" + subnet[0] + "." + subnet[1] + "." + subnet[2] + "." + subnet[3]);
System.Diagnostics.Debug.WriteLine("gate way :" + gw[0] + "." + gw[1] + "." + gw[2] + "." + gw[3]);
var dnsCount = ipProperties.DnsAddresses.Length;
for (int i = 0; i < dnsCount; i++)
{
var dns = ipProperties.DnsAddresses[i].GetAddressBytes();
System.Diagnostics.Debug.WriteLine("dns[" + i + "] :" + dns[0] + "." + dns[1] + "." + dns[2] + "." + dns[3]);
}
if (address[0] != 0 && address[1] != 0 && address[2] != 0 && address[3] != 0)
linkReady = true;
}
}
}
This code is now working on SC20100 Dev and SC20260 Dev board, but not on mine.
I donât know whatâs wrong.
Perhaps share your schematics so we can have a look with you?
Ok, found the culprit, it was the diode on the USB
Too big voltage dropâŚ
Hi Darko. What are the first 5 digits of the SIM number? You might use the wrong APN name.