11# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22# SPDX-License-Identifier: MIT
33
4+ import os
45import time
56import board
67import busio
78import digitalio
9+ import adafruit_connection_manager
810from adafruit_fona .adafruit_fona import FONA
911import adafruit_fona .adafruit_fona_network as network
10- import adafruit_fona .adafruit_fona_socket as socket
12+ import adafruit_fona .adafruit_fona_socket as pool
1113
1214import adafruit_minimqtt .adafruit_minimqtt as MQTT
1315
14- ### Cellular ###
16+ # Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys
17+ # with your GPRS credentials. Add your Adafruit IO username and key as well.
18+ # DO NOT share that file or commit it into Git or other source control.
1519
16- # Get cellular details and more from a secrets.py file
17- try :
18- from secrets import secrets
19- except ImportError :
20- print ("Cellular secrets are kept in secrets.py, please add them there!" )
21- raise
20+ aio_username = os .getenv ("aio_username" )
21+ aio_key = os .getenv ("aio_key" )
2222
2323# Create a serial connection for the FONA connection
2424uart = busio .UART (board .TX , board .RX )
@@ -71,7 +71,7 @@ def publish(client, userdata, topic, pid):
7171
7272# Initialize cellular data network
7373network = network .CELLULAR (
74- fona , (secrets [ "apn" ], secrets [ "apn_username" ], secrets [ "apn_password" ] )
74+ fona , (os . getenv ( "apn" ), os . getenv ( "apn_username" ), os . getenv ( "apn_password" ) )
7575)
7676
7777while not network .is_attached :
@@ -85,15 +85,16 @@ def publish(client, userdata, topic, pid):
8585 time .sleep (0.5 )
8686print ("Network Connected!" )
8787
88- # Initialize MQTT interface with the cellular interface
89- MQTT .set_socket (socket , fona )
88+ ssl_context = adafruit_connection_manager .create_fake_ssl_context (pool , fona )
9089
9190# Set up a MiniMQTT Client
9291client = MQTT .MQTT (
93- broker = secrets [ "broker" ] ,
94- username = secrets [ "user" ] ,
95- password = secrets [ "pass" ] ,
92+ broker = os . getenv ( "broker" ) ,
93+ username = os . getenv ( "username" ) ,
94+ password = os . getenv ( "password" ) ,
9695 is_ssl = False ,
96+ socket_pool = pool ,
97+ ssl_context = ssl_context ,
9798)
9899
99100# Connect callback handlers to client
0 commit comments