Anyone have a reliable MQTT interface using PyCom?



  • I'm trying to use pycom for MQTT to GCP. I can't really make a reliable connection. In this screenshot, I show a long running exchange of messages with GCP, but once it fails bringing down the network interface and restarting still results in a crash. The umqtt.py and google_iot_core.py code which is from the pycom github is in play. I have filed issues with the files there and I have not gotten any response. I'm asking here again in hopes someone can advise if this is simply the expected behaviour.

    I have added a poll/select timeout on the mqtt socket read in umqtt.py. That is shown with the !!! in the debug log.

    Screenshot from 2020-07-12 09-43-56.png


  • Pybytes Beta

    @ahmadelmasri said in Anyone have a reliable MQTT interface using PyCom?:

    Hi @netskink,

    Yes this is part of Pybytes, but you can use the MQTT without integrating with pybytes, I mean you can use the library instead of umqtt.py

    In your case what you should use is only:

    • mqtt_core.py
    • msg_handl.py

    the try-catch is related to libraries under the "lib" folder and in the frozen zone. so if you are using your own firmware, you can just add the above files and ignore the try-catch or remove them. if you are using pybytes firmware, you can import mqtt.py or _mqtt.py and do subscribe, publish directly.

    @ahmadelmasri I am trying this but it complains about missing arguments for MQTTClient, such as the mqtt_download_topic and pybytes_protocol. Do you have complete example code using the Pybytes MQTT library?



  • Hi @netskink,

    Yes this is part of Pybytes, but you can use the MQTT without integrating with pybytes, I mean you can use the library instead of umqtt.py

    In your case what you should use is only:

    • mqtt_core.py
    • msg_handl.py

    the try-catch is related to libraries under the "lib" folder and in the frozen zone. so if you are using your own firmware, you can just add the above files and ignore the try-catch or remove them. if you are using pybytes firmware, you can import mqtt.py or _mqtt.py and do subscribe, publish directly.



  • @ahmadelmasri Im using Google's IOT Core. Not pybytes.

    So only the umqtt.py file would apply to me. Just looking at the github, this code looks like it has tight coupling with pybytes and other unknown components.

    What is the deal with all these try exception blocks on imports? Is that so it can be run with regular python and micropython?

    try:
        from mqtt_core import MQTTCore as mqtt_core
    except:
        from _mqtt_core import MQTTCore as mqtt_core
    

    There is a subscribe method in _mqtt_core.py and a subscribe method in _mqtt.py How is this better?



  • Hello @netskink,

    I recommend checking the new MQTT protocol which is more reliable.

    https://github.com/pycom/pycom-micropython-sigfox/tree/Dev/esp32/frozen/Pybytes

    files to check (work with):

    • mqtt.py
    • mqtt_core.py
    • msg_handl.py

    Best Regards,
    Ahmad EL Masri


Log in to reply
 

Pycom on Twitter