Skip to content

Updated Cellular Examples #34

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 1 commit into from
Jun 1, 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
20 changes: 11 additions & 9 deletions examples/minimqtt_adafruitio_cellular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import busio
import digitalio
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.adafruit_fona_gsm import GSM
import adafruit_fona.adafruit_fona_network as network
import adafruit_fona.adafruit_fona_socket as socket

import adafruit_minimqtt as MQTT
Expand Down Expand Up @@ -54,19 +54,21 @@ def message(client, topic, message):
print("New message on topic {0}: {1}".format(topic, message))


# Initialize GSM modem
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
# Initialize cellular data network
network = network.CELLULAR(
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
)

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

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

# Initialize MQTT interface with the cellular interface
MQTT.set_socket(socket, fona)
Expand Down
20 changes: 11 additions & 9 deletions examples/minimqtt_simpletest_cellular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import busio
import digitalio
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.adafruit_fona_gsm import GSM
import adafruit_fona.adafruit_fona_network as network
import adafruit_fona.adafruit_fona_socket as socket

import adafruit_minimqtt as MQTT
Expand Down Expand Up @@ -65,19 +65,21 @@ def publish(client, userdata, topic, pid):
print("Published to {0} with PID {1}".format(topic, pid))


# Initialize GSM modem
gsm = GSM(fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"]))
# Initialize cellular data network
network = network.CELLULAR(
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
)

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

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

# Initialize MQTT interface with the cellular interface
MQTT.set_socket(socket, fona)
Expand Down