Skip to content

Commit 0e81942

Browse files
authored
Merge pull request #1054 from brentru/update-planters-mqtt
Updating Planter Guide Examples for MiniMQTT Breaking Update
2 parents 1b18cfc + 266a96c commit 0e81942

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

PyPortal_AWS_IOT_Planter/code.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from adafruit_esp32spi import adafruit_esp32spi
1616
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
1717
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
18-
from adafruit_minimqtt import MQTT
18+
import adafruit_minimqtt as MQTT
1919
from adafruit_aws_iot import MQTT_CLIENT
2020
from adafruit_seesaw.seesaw import Seesaw
2121
import aws_gfx_helper
@@ -82,6 +82,9 @@
8282
wifi.connect()
8383
print("Connected!")
8484

85+
# Initialize MQTT interface with the esp interface
86+
MQTT.set_socket(socket, esp)
87+
8588
# Soil Sensor Setup
8689
i2c_bus = busio.I2C(board.SCL, board.SDA)
8790
ss = Seesaw(i2c_bus, addr=0x36)
@@ -120,10 +123,8 @@ def message(client, topic, msg):
120123
print("Message from {}: {}".format(topic, msg))
121124

122125
# Set up a new MiniMQTT Client
123-
client = MQTT(socket,
124-
broker = secrets['broker'],
125-
client_id = secrets['client_id'],
126-
network_manager = wifi)
126+
client = MQTT.MQTT(broker = secrets['broker'],
127+
client_id = secrets['client_id'])
127128

128129
# Initialize AWS IoT MQTT API Client
129130
aws_iot = MQTT_CLIENT(client)

PyPortal_GCP_IOT_Planter/code.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1616
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1717
from adafruit_gc_iot_core import MQTT_API, Cloud_Core
18-
from adafruit_minimqtt import MQTT
18+
import adafruit_minimqtt as MQTT
1919
from adafruit_seesaw.seesaw import Seesaw
2020
import digitalio
2121

@@ -44,6 +44,9 @@
4444
wifi.connect()
4545
print("Connected!")
4646

47+
# Initialize MQTT interface with the esp interface
48+
MQTT.set_socket(socket, esp)
49+
4750
# Soil Sensor Setup
4851
i2c_bus = busio.I2C(board.SCL, board.SDA)
4952
ss = Seesaw(i2c_bus, addr=0x36)
@@ -138,12 +141,10 @@ def handle_pump(command):
138141
print("Your JWT is: ", jwt)
139142

140143
# Set up a new MiniMQTT Client
141-
client = MQTT(socket,
142-
broker=google_iot.broker,
143-
username=google_iot.username,
144-
password=jwt,
145-
client_id=google_iot.cid,
146-
network_manager=wifi)
144+
client = MQTT.MQTT(broker=google_iot.broker,
145+
username=google_iot.username,
146+
password=jwt,
147+
client_id=google_iot.cid)
147148

148149
# Initialize Google MQTT API Client
149150
google_mqtt = MQTT_API(client)
@@ -187,4 +188,5 @@ def handle_pump(command):
187188
except (ValueError, RuntimeError) as e:
188189
print("Failed to get data, retrying", e)
189190
wifi.reset()
191+
google_mqtt.reconnect()
190192
continue

pyportal_pet_planter/code.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from adafruit_bitmap_font import bitmap_font
1212
from adafruit_display_text.label import Label
1313
from adafruit_io.adafruit_io import IO_MQTT
14-
from adafruit_minimqtt import MQTT
14+
import adafruit_minimqtt as MQTT
1515
from adafruit_pyportal import PyPortal
1616
from adafruit_seesaw.seesaw import Seesaw
1717
from simpleio import map_range
@@ -181,14 +181,13 @@
181181
continue
182182
print("Connected to WiFi!")
183183

184-
# Initialize a new MiniMQTT Client object
185-
mqtt_client = MQTT(
186-
socket=socket,
187-
broker="io.adafruit.com",
188-
username=secrets["aio_username"],
189-
password=secrets["aio_key"],
190-
network_manager=wifi
191-
)
184+
# Initialize MQTT interface with the esp interface
185+
MQTT.set_socket(socket, esp)
186+
187+
# Initialize a new MQTT Client object
188+
mqtt_client = MQTT.MQTT(broker="https://io.adafruit.com",
189+
username=secrets["aio_user"],
190+
password=secrets["aio_key"])
192191

193192
# Adafruit IO Callback Methods
194193
# pylint: disable=unused-argument

0 commit comments

Comments
 (0)