Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example on how to automatically connect to the APN #38

Closed
sebi5361 opened this issue Mar 4, 2020 · 4 comments
Closed

Example on how to automatically connect to the APN #38

sebi5361 opened this issue Mar 4, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@sebi5361
Copy link

sebi5361 commented Mar 4, 2020

Could you provide an example on how to automatically connect to the APN when booting?
I implemented a loop but often it just won't connect forever.

@pulkin
Copy link
Owner

pulkin commented Mar 14, 2020

You may try something like:

import cellular
import time
timeout = time.ticks_ms() + 1e4
while time.ticks_ms() < timeout:
    try:
        cellular.gprs("apn", "user", "pass")
        break
    except CellularError:
        if time.ticks_ms() < timeout:
            time.sleep(1)
        else:
            raise

@pulkin
Copy link
Owner

pulkin commented May 4, 2020

I added a callback on_status_event(f) for your convenience. The function you input will be triggered each time the network status changed. You may invent something like

def f(status):
    if status == 1:
        cellular.on_status_event(None)
        cellular.gprs("internet", "", "")

cellular.on_status_event(f)

and it will hopefully work.

@pulkin
Copy link
Owner

pulkin commented May 9, 2020

MWE https://github.com/pulkin/micropython/blob/master/ports/gprs_a9/examples/example_42_event_driven_gprs.py

@pulkin
Copy link
Owner

pulkin commented Jun 21, 2020

Feel free to reopen.

@pulkin pulkin closed this as completed Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants