0

I managed to connect an ESP01 using Micropython 1.9.2 to a mosquitto broker running in my computer. I also managed to simulate a device and connect a mosquitto client from my computer to the Watson Broker. But when I try to connect the ESP directly to Watson I receive a "connection refused" message

MQTTException: 5
# Full stream answered by Watson is:  b' \x02\x00\x05'

My configuration parameters are:

  • WATSON_CLIENT_ID = "d:[ORG]:ESP8266:fv_esp01s_02"
  • WATSON_BROKER_IP = "[ORG].messaging.internetofthings.ibmcloud.com"
  • WATSON_USER = "use-token-auth"
  • WATSON_PWD = b"[TOKEN]"

As I said, in Watson, I had created the defined "TLS Optional" and configured the device. I tested the connection with a mosquitto client and it worked.

Any help is more than welcomed!, Best!

Francisco
  • 151
  • 1
  • 7

1 Answers1

3

I found the answer looking at the code revisions in umqtt.simple (the mqtt library for esp8266)

The answer is that in the umqtt examples there was one that uses hexlify( client_id) and I followed as standard:

client = MQTTClient(client_id=hexlify(MQTT_CLIENT_ID), server=MQTT_BROKER_IP, user=MQTT_USER, password=MQTT_PWD)

Apparently mosquitto broker understand this but not the Watson IBM broker. Changing to:

client = MQTTClient(client_id=MQTT_CLIENT_ID, server=MQTT_BROKER_IP, user=MQTT_USER, password=MQTT_PWD)

solves the issue. For watson the variables format is as follows:

  • CLIENT_ID = bytes
  • MQTT_BROKER_IP (or url) = string
  • MQTT_USER = string
  • MQTT_PWD = bytes

Pay attention to the topic/message formats as well.

Best!

Francisco
  • 151
  • 1
  • 7
  • "in the umqtt examples the suggested way" - Can you point where there's this "suggested way" in umqtt examples? umqtt examples are examples, you need to adjust them to work for you. There's no "suggested way" for client ID. – pfalcon Sep 09 '17 at 19:59
  • Hi. Somehow I arrived to this example and followed as a reference. https://github.com/micropython/micropython-lib/blob/master/umqtt.simple/example_sub_led.py Then I considered the hexlify() as a practice. – Francisco Sep 10 '17 at 15:24
  • Updated the answer. Thanks pfalcon. – Francisco Sep 10 '17 at 15:30