Skip to content

Commit ce1a94d

Browse files
committed
PR comments
1 parent 67f971f commit ce1a94d

16 files changed

+43
-33
lines changed

examples/cellular/minimqtt_adafruitio_cellular.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
### Feeds ###
3434

3535
# Setup a feed named 'photocell' for publishing to a feed
36-
photocell_feed = aio_username + "/feeds/photocell"
36+
photocell_feed = f"{aio_username}/feeds/photocell"
3737

3838
# Setup a feed named 'onoff' for subscribing to changes
39-
onoff_feed = aio_username + "/feeds/onoff"
39+
onoff_feed = f"{aio_username}/feeds/onoff"
4040

4141
### Code ###
4242

examples/cellular/minimqtt_simpletest_cellular.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
apn_password = getenv("apn_password")
2222
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
2323
aio_key = getenv("ADAFRUIT_AIO_KEY")
24+
broker = getenv("broker", "io.adafruit.com")
2425

2526
# Create a serial connection for the FONA connection
2627
uart = busio.UART(board.TX, board.RX)
@@ -88,7 +89,7 @@ def publish(client, userdata, topic, pid):
8889

8990
# Set up a MiniMQTT Client
9091
client = MQTT.MQTT(
91-
broker="io.adafruit.com",
92+
broker=broker,
9293
username=aio_username,
9394
password=aio_key,
9495
is_ssl=False,

examples/cpython/minimqtt_adafruitio_cpython.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
### Feeds ###
2222

2323
# Setup a feed named 'photocell' for publishing to a feed
24-
photocell_feed = aio_username + "/feeds/photocell"
24+
photocell_feed = f"{aio_username}/feeds/photocell"
2525

2626
# Setup a feed named 'onoff' for subscribing to changes
27-
onoff_feed = aio_username + "/feeds/onoff"
27+
onoff_feed = f"{aio_username}/feeds/onoff"
2828

2929
### Code ###
3030

examples/cpython/minimqtt_simpletest_cpython.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import adafruit_minimqtt.adafruit_minimqtt as MQTT
99

1010
# Add your Adafruit IO username and key to your env.
11+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
1112
# example:
1213
# export ADAFRUIT_AIO_USERNAME=your-aio-username
1314
# export ADAFRUIT_AIO_KEY=your-aio-key
15+
# export broker=io.adafruit.com
1416

1517
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
1618
aio_key = getenv("ADAFRUIT_AIO_KEY")
19+
broker = getenv("broker", "io.adafruit.com")
1720

1821
### Topic Setup ###
1922

@@ -23,7 +26,7 @@
2326

2427
# Adafruit IO-style Topic
2528
# Use this topic if you'd like to connect to io.adafruit.com
26-
# mqtt_topic = aio_username + "/feeds/temperature"
29+
# mqtt_topic = f"{aio_username}/feeds/temperature"
2730

2831

2932
### Code ###
@@ -63,7 +66,7 @@ def message(client, topic, message):
6366

6467
# Set up a MiniMQTT Client
6568
mqtt_client = MQTT.MQTT(
66-
broker="io.adafruit.com",
69+
broker=broker,
6770
username=aio_username,
6871
password=aio_key,
6972
socket_pool=socket,

examples/esp32spi/minimqtt_adafruitio_esp32spi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
### Feeds ###
4848

4949
# Setup a feed named 'photocell' for publishing to a feed
50-
photocell_feed = aio_username + "/feeds/photocell"
50+
photocell_feed = f"{aio_username}/feeds/photocell"
5151

5252
# Setup a feed named 'onoff' for subscribing to changes
53-
onoff_feed = aio_username + "/feeds/onoff"
53+
onoff_feed = f"{aio_username}/feeds/onoff"
5454

5555
### Code ###
5656

examples/esp32spi/minimqtt_pub_sub_blocking_esp32spi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
### Adafruit IO Setup ###
4848

4949
# Setup a feed named `testfeed` for publishing.
50-
default_topic = aio_username + "/feeds/testfeed"
50+
default_topic = f"{aio_username}/feeds/testfeed"
5151

5252
### Code ###
5353

examples/esp32spi/minimqtt_pub_sub_blocking_topic_callbacks_esp32spi.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
import adafruit_minimqtt.adafruit_minimqtt as MQTT
1515

1616
# Get WiFi details and broker keys, ensure these are setup in settings.toml
17+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
1718
ssid = getenv("CIRCUITPY_WIFI_SSID")
1819
password = getenv("CIRCUITPY_WIFI_PASSWORD")
19-
broker = getenv("broker")
20-
broker_port = getenv("broker_port")
20+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
21+
aio_key = getenv("ADAFRUIT_AIO_KEY")
22+
broker = getenv("broker", "io.adafruit.com")
23+
broker_port = int(getenv("broker_port", "8883")) # Port 1883 insecure, 8883 secure
2124

2225
### WiFi ###
2326

@@ -75,7 +78,7 @@ def on_battery_msg(client, topic, message):
7578
# Method called when device/batteryLife has a new value
7679
print(f"Battery level: {message}v")
7780

78-
# client.remove_topic_callback(aio_username + "/feeds/device.batterylevel")
81+
# client.remove_topic_callback(f"{aio_username}/feeds/device.batterylevel")
7982

8083

8184
def on_message(client, topic, message):
@@ -95,6 +98,8 @@ def on_message(client, topic, message):
9598
client = MQTT.MQTT(
9699
broker=broker,
97100
port=broker_port,
101+
username=aio_username,
102+
password=aio_key,
98103
socket_pool=pool,
99104
ssl_context=ssl_context,
100105
)
@@ -105,14 +110,14 @@ def on_message(client, topic, message):
105110
client.on_subscribe = subscribe
106111
client.on_unsubscribe = unsubscribe
107112
client.on_message = on_message
108-
client.add_topic_callback(aio_username + "/feeds/device.batterylevel", on_battery_msg)
113+
client.add_topic_callback(f"{aio_username}/feeds/device.batterylevel", on_battery_msg)
109114

110115
# Connect the client to the MQTT broker.
111116
print("Connecting to MQTT broker...")
112117
client.connect()
113118

114119
# Subscribe to all notifications on the device group
115-
client.subscribe(aio_username + "/groups/device", 1)
120+
client.subscribe(f"{aio_username}/groups/device", 1)
116121

117122
# Start a blocking message loop...
118123
# NOTE: NO code below this loop will execute

examples/esp32spi/minimqtt_pub_sub_nonblocking_esp32spi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
### Adafruit IO Setup ###
4848

4949
# Setup a feed named `testfeed` for publishing.
50-
default_topic = aio_username + "/feeds/testfeed"
50+
default_topic = f"{aio_username}/feeds/testfeed"
5151

5252

5353
### Code ###

examples/esp32spi/minimqtt_pub_sub_pyportal_esp32spi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
1616
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
1717
aio_key = getenv("ADAFRUIT_AIO_KEY")
18+
broker = getenv("broker", "io.adafruit.com")
1819

1920
# ------------- MQTT Topic Setup ------------- #
2021
mqtt_topic = "test/topic"
@@ -53,7 +54,7 @@ def message(client, topic, message):
5354

5455
# Set up a MiniMQTT Client
5556
mqtt_client = MQTT.MQTT(
56-
broker="io.adafruit.com",
57+
broker=broker,
5758
username=aio_username,
5859
password=aio_key,
5960
is_ssl=False,

examples/esp32spi/minimqtt_simpletest_esp32spi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
password = getenv("CIRCUITPY_WIFI_PASSWORD")
1818
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
1919
aio_key = getenv("ADAFRUIT_AIO_KEY")
20+
broker = getenv("broker", "io.adafruit.com")
2021

2122
# If you are using a board with pre-defined ESP32 Pins:
2223
esp32_cs = DigitalInOut(board.ESP_CS)
@@ -38,7 +39,7 @@
3839
except RuntimeError as e:
3940
print("could not connect to AP, retrying: ", e)
4041
continue
41-
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
42+
print("Connected to", esp.ap_info.ssid, "\tRSSI:", esp.ap_info.rssi)
4243

4344
### Topic Setup ###
4445

@@ -48,7 +49,7 @@
4849

4950
# Adafruit IO-style Topic
5051
# Use this topic if you'd like to connect to io.adafruit.com
51-
# mqtt_topic = aio_username + '/feeds/temperature'
52+
# mqtt_topic = f"{aio_username}/feeds/temperature"
5253

5354
### Code ###
5455

@@ -91,7 +92,7 @@ def message(client, topic, message):
9192

9293
# Set up a MiniMQTT Client
9394
mqtt_client = MQTT.MQTT(
94-
broker="io.adafruit.com",
95+
broker=broker,
9596
username=aio_username,
9697
password=aio_key,
9798
socket_pool=pool,

0 commit comments

Comments
 (0)