Skip to content

Update Cellular Examples for Adafruit FONA (3G/GSM) #29

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

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions examples/requests_advanced_cellular.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# pylint: disable=unused-import
import time
import board
import busio
import digitalio
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.adafruit_fona_gsm import GSM
from adafruit_fona.fona_3g import FONA3G
import adafruit_fona.adafruit_fona_network as network
import adafruit_fona.adafruit_fona_socket as cellular_socket
import adafruit_requests as requests

Expand All @@ -14,26 +16,31 @@
print("GPRS secrets are kept in secrets.py, please add them there!")
raise

# Create a serial connection for the FONA connection using 4800 baud.
# These are the defaults you should use for the FONA Shield.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
uart = busio.UART(board.TX, board.RX, baudrate=4800)
rst = digitalio.DigitalInOut(board.D4)
# Create a serial connection for the FONA connection
uart = busio.UART(board.TX, board.RX)
rst = digitalio.DigitalInOut(board.D9)

# Initialize FONA module (this may take a few seconds)
fona = FONA(uart, rst)
# Use this for FONA800 and FONA808
# fona = FONA(uart, rst)

# initialize gsm
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
# Use this for FONA3G
fona = FONA3G(uart, rst)

while not gsm.is_attached:
# Initialize cellular data network
network = network.CELLULAR(
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
)

while not network.is_attached:
print("Attaching to network...")
time.sleep(0.5)
print("Attached!")

while not gsm.is_connected:
while not network.is_connected:
print("Connecting to network...")
gsm.connect()
time.sleep(5)
network.connect()
time.sleep(0.5)
print("Network Connected!")

# Initialize a requests object with a socket and cellular interface
requests.set_socket(cellular_socket, fona)
Expand Down
31 changes: 19 additions & 12 deletions examples/requests_simpletest_cellular.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# pylint: disable=unused-import
import time
import board
import busio
import digitalio
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.adafruit_fona_gsm import GSM
from adafruit_fona.fona_3g import FONA3G
import adafruit_fona.adafruit_fona_network as network
import adafruit_fona.adafruit_fona_socket as cellular_socket
import adafruit_requests as requests

Expand All @@ -14,26 +16,31 @@
print("GPRS secrets are kept in secrets.py, please add them there!")
raise

# Create a serial connection for the FONA connection using 4800 baud.
# These are the defaults you should use for the FONA Shield.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
uart = busio.UART(board.TX, board.RX, baudrate=4800)
# Create a serial connection for the FONA connection
uart = busio.UART(board.TX, board.RX)
rst = digitalio.DigitalInOut(board.D4)

# Initialize FONA module (this may take a few seconds)
# Use this for FONA800 and FONA808
fona = FONA(uart, rst)

# initialize gsm
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
# Use this for FONA3G
# fona = FONA3G(uart, rst)

while not gsm.is_attached:
# Initialize cellular data network
network = network.CELLULAR(
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
)

while not network.is_attached:
print("Attaching to network...")
time.sleep(0.5)
print("Attached!")

while not gsm.is_connected:
while not network.is_connected:
print("Connecting to network...")
gsm.connect()
time.sleep(5)
network.connect()
time.sleep(0.5)
print("Network Connected!")

# Initialize a requests object with a socket and cellular interface
requests.set_socket(cellular_socket, fona)
Expand Down