← index #6564Issue #4708
Related · high · value 2.228
QUERY · ISSUE

GSM PPP is not Attaching to Micropython network.PPP

openby vijenderpandaopened 2020-10-22updated 2024-09-13
port-esp32

Kindly check ,
i followed to your last answer that we need to pass the authmode while connecting,
i have don that too , but still no luck

i am trying on ESP32 and SIM900A

class InitSimData():
def init(self):
self.gsm = machine.UART(1,tx=2, rx=4, timeout=1000, baudrate=9600)
time.sleep(interval)
self.check_sim()

    time.sleep(interval)
    self.register_sim()

    # time.sleep(interval)
    # self.getOPR()

    time.sleep(interval)
    self.attachGPRS()

    time.sleep(interval)
    self.rquestIPwithAPN()

    time.sleep(interval)
    self.getCGDCONT()

    # time.sleep(interval)
    # self.qosProfile()

    # time.sleep(interval)
    # self.qosProfilenext()


    time.sleep(interval)
    self.checkIP()

    time.sleep(interval)
    self.PDPcontext()


    time.sleep(interval)
    self.attachGSMtoPPP()


    

    
    
    

    
    

    


def check_sim(self):
    while True:
        self.gsm.write("AT\r\n")
        status = self.read_status()
        if status == "OK":
            print("Sim Initialized with status with status",status)
            return True
        else:
            pass
def register_sim(self):
    while True:
        self.gsm.write("AT+CREG?\r\n")
        status = self.read_status()
        if status == "+CREG: 0,1":
            print("Sim Registered with status with status",status)
            return True
        else:
            pass
def getOPR(self):
    while True:
        self.gsm.write("AT+COPS?\r\n")
        status = self.read_first()
        if status.startswith('+COPS'):
            print("Sim Operator Name is",status)
            return True
        else:
            pass

def attachGPRS(self):
    while True:
        self.gsm.write("AT+CGATT?\r\n")
        status = self.read_first()
        print("GPRS Status")
        if status == "+CGATT: 1":
            print("GPRS Attached with status with status", status)
            return True
        else:
            pass
def rquestIPwithAPN(self):
    self.gsm.write('AT+CGDCONT=1,"IP","portalnmms",\r\n')
    status = self.read_status()
    print("Checking status for CDGCONT response--",status)
    if status == 'OK':
        print("Sim Connected with APN and IP Address is ", status)
        return status
    else:
        self.rquestIPwithAPN()

def getCGDCONT(self):
    self.gsm.write('AT+CGDCONT=?\r\n')
    status = self.read_first()
    print("IP Details--",status)
    if status.startswith('+CGDCONT'):
        print("Sim Connected with IP---- ", status)
        return status
    else:
        time.sleep(1)
        self.getCGDCONT()

def getCGDCONTsec(self):
    self.gsm.write('AT+CGDCONT=?\r\n')
    status = self.read_status()
    print("IP Sec st Details--",status)
    if not status == '':
        print("Sim sec st Connected with IP---- ", status)
        return status
    else:
        time.sleep(1)
        self.getCGDCONT()

def qosProfile(self):
    """Define a QoS profile for PDP context 1, with
    Traffic Class 3 (background), maximum bit rate
    64 kb/s both for UL and for DL, no Delivery Order
    requirements, a maximum SDU size of 320
    octets, an SDU error ratio of 10-4
    , a residual bit
    error ratio of 10-5
    , delivery of erroneous SDUs
    allowed and Traffic Handling Priority 3."""

    self.gsm.write('AT+CGEQREQ=1,3,64,64,,,0,320,"1E4","1E5",1,,3\r\n')
    status = self.read_first()
    print("Qos Profile",status)
    if not status== '':
        print("Sim QOS Status---- ", status)
        return status
    else:
        time.sleep(1)
        self.qosProfile()

def PDPcontext(self):
    """PDP context 1 activation (alternatively with
        AT+CGDATA="PPP", 1 or ATD*99***1#)."""

    self.gsm.write('AT+CGDATA="PPP",1\r\n')
    status = self.read_first()
    print("CGDDATA PP ATTACHED ----", status)
    if status.startswith('CONNECT'):
        print("CGDDATA context 1 activation---- ", status)
        return status
    else:
        time.sleep(1)
        self.PDPcontext()

def checkIP(self):
    """Show address of PDP context 1. If PPP is used
        this command shall be sent from another AT
        command interface."""

    self.gsm.write('AT+CGPADDR=1\r\n')
    status = self.read_first()
    print("checkip method --",status)
    if status.startswith('+CGPADDR'):
        print("PDP context 1 activation---- ", status)
        return status
    else:
        time.sleep(1)
        self.checkIP()



def attachGSMtoPPP(self):
    import network
    GPRS=network.PPP(self.gsm)
    GPRS.active(True)
    GPRS.connect(authmode=GPRS.AUTH_PAP, username="", password="")
    if GPRS.isconnected():
        print(GPRS.ifconfig())
        return True
    else:
        time.sleep(0.5)
        self.attachGSMtoPPP()




        

        

def read_status(self):
    self.gsm.readline()
    status = self.gsm.readline()
    if status:
        status = status.decode().replace('\r\n','')
        return status
    else:
        print("Sim Module Not Connected or UART using by other device")
def read_first(self):
    status = self.gsm.readline()
    if status:
        status = status.decode().replace('\r\n','')
        return status
    else:
        print("Sim Module Not Connected or UART using by other device")

if name == "main":

print("Calling Main File")
time.sleep(10)
print("Starting the Sim Initailization Process")
sim = InitSimData()

-------------------------###########################------------ output logs are ----

gsm = machine.UART(1, rx=4, tx=2, baudrate=9600,timeout=1000)
gsm.write('AT\r\n')
4
print(gsm.readline())
b'\r\n'
print(gsm.readline())
b'OK\r\n'
print(gsm.read())
None
gsm.write('AT\r\n')
4
print(gsm.read())
b'\r\nOK\r\n'
gsm.write('AT+CGDCONT=1,"IP","portalnmms"\r\n')
32
print(gsm.read())
b'\r\nOK\r\n'
gsm.write('AT+CGDATA="PPP",1\r\n')
19
print(gsm.read())
b'\r\nERROR\r\n'

gsm.write('ATD99**1#\r\n')
13
print(gsm.read())
b'\r\n\r\nCONNECT\r\n\r\n'

GPRS=network.PPP(gsm)

GPRS.active(True)
True
GPRS.connect(authmode=GPRS.AUTH_PAP, username="", password="")
GPRS.isconnected()
False
GPRS.isconnected()
False
GPRS.isconnected()
False
GPRS.isconnected()

CANDIDATE · ISSUE

network.PPP troubles

openby nedoskivopened 2019-04-20updated 2024-12-21
port-esp32

Hello,

I finally managed to connect my GSM modem and start PPP link, but when decide to drop the link in order to control modem again prompt/system hangs (froze the promp) for unlimited time, but can be interrupted with control-C and the link is down after interruption.

That happen even without actially connect to internet:

>>> import machine
>>> import network
>>> gsm = machine.UART(1,tx=22, rx=21, timeout=1000,  baudrate=9600)
>>> ppp=network.PPP(gsm)
>>> ppp.active(True)
True
>>> ppp.active(False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt: 
>>> 
>>> 

Sometimes it reset module when interrupt with ctrl-c. I'm using:

MicroPython v1.10-290-g8402c26cf on 2019-04-20; ESP32 module with ESP32

P.S.

I can add that ppp.status() never return anything to me, connected, disconnected does not matter, it always prompt nothing.

P.S.1
ppp.isconnected() , start show True when it get IP address, but I do a little test, unplug my GSM modem, and let some time passes, so far it is 15 minutes and it still returns True

P.S.2
Noticed that DNS server is not set from ppp.ifconfig()

`>>> ppp.ifconfig()
('10.164.62.94', '192.168.254.254', '255.255.255.255', '0.0.0.0')

ppp.ifconfig("8.8.8.8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object 'str' isn't a tuple or list
ppp.ifconfig(dns="8.8.8.8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function doesn't take keyword arguments`
Do not know how to set it UP since there is no documentation.

  • tested there is no internet on the board, without DNS

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied