New websocket software example

Alastair Gilmore on 17 Sep 2021
Latest activity Reply by Alastair Gilmore on 17 Sep 2021

Hi, I've been using ThingSpeak now for a number of years capturing temperature data from a Pi zero and Python. I currently use the Unsecured TCP option, but the recent email about moving to mqtt3 server suggests websockets. I've looked at the example and understand username, password and channel ID, but not what the Client ID is. Can someone tell me what this is please.

Many thanks Alastair

Alain Kuchta
Alain Kuchta on 17 Sep 2021

MQTT Brokers need to keep track of each connected device in order to properly route messages to and from it. Brokers use ClientId to uniquely identify an MQTT connection for this purpose.

For example, if you own 3 Pi Zeros, each of them must use a unique ClientId. Otherwise, the Pi Zeros will be like three people trying to share one chair. Each time someone sits down, the other two are forced to stand. Similarly, the Pi Zeros will continually disconnect and reconnect.

When you add a device to your MQTT Devices, ThingSpeak generates a unique ClientId for it. You'll also get a unique username and password for that device.

It may be confusing that both Username and ClientId are required to connect; this is sort of just a quirk of the MQTT protocol.

Further Reading

MQTT Basics - Create a ThingSpeak MQTT Device

MQTT 3.1.1 Protocol: Client Identifier

Alastair Gilmore
Alastair Gilmore on 17 Sep 2021

Many thanks Alain, got it working. Alastair

Tags

No tags entered yet.