micropython / micropython/micropython

With network.PPP device hangs after several hours of operation

Open
#16,340 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug port-rp2
Dominant language
C
Stars
22.1k
Forks
9k
Avg merge
6d 4h
Merged PRs (30d)
16

Description

Port, board and/or hardware

rp2

MicroPython version

MicroPython v1.25.0-preview.72.g2e796d6c3.dirty on 2024-11-30; Raspberry Pi Pico W with RP2040

Reproduction

import time
import network
from machine import UART, Pin

import constants

class Modem:

def __init__(self, log):
    self.log = log

    self.uart = UART(0, 115200, rxbuf=1000)

    self.power_pin = Pin(constants.MODEM_POWER_PIN, Pin.OUT)
    self.status_pin = Pin(constants.MODEM_STATUS_PIN, Pin.IN)

    self.ppp = None

def send_at_comm(self, command, timeout=5):
    self.log.info("AT:", command)

    compose = f"{command}\r\n".encode()

    try:
        self.uart.write(compose)
    except:
        self.log.info("Error occured while AT command writing to modem")

    time.sleep(0.1)
    return self.get_response(timeout)

def get_response(self, timeout=5):
    response = ""

    timer = time.time()
    while True:
        time.sleep(0.1)

        if time.time() - timer < timeout:
            while self.uart.any():
                try:
                    response += self.uart.read(self.uart.any()).decode("utf-8")
                except:
                    pass

            return response
        else:
            return "timeout"

def connect_PPP(self):
    self.reset()

    time.sleep(2)
    result = self.send_at_comm("ATZ")
    self.log.info(result)

    time.sleep(2)
    result = self.send_at_comm("AT")
    self.log.info(result)

    time.sleep(2)
    result = self.send_at_comm('AT+CGDCONT=1,"IP","super"')
    self.log.info(result)

    time.sleep(2)
    operator = self.operator()
    self.log.info(result)

    time.sleep(2)
    result = self.send_at_comm("ATDT*99#")
    self.log.info(result)

    time.sleep(2)
    self.ppp = network.PPP(self.uart)

    time.sleep(2)
    self.ppp.connect()

    while not self.ppp.isconnected():
        self.log.info("connecting PPP")
        time.sleep(2)

    self.log.info("PPP connected", self.ppp.ifconfig())

    return operator

def operator(self):
    command = "AT+COPS?"
    response = self.send_at_comm(command)
    self.log.info(response)

    operator = None
    access_technology = None

    response = self.preprocess_response(response)
    pos = response.find("+COPS: ")
    if pos:
        splitted = response[pos:].split(",")
        self.log.info(splitted)
        operator = splitted[2]

        if splitted[3] == "0":
            access_technology = "GSM"
        elif splitted[3] == "8":
            access_technology = "LTE CAT M1"
        elif splitted[3] == "9":
            access_technology = "LTE CAT NB1"

    return {"operator": operator, "access_technology": access_technology}

def power_toggle(self):
    self.power_pin.high()
    time.sleep(2)
    self.power_pin.low()

def is_on(self):
    value = self.status_pin.value()
    if value == 0:
        return True

    return False

def reset(self):
    self.log.info("reseting modem")
    if self.is_on():
        self.power_toggle()
        time.sleep(2)

    self.power_toggle()

def preprocess_response(self, data):
    return data.replace("\r\n", ",")
Expected behaviour

PPP works until disconnect

Observed behaviour

Device hangs after several hours of operation. Im using Sixfab PicoLTE (Pico W integrated with Quectel BG95-M3 modem).

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied network.PPP example on the RP2040 Pico W with the Sixfab PicoLTE and BG95-M3 modem, monitoring the UART and connection state until the hang occurs. No repository file or test is named; done would be identifying the failure in PPP operation and documenting a reproducible cause and regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.