SiPy, Micropython and Google IoT Core MQTT

  • Hi, new to pycom but do have experience with MQTT and Google IoT Core.

    Has anyone managed to connect a device running micropython to the Google MQTT IoT Core broker service?

    If so could they please help me with the initial connection code.

    My code:

    #example here:
    from umqtt import MQTTClient
    from network import WLAN
    import machine
    import time
    def sub_cb(topic, msg):
    wlan = WLAN(mode=WLAN.STA)
    wlan.connect("SSID", auth=(WLAN.WPA2, "WIFIPWD"), timeout=5000)
    while not wlan.isconnected():
    print("Connected to Wifi\n")
    client = MQTTClient("device_id", "", user="USERNAME", password="APIKEY", port=8883)
    while True:
        print("Sending ON")
        client.publish(topic="projects/mongoose-iota/topics/telemetry-topic", msg="ON")
        print("Sending OFF")
        client.publish(topic="projects/mongoose-iota/topics/telemetry-topic", msg="OFF")

    I keep getting this error:

    Traceback (most recent call last):
    File "", line 22, in <module>
    File "/flash/lib/", line 97, in connect
    MicroPython v1.8.6-849-86da809 on 2018-01-17; SiPy with ESP32

    Line 97 is this, mqtt taken from this source

    assert resp[0] == 0x20 and resp[1] == 0x02

    Any help would be very much appreciated.
    Thank you in advance!

  • @jonnyboy I've been trying to get our pycom device talking to google IoT Core as well. Did you have any luck making it work or finding a micro-python compatible JWT Library?

  • @seb
    JWT tokens use HMAC
    and this lib can be used for it

  • @jonnyboy said in SiPy, Micropython and Google IoT Core MQTT:

    It is my understanding that google's mqtt requires you to use JWT to authenticate, unfortunately the cryptography necessary to create JWT tokens is not something our modules can support with the current firmware. You would have to use an external server to generate the JWT tokens which when using MQTT are valid for 1h.

  • Hi, bumping this on.....anyone please.


Pycom on Twitter