Two devices send messages, only the messages from one are arriving

Hi there`

I'm new to node red and have an issue with multiple devices.
I've managed to send data from my esp via mqtt to node-red. this data is processed and stored in influxDB. so far so good, everything worked.
the next step was to multiply the devices sending messages. when I start my second esp (same code), the MQTT messages are arriving at node red, but the messages from the previous device are no longer arriving. When I reset the first device the messages from the first device are here, but the messages from the second device no more.
It seemed to me that only one device can send on one topic. So I created a new topic for the second device but the results were the same: only messages from one device were arriving at node red.

Any help?

Thanks in advance

I'm using node red v206

Are you setting unique MQTT client ID for the esp devices?

Check your brokers logs

Ps, yes, you need unique topics. How else would you know which device is sending data?

You could always use the MAC address to form part of the topic (and client ID) to make them unique (and therefore keep your esp code the same/portable)

As @Steve-Mcl has said you should check your broker logs. You can also use MQTT Explorer (http://mqtt-explorer.com) to look at messages in real time to see if they are in fact being sent but not being received correctly by your MQTT-in nodes.

I have a similar setup with multiple ESP-based devices sending sensor readings or receiving commands, and although most messages have unique topics there are some which I use a fixed topic for, as I'm not worried which device it came from.

thanks for the answers.
I checked the broker logs and noticed that I can't have the same code twice because they both had the same mqtt client id and therefore the mqtt broker disconnect the first one.

thanks again for the support!

You can ...

Or generate a random client ID or use the static/DHCP IP address to make up a client ID

How do you program the esp?

If you use the Arduino IDE, the examples for PubSubClient.h include generating random client IDs.

    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);

There's a chance that using random() could give a repeated ID, especially if it's done quite early the startup code, before any variable time steps like connecting to the WiFi. I've gone with using the MAC address as mentioned by @Steve-Mcl as it's supposed to be unique for every device.

eta : unless the random seed is set "randomly" during startup, you'll actually get the same value every time, so it's probably not a good way to set the client ID...

I know, "random" isnt actually random.
But it's not my code, it seems to be by one knolleary
Where have I heard that name before? :smiley:

And in the example code it sets the client id, tries to connect and if it fails, starts again.

Ah, right - that would work. I only glanced at the examples when implementing my framework since it's a very easy library to set up and use.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.