|
15 | 15 | from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
|
16 | 16 | import adafruit_esp32spi.adafruit_esp32spi_socket as socket
|
17 | 17 | from adafruit_gc_iot_core import MQTT_API, Cloud_Core
|
18 |
| -from adafruit_minimqtt import MQTT |
| 18 | +import adafruit_minimqtt as MQTT |
19 | 19 | from adafruit_seesaw.seesaw import Seesaw
|
20 | 20 | import digitalio
|
21 | 21 |
|
|
44 | 44 | wifi.connect()
|
45 | 45 | print("Connected!")
|
46 | 46 |
|
| 47 | +# Initialize MQTT interface with the esp interface |
| 48 | +MQTT.set_socket(socket, esp) |
| 49 | + |
47 | 50 | # Soil Sensor Setup
|
48 | 51 | i2c_bus = busio.I2C(board.SCL, board.SDA)
|
49 | 52 | ss = Seesaw(i2c_bus, addr=0x36)
|
@@ -138,12 +141,10 @@ def handle_pump(command):
|
138 | 141 | print("Your JWT is: ", jwt)
|
139 | 142 |
|
140 | 143 | # 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) |
147 | 148 |
|
148 | 149 | # Initialize Google MQTT API Client
|
149 | 150 | google_mqtt = MQTT_API(client)
|
@@ -187,4 +188,5 @@ def handle_pump(command):
|
187 | 188 | except (ValueError, RuntimeError) as e:
|
188 | 189 | print("Failed to get data, retrying", e)
|
189 | 190 | wifi.reset()
|
| 191 | + google_mqtt.reconnect() |
190 | 192 | continue
|
0 commit comments