Skip to content

Exception tricky to troubleshoot when defaulted to SSL but broker is not SSL #60

Closed
@rpavlik

Description

@rpavlik

I'm using a MatrixPortal successfully connected to wifi, on a network with a mosquitto mqtt server, no authentication or security on that. circuitpython 6.1.0, latest library bundle (I think - circup isn't working for me today, but I hand-selected the libraries I think I needed and copied them manually from the bundle), latest nina firmware on esp32, mqtt broker is specified by ip (v4) address in the secrets file.

Chopped down code:

import random
import time
from secrets import secrets

import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_minimqtt.adafruit_minimqtt as MQTT
import board
import busio
import neopixel
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
from adafruit_matrixportal.matrixportal import MatrixPortal

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(
    board.NEOPIXEL, 1, brightness=0.2
) 
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

print("Connecting to WiFi...")
wifi.connect()
print("Connected!")
# --- Display setup ---
matrixportal = MatrixPortal( debug=True, esp=esp, external_spi=spi)
# Create a new label with the color and text selected
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
    scrolling=True,
)

# Static 'Connecting' Text
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(2, (matrixportal.graphics.display.height // 2) - 1),
)

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

# Set up a MiniMQTT Client
mqtt_client = MQTT.MQTT(
    broker=secrets["broker"],
    log=True
)
PRESSURE_TOPIC = "office/sensor/pressure/state"

last_pressure = 0
def handle_message(client, topic, message):
    global last_pressure
    message = int(float(message))
    if last_pressure != message:
        scd.ambient_pressure = message
        last_pressure = message

def connected(client, userdata, flags, rc):
    # This function will be called when the client is connected
    # successfully to the broker.
    print("Connected to MQTT broker! Listening for topic changes on %s" % PRESSURE_TOPIC)
    
    matrixportal.set_text("Connected", 1)

    client.subscribe(PRESSURE_TOPIC)

mqtt_client.on_message = handle_message
mqtt_client.on_connect = connected

matrixportal.set_text("Connecting", 1)
mqtt_client.connect()

(Yes, I'm initially just trying to just read a pressure from another sensor in my network, since I'm porting some code from the Clue. Just trying to get my scd30 and pm25 sensor submitting to mqtt and thus influxdb and grafana, in addition to a local display :D )

I get this output:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

code.py output:
Connecting to WiFi...
Connected!
Init display
Init background
Init text area
Init text area
Creating text area with : Connecting
Traceback (most recent call last):
  File "code.py", line 97, in <module>
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 304, in connect
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 304, in connect
MMQTTException: ('Invalid broker address defined.', RuntimeError('Expected 01 but got 00',))

Line 97 is the mqtt connect line at the end of the cut down code.

Resembles #50 but not sure if it's the same. Hardware reset doesn't seem to help.

(Is this the right place for these kinds of "Seems like this should work, but I might be doing it wrong" questions, or would you prefer forums or discord?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions