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

    Simple MQTT Tutorial

    Scheduled Pinned Locked Moved WiPy 2&3
    34 Posts 13 Posters 30.0k Views 16 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.
    • G Offline
      gertjanvanhethof Pybytes Beta @gertjanvanhethof
      last edited by

      I found the error. The port is wrong.
      It should be: 1883.
      Then connect is working.

      1 Reply Last reply Reply Quote 0
      • G Offline
        gas @vruizvil
        last edited by

        @vruizvil Hi
        I started a mosquitto on my laptop (vm debian) and it is working with the code as it is i updated it a little to make it configurable via config param file (wifi and mqtt)
        what error you are getting ?

        G 1 Reply Last reply Reply Quote 0
        • G Offline
          gertjanvanhethof Pybytes Beta @gas
          last edited by

          @gas It's working now. The used port was wrong. Thxs for your help.

          1 Reply Last reply Reply Quote 0
          • R Offline
            RSK
            last edited by

            MQTTClient is missing in the latest firmware, using the image release on 02/Dec/2016.

            Could someone confirm this.

            0_1481092220727_upload-95d4b814-1a49-47db-b229-f9092eb4c7e0

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              sakis @RSK
              last edited by

              @RSK umqtt is not part of Pycom's firmware or standard micropython. It is an external Python library, so to be able to use it you need to upload it to your device.

              The easiest way to do that is using Pymakr. Another way is using plain FTP (https://docs.pycom.io/pycom_esp32/pycom_esp32/general.html#local-file-system-and-ftp-access).

              Please read step 2 again and try to follow the instructions. If you have any problems let us know.

              1 Reply Last reply Reply Quote 0
              • R Offline
                RSK
                last edited by

                @sakis Thanks!

                I have downloaded umqtt.simple.py from https://github.com/micropython/micropython-lib and placed it in /flash/simple.py of the LoPy using FTP.

                And trying to connect from my LoPy application:
                0_1481109485470_upload-f0cd9d87-92ef-4d6a-8a64-b3240df41eb4

                With Hive settings:
                0_1481109531558_upload-397a9e59-4d48-495d-9538-b57cf969c284

                But connect fails with error "bytes index out of range":
                0_1481109598988_upload-974ac761-263f-4c25-8604-d9a97e83b289

                Please help to resolve.

                Thanks & Regards,
                Satish Kumar. R.

                1 Reply Last reply Reply Quote 0
                • R Offline
                  RSK
                  last edited by

                  Sorry the link i provided is incorrect, downloaded from the below link:
                  https://pypi.python.org/pypi/micropython-umqtt.simple

                  And the changes done to line number 57 "self.sock.settimeout(self.timeout)"

                  Thanks & Regards,
                  Satish Kumar. R.

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    sakis @RSK
                    last edited by

                    @RSK Have you tried using port 1883 instead of 8000?

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      RSK
                      last edited by

                      I am trying in Windows, by default http://www.hivemq.com/demos/websocket-client/
                      give port number 8000.

                      If i try to change in the browser to 1883 then socket connection fails in websocket client.

                      M 1 Reply Last reply Reply Quote 0
                      • M Offline
                        MrPy @RSK
                        last edited by

                        @RSK , Pretty sure you have a port issue. 1883 should work. For some reason Hive MQ isn't accepting requests on 1883 currently. I will search for another public test broker..

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          RSK
                          last edited by

                          @MrPy Thanks!

                          Adjusting the timeout period in simple.py is helping to make the setup work consistent.

                          0_1481187961439_upload-e25fcf75-b2f3-4f2b-ae79-aafb824f0594

                          This might help.

                          Thanks & Regards,
                          Satish Kumar. R.

                          1 Reply Last reply Reply Quote 0
                          • L Offline
                            lcgeldenhuys
                            last edited by

                            What version of the micropython-umqtt.simple library are you using? I'm trying the latest 1.3.2. It doesn't have the same bug on line 57 anymore, in fact it doesn't seem to use the same timeout mechanism.

                            I'm not able to connect successfully to the HiveMQ public broker:

                            Traceback (most recent call last):
                            File "main.py", line 10, in <module>
                            File "/flash/lib/umqtt.py", line 74, in connect
                            OSError: [Errno 113] EHOSTUNREACH

                            Using:

                            client = MQTTClient("MQTT_lcg_Client", "broker.hivemq.com", port=1883)
                            client.settimeout = settimeout
                            client.connect()

                            I can pub / sub using the MQTT.fx client on my laptop, and the WiPy is on the same network (I can ping and ftp to WiPy from laptop).

                            Any ideas?

                            1 Reply Last reply Reply Quote 0
                            • P Offline
                              pwest
                              last edited by

                              I'm also using the same apparently current 1.3.2 simple.py file, and having the exact issue described by lcgeldenhuys 3 months ago. Any suggestions on how to get past this?

                              -Phil

                              1 Reply Last reply Reply Quote 0
                              • B Offline
                                bucknall
                                last edited by

                                Hi @pwest,

                                It might be work checking out https://youtu.be/3NDPSbr5J14?list=PLS09TA19umCOavPeP_FoMHoCuCzjJUWQk, where I talk about MQTT and how to get set up with it.

                                Currently, the documentation on MQTT that we have online is out of date and I am re-writing it as we speak. I'll post back once it has been published!

                                Thanks,

                                Alex

                                Developer Evangelist - Pycom

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  achide
                                  last edited by

                                  Hi,

                                  I'm new with pycom. Maybe it's a stupid question, I would like to know how to import umqtt library.
                                  I've put it in lib folder of sys.path, but when I import this module, it told me no module named 'umqtt'?

                                  B 1 Reply Last reply Reply Quote 0
                                  • B Offline
                                    bucknall @achide
                                    last edited by

                                    @achide How are you uploading code to your device? Are you using the Pymakr Plugin?

                                    Developer Evangelist - Pycom

                                    A 1 Reply Last reply Reply Quote 0
                                    • A Offline
                                      achide @bucknall
                                      last edited by

                                      @bucknall yes, I use Pymakr.

                                      L 1 Reply Last reply Reply Quote 0
                                      • L Offline
                                        livius @achide
                                        last edited by livius

                                        @achide
                                        Pymakr IDE or Pymakr Atom Plugin?
                                        If First then do not use it.

                                        think about people first, then computers

                                        A 1 Reply Last reply Reply Quote 0
                                        • A Offline
                                          achide @livius
                                          last edited by

                                          @livius
                                          Hi, thanks for reply!
                                          It's Pymakr Atom Plugin I use.
                                          I've copy umqtt.py under lib file. Like this :
                                          0_1497965611638_upload-c188ec33-a802-43fc-a0ae-d3f359495e3e
                                          Then when I run the code, it shows like that :
                                          0_1497965697277_upload-c689486e-f0b6-43cf-87dc-2f5694e8644b
                                          What should I do ?

                                          L 1 Reply Last reply Reply Quote 0
                                          • L Offline
                                            livius @achide
                                            last edited by

                                            @achide
                                            I do not use pymakr
                                            but if i understand screen correctly you put it into
                                            \flash\lib\connections
                                            but you should into
                                            \flash\lib

                                            think about people first, then computers

                                            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
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom