Can't subscript and publish message

I used a microbit with NodeMCU to do a IoTproject. The microbit can be connected to MQT broker but it can’t subscript and publish message. The wi-fi connecton is OK since I can send data to ThingSpeak. How can I fix it? Thanks!

Hi @cwip ,

It is great that you are interested in MQTT, welcome to the community!

Which MQTT broker are you connecting to? Is that a HiveMQ Cloud or something else?

Which topic are you subscribing to or publishing?

How do you prove that your device is actually connected? How do you prove that your device is rejected to subscribe or publish? For example, do you receive a response packet with some error reason code or does the broker close the connection to your device without a Disconnect?

Kind regards,
Dasha from HiveMQ Team

Thanks for your reply. I used the module “ESP8266_IoT” in micro:bit editor. The module has the function to check the MQTT broker is connected or not. And I write a if statement to check it. It shows that the device is connected to MQTT broker.
I used my Cluster with port(TLS) 8883. I have tried to use CLI in my computer and it works properly (The data can be published from my computer and the web client can subscribe the data. But it’s strange that when I connected my computer to the MQTT broker, the microbit failed to connect to the MQTT broker. After I disconnected my computer from the broker, the microbit can be connected to the broker properly.
The program I wrote will be checked the connection between broker and microbit before the message is sent. If it fails to connect, it will shows a error message. But No error message during the publishing process.

Hi @cwip ,

I would suggest first checking the broker logs for a hint. Logs are stored in the $HIVEMQ_HOME/log directory.

  • event.log contains client connect and disconnect events
  • hivemq.log contains broker events and other useful information

You can also log all MQTT messages, incoming and outgoing, to hivemq.log. To do that you need to install an open-source HiveMQ Extension MQTT Message Log.

To get more information you need to make the logging more verbose. You can edit the configuration file $HIVEMQ_HOME/conf/logback.xml and change the log level from INFO to DEBUG. Find the line:

<root level="${HIVEMQ_LOG_LEVEL:-INFO}">

and change it to:

`<root level="${HIVEMQ_LOG_LEVEL:-DEBUG}">`

Please refer to HiveMQ Logging documentation: Logging :: HiveMQ Documentation

I hope it helps.
Kind regards,
Dasha from HiveMQ Team.

I’m a bit confused

AFAIK - a microbit doesn’t have WiFi and can not run NodeMCU firmware

Are you sure you’ve described your hardware and software setup correctly?

That can be a sign that you are using the same clientID for you device and your computer. If a broker is connected to a client and another client tries to connect using the same clientID, then the broker will disconnect the 1st client and connect to the 2nd client