Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

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

    Scheduled Pinned Locked Moved MicroPython
    mqtt
    6 Posts 3 Posters 1.8k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      Thosch42
      last edited by

      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 "main.py", line 51, in <module>
        File "/flash/lib/mqtt.py", 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.

      Cheers,
      Thomas

      1 Reply Last reply Reply Quote 0
      • ledbelly2142L Offline
        ledbelly2142
        last edited by

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

        Friends don't let friends run with scissors

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          BetterAuto Pybytes Beta @ledbelly2142
          last edited by

          @ledbelly2142 said in Can someone pls. confirm, that MQTT is running w\ latest FW:

          The MQTT lib from Pycom (on github) is working for me.

          This one?
          https://github.com/pycom/pycom-libraries/blob/master/examples/mqtt/mqtt.py

          1 Reply Last reply Reply Quote 0
          • ledbelly2142L Offline
            ledbelly2142
            last edited by ledbelly2142

            Yes from this example
            https://github.com/pycom/pycom-libraries/tree/master/examples/mqtt

            Your main.py 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():
                    machine.idle()
            
            print(wlan.ifconfig())
            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.

            Friends don't let friends run with scissors

            T 1 Reply Last reply Reply Quote 2
            • T Offline
              Thosch42 @ledbelly2142
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • T Offline
                Thosch42
                last edited by

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

                Thanks.

                Thomas

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom