pulkin / micropython

MicroPython implementation on Ai-Thinker GPRS module A9 (RDA8955)
https://micropython.org
MIT License
103 stars 30 forks source link

Hangs up without uart connection #64

Closed bokolob closed 3 years ago

bokolob commented 3 years ago

Hello again. My board hangs up after USB cable disconnecting. It is powered with a lipo battery and connected to computer through a cp2120 USB-UART converter (converter shares ground with the board, but powered by USB). I upload a simple GPS tracking script with ampy, and run "import tacker" in the minicom. It starts to print some stuff out, and then I disconnect the cable. After about 5 minutes (yes, it happens not immediately but after a while) module hangs up and only reset can help. However, the script will work for hours with UART connected.

It's reproducible in 100% of tries.

It's like

while True: gps.on() cellular.gprs(...) write_coords_to_socket() utime.sleep(60);

pulkin commented 3 years ago

It is not a firmware problem given the way you describe it. My best guess is that you actually connect 5V of your cp2120 to the board. Once disconnected it dies either because your battery does not provide enough power or you use some sort of power bank which goes to sleep if not enough power is drawn.

bokolob commented 3 years ago

No, it's definitely not the reason...
I've made an experiment just now - without running program it continues work. Their +5vs aren't connected and I have 1000 mAh LiPo, I want to believe that it has good quality :)

And eventually, it has got stuck just when I was writing this answer and being connected to USB!

Maybe the reason is some network problems? Maybe I should try without GPRS.

My socket code is here

def send_rtt_coordinates():
    s = socket.socket()
    try:
        s.connect((SETTINGS['rtt_server'], SETTINGS['rtt_port']))
        print(get_rtt_string())
        s.write(get_rtt_string())
    finally:
        s.close()

But I don't check if I'm connected to the network or not.

bokolob commented 3 years ago

The full code is here - https://github.com/bokolob/tracker/blob/master/tracker.py

bokolob commented 3 years ago

So, without sockets, it seems to work without any problems.

pulkin commented 3 years ago

And eventually, it has got stuck just when I was writing this answer and being connected to USB!

In this case you should probably investigate what coolwather reports. You might also have forgotten else before

set_gprs_state(False)
bokolob commented 3 years ago

Reports? Do you mean Tracer plugin or gdb? Or it is something else? How to make tracer work on Linux? It pretends to be connected, but display nothing :( And about gdb - where can I get elf file that is required?

bokolob commented 3 years ago

I've added some debug prints and it seems that problem is with sockets. And the strangest thing is that the board become unable to take calls (you get a message that the phone is out of service).

BTW: s.settimeout() doesn't help

bokolob commented 3 years ago

My investigation shows that if we don't get a response to connect call, then the board freezes. It's probably because of the lwip call internals.

I tried the next piece of code, but it still doesn't work.

def connect_with_timeout(s, server, port, timeout):
    s.setblocking(0);

    try:
        s.connect((server, port))
    except Exception as err:
        pass

    readable,writable,exceptionavailable = select.select([s],[s],[s],10)

    for s in writable:
        s.setblocking(1)
        return s

    raise Exception("Connect timeout")
pulkin commented 3 years ago

Ok, this I can investigate.

bokolob commented 3 years ago

But you know.. I think it's somehow connected with my battery scheme. Снимок экрана 2020-07-05 в 17 08 58

bokolob commented 3 years ago

Finally, I've investigated this issue. Establishing TCP connection via GPRS producing current spikes, that makes those effects. The root of the problem was the lack of decoupling capacitance.