adafruit / Adafruit_CircuitPython_MiniMQTT

MQTT Client Library for CircuitPython
Other
79 stars 50 forks source link

mqtt_client.connect() throws error: function takes 1 positional arguments but 4 were given #202

Closed scarolan closed 9 months ago

scarolan commented 9 months ago

Here's the relevant snippet of code that causes the error

# Adafruit IO MQTT settings
aio_username = os.getenv("AIO_USERNAME")
aio_key = os.getenv("AIO_KEY")
mqtt_broker = "io.adafruit.com"
mqtt_port = 1883  # Change to 8883 for SSL connection

# I2C setup for the SHT31D sensor
i2c = busio.I2C(board.PORTA_SCL, board.PORTA_SDA)
sht31 = adafruit_sht31d.SHT31D(i2c)

def connected(client):
    print("Connected to Adafruit IO!")

def disconnected(client):
    print("Disconnected from Adafruit IO!")

# Initialize MQTT client
mqtt_client = MQTT.MQTT(
    broker=mqtt_broker,
    port=mqtt_port,
    username=aio_username,
    password=aio_key,
    socket_pool=pool,
    #ssl_context=ssl_context,
)

mqtt_client.on_connect = connected
mqtt_client.on_disconnect = disconnected

# Connect the client to the MQTT broker
print("Connecting to Adafruit IO...")
mqtt_client.connect()

When it attempts to connect we get:

Connected!
Connecting to Adafruit IO...
Traceback (most recent call last):
  File "code.py", line 73, in <module>
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 535, in connect
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 655, in _connect
TypeError: function takes 1 positional arguments but 4 were **given**
scarolan commented 9 months ago

this was user error, my callback functions didn't match the ones in the examples.