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

**URL:** <https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349>\
**Category:** General\
**Created:** [21 September 2021 15:12 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349 "2021-09-21T15:12:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![minime](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minime/32/48411_2.png) [@minime](https://discourse.nodered.org/u/minime)\
**Post date:** [21 September 2021 15:12 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/1 "2021-09-21T15:12:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 September 2021 15:21 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/2 "2021-09-21T15:21:08Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [21 September 2021 17:38 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/3 "2021-09-21T17:38:52Z")

</div>

As @Steve-Mcl has said you should check your broker logs. You can also use MQTT Explorer ([http://mqtt-explorer.com](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.

---

<div class="post-metadata">

**Author:** ![minime](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minime/32/48411_2.png) [@minime](https://discourse.nodered.org/u/minime)\
**Post date:** [23 September 2021 14:26 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/4 "2021-09-23T14:26:01Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 September 2021 18:09 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/5 "2021-09-23T18:09:44Z")

</div>

> [@minime](#):
>
> 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

You can ...

> [@Steve-Mcl](#):
>
> 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)

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 September 2021 18:55 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/6 "2021-09-23T18:55:54Z")

</div>

How do you program the esp?

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

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

```

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [23 September 2021 21:18 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/7 "2021-09-23T21:18:18Z")

</div>

> [@jbudd](#):
>
> ```auto
> // 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...

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 September 2021 23:02 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/8 "2021-09-23T23:02:34Z")

</div>

I know, "random" isnt actually random.  
But it's not my code, it seems to be by one [knolleary](https://github.com/knolleary/pubsubclient)  
Where have I heard that name before? 😃

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

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [24 September 2021 09:45 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/9 "2021-09-24T09:45:51Z")

</div>

> [@jbudd](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 November 2021 09:46 UTC](https://discourse.nodered.org/t/two-devices-send-messages-only-the-messages-from-one-are-arriving/51349/10 "2021-11-23T09:46:17Z")

</div>

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