Skip to content

Commit 6cd9b60

Browse files
author
brentru
committed
add gcp
1 parent f8b20a8 commit 6cd9b60

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

0 commit comments

Comments
 (0)