GSM PPP is not Attaching to Micropython network.PPP
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()
ESP32: network.PPP on UART not working, interrupt-issue?
Hello,
I'm trying to use network.PPP with a GSM modem, but it does not work.
My code:
[.... initalization, APN setup etc.]
modem_uart.write('AT+CGDATA="PPP",1\r\n')
time.sleep(1)
print(modem_uart.readline()) => b'\r\n'
print(modem_uart.readline()) => b'CONNECT\r\n'
ppp = network.PPP(modem_uart)
ppp.active(True)
[waiting a few minutes, checking in the meantime
>>> ppp.ifconfig()
('0.0.0.0', '0.0.0.0', '255.255.255.255', '0.0.0.0')
>>> ppp.status()
>>> ppp.isconnected()
False
Then I checked if data is received from the modem, still in the rx buffer:
>>> modem_uart.any()
215
>>> modem_uart.read()
b'~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~~\xff}#\xc0!}!}!} }2}"}&} }*} } }#}$\xc0#}\'}"}(}"U\x83~\r\nNO CARRIER\r\n'
It seems the modem tries to establish connection, sending handshakes every few seconds, but network.PPP does not even pick up data from the UART. How is that supposed to work, I assumed it would be interrupt-driven in the background?
But I'm also not able to figure out how to get interrupts for received data on the UART manually, is it a feature missing on the ESP32, is that maybe causing the PPP issue?
>>> UART.irq
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'UART' has no attribute 'irq'
>>> modem_uart.irq
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'UART' object has no attribute 'irq'
I'm using esp32-idf4-20210202-v1.14.bin with a SIM800L GPRS modem.
According to https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/uart.html#uart-api-using-interrupts the ESP32 should support interrupts on the UART.
If interrupts are not supported and that is the issue, is there a way to manually feed the received data from the UART into ppp, from my main loop with select()?
Thanks
Sebastian