Skip to content

Updating Planter Guide Examples for MiniMQTT Breaking Update #1054

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 4 commits into from
Mar 17, 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
11 changes: 6 additions & 5 deletions PyPortal_AWS_IOT_Planter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_minimqtt import MQTT
import adafruit_minimqtt as MQTT
from adafruit_aws_iot import MQTT_CLIENT
from adafruit_seesaw.seesaw import Seesaw
import aws_gfx_helper
Expand Down Expand Up @@ -82,6 +82,9 @@
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)

# Soil Sensor Setup
i2c_bus = busio.I2C(board.SCL, board.SDA)
ss = Seesaw(i2c_bus, addr=0x36)
Expand Down Expand Up @@ -120,10 +123,8 @@ def message(client, topic, msg):
print("Message from {}: {}".format(topic, msg))

# Set up a new MiniMQTT Client
client = MQTT(socket,
broker = secrets['broker'],
client_id = secrets['client_id'],
network_manager = wifi)
client = MQTT.MQTT(broker = secrets['broker'],
client_id = secrets['client_id'])

# Initialize AWS IoT MQTT API Client
aws_iot = MQTT_CLIENT(client)
Expand Down
16 changes: 9 additions & 7 deletions PyPortal_GCP_IOT_Planter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_gc_iot_core import MQTT_API, Cloud_Core
from adafruit_minimqtt import MQTT
import adafruit_minimqtt as MQTT
from adafruit_seesaw.seesaw import Seesaw
import digitalio

Expand Down Expand Up @@ -44,6 +44,9 @@
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)

# Soil Sensor Setup
i2c_bus = busio.I2C(board.SCL, board.SDA)
ss = Seesaw(i2c_bus, addr=0x36)
Expand Down Expand Up @@ -138,12 +141,10 @@ def handle_pump(command):
print("Your JWT is: ", jwt)

# Set up a new MiniMQTT Client
client = MQTT(socket,
broker=google_iot.broker,
username=google_iot.username,
password=jwt,
client_id=google_iot.cid,
network_manager=wifi)
client = MQTT.MQTT(broker=google_iot.broker,
username=google_iot.username,
password=jwt,
client_id=google_iot.cid)

# Initialize Google MQTT API Client
google_mqtt = MQTT_API(client)
Expand Down Expand Up @@ -187,4 +188,5 @@ def handle_pump(command):
except (ValueError, RuntimeError) as e:
print("Failed to get data, retrying", e)
wifi.reset()
google_mqtt.reconnect()
continue
17 changes: 8 additions & 9 deletions pyportal_pet_planter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.label import Label
from adafruit_io.adafruit_io import IO_MQTT
from adafruit_minimqtt import MQTT
import adafruit_minimqtt as MQTT
from adafruit_pyportal import PyPortal
from adafruit_seesaw.seesaw import Seesaw
from simpleio import map_range
Expand Down Expand Up @@ -181,14 +181,13 @@
continue
print("Connected to WiFi!")

# Initialize a new MiniMQTT Client object
mqtt_client = MQTT(
socket=socket,
broker="io.adafruit.com",
username=secrets["aio_username"],
password=secrets["aio_key"],
network_manager=wifi
)
# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(broker="https://io.adafruit.com",
username=secrets["aio_user"],
password=secrets["aio_key"])

# Adafruit IO Callback Methods
# pylint: disable=unused-argument
Expand Down