Can someone pls. confirm, that MQTT is running w\ latest FW

  • Hi all!
    I'm testing some sensors, and just wanted to push the measurements to my local MQTT Broker. But I get allways an error in the MQTT lib.

     File "", line 51, in <module>
      File "/flash/lib/", line 84, in connect
    IndexError: bytes index out of range

    I did it a thousand times with WiPys 2.0 and LoPys, and it worked allway seemlessly.


  • Arghh. Got it. It was a typo in the config file of my broker. The broker was running on the wrong port.



  • @ledbelly2142
    You don't use client.connect(). Is this right? The connect() method is the one, that gives me the error.

  • Yes from this example

    Your should have something like:

    import socket
    import struct
    import machine
    import time
    import ubinascii
    import network
    from network import WLAN
    from network import LoRa
    from mqtt import MQTTClient
    wlan = network.WLAN(mode=network.WLAN.STA, antenna=WLAN.EXT_ANT)
    #wlan.antenna(WLAN.EXT_ANT) You may be using internal antenna
    wlan.connect('WiFiSSID', auth=(WLAN.WPA2, 'WiFiPassword'), timeout=5000)
    while not wlan.isconnected():
    print("Connected to Wifi\n")
    client = MQTTClient("nameofMQTTserver", "IPaddressOrURLforMQTTserver", port=1883, user="EnterUserNameForMQTTserver", password="EnterPasswordForMQTTserver")
    client.settimeout = settimeout
    # You may not be using port 1883, use 8883 if using SSL
    #then test with something like:
    client.publish("house001/sensor/sensorId_001/temp/c", "23.48")
    #the way this library is set up, it needs the topic, then the topic value to be written

    If you are not using MQTTlense, I highly recommend it for Chrome. Simple and easy to use for testing. More on MQTTlense HERE

    The QOS for this Library is set to 0 (best effort similar to TCP/IP), to avoid ping pong MQTT messaging, use QOS 2 (once and only once) on the subscriber for testing.

  • Pybytes Beta

  • The MQTT lib from Pycom (on github) is working for me. I did not get an index error.

Log in to reply

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.