|
| 1 | +# pylint: disable=unused-import |
1 | 2 | import time
|
2 | 3 | import board
|
3 | 4 | import busio
|
4 | 5 | import digitalio
|
5 | 6 | from adafruit_fona.adafruit_fona import FONA
|
6 |
| -from adafruit_fona.adafruit_fona_gsm import GSM |
| 7 | +from adafruit_fona.fona_3g import FONA3G |
| 8 | +import adafruit_fona.adafruit_fona_network as network |
7 | 9 | import adafruit_fona.adafruit_fona_socket as cellular_socket
|
8 | 10 | import adafruit_requests as requests
|
9 | 11 |
|
|
14 | 16 | print("GPRS secrets are kept in secrets.py, please add them there!")
|
15 | 17 | raise
|
16 | 18 |
|
17 |
| -# Create a serial connection for the FONA connection using 4800 baud. |
18 |
| -# These are the defaults you should use for the FONA Shield. |
19 |
| -# For other boards set RX = GPS module TX, and TX = GPS module RX pins. |
20 |
| -uart = busio.UART(board.TX, board.RX, baudrate=4800) |
21 |
| -rst = digitalio.DigitalInOut(board.D4) |
| 19 | +# Create a serial connection for the FONA connection |
| 20 | +uart = busio.UART(board.TX, board.RX) |
| 21 | +rst = digitalio.DigitalInOut(board.D9) |
22 | 22 |
|
23 |
| -# Initialize FONA module (this may take a few seconds) |
24 |
| -fona = FONA(uart, rst) |
| 23 | +# Use this for FONA800 and FONA808 |
| 24 | +# fona = FONA(uart, rst) |
25 | 25 |
|
26 |
| -# initialize gsm |
27 |
| -gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])) |
| 26 | +# Use this for FONA3G |
| 27 | +fona = FONA3G(uart, rst) |
28 | 28 |
|
29 |
| -while not gsm.is_attached: |
| 29 | +# Initialize cellular data network |
| 30 | +network = network.CELLULAR( |
| 31 | + fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]) |
| 32 | +) |
| 33 | + |
| 34 | +while not network.is_attached: |
30 | 35 | print("Attaching to network...")
|
31 | 36 | time.sleep(0.5)
|
| 37 | +print("Attached!") |
32 | 38 |
|
33 |
| -while not gsm.is_connected: |
| 39 | +while not network.is_connected: |
34 | 40 | print("Connecting to network...")
|
35 |
| - gsm.connect() |
36 |
| - time.sleep(5) |
| 41 | + network.connect() |
| 42 | + time.sleep(0.5) |
| 43 | +print("Network Connected!") |
37 | 44 |
|
38 | 45 | # Initialize a requests object with a socket and cellular interface
|
39 | 46 | requests.set_socket(cellular_socket, fona)
|
|
0 commit comments