pulkin / micropython

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

when call icellular.gprs("v-internet", "", "") then gprs reconnect ? #83

Closed tinamore closed 3 years ago

tinamore commented 3 years ago

Thank you for your wonderful Project.

I have a question that is:

Example When I run

import utime
import cellular
import socket

cellular.gprs ("v-internet", "", "")

while 1:
    utime.sleep_ms(500)
    print("IP", socket.get_local_ip())
    host = "httpstat.us"
    port = 80
    s = socket.socket()
    s.connect((host, port))
    message = "GET /200 HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n"
    s.write(message.format(host))
    print(s.read(256))
    s.close()

will the cellular.gprs function take care of the reconect gprs automation? I don't need to check status gprs (then if not gprs then reconnect gprs) every time open socket?

pulkin commented 3 years ago

I doubt it reconnects. Your best guess is to track status events via on_status_event.

tinamore commented 3 years ago

Thank for your support. Do you have an example full code of maintaining a persistent connection. Obviously this is very important. Can I do this?

import utime
import cellular
import socket

cellular.gprs("v-internet", "", "")

while 1:
    utime.sleep_ms(500)

    if not cellular.gprs():
        cellular.gprs("v-internet", "", "")

    print("IP", socket.get_local_ip())
    host = "httpstat.us"
    port = 80
    s = socket.socket()
    s.connect((host, port))
    message = "GET /200 HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n"
    s.write(message.format(host))
    print(s.read(256))
    s.close()
pulkin commented 3 years ago

The most reliable way is to reboot the module before each payload.

tinamore commented 3 years ago

Thank you very much.