# Mqtt takes up to 5 seconds

**URL:** <https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597>\
**Category:** General\
**Created:** [13 March 2021 22:07 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597 "2021-03-13T22:07:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)\
**Post date:** [13 March 2021 22:07 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/1 "2021-03-13T22:07:52Z")

</div>

Hello,  
I'm using mqtt broker aedes node inside node red.  
Node red is installed on raspi 4b 4gb. My mqtt device is shelly-1 wich I use to register the state of the switch and after that I turn the lights on or off. For the lights I am using philips hue. I've connected my shelly to wifi repeater. Both have perfect connection, but sometimes it takes between 5 and 10 seconds to get something happen. But it's only for the first time. When I trigger the switch again, it works instant. After some time passed. Again first trigger 5 seconds. But not every time, it's like every 2nd time. It's a little bit annoying.  
I have already installed one of those, connected to the wifi router and it works perfectly.

What could be the problem with this device. Do I miss some preference?  
I'm using qos 1.

Somehow I think my repeater is garbage. I'm using TP-Link TL-WA850RE.

Any ideas?

---

<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:** [13 March 2021 22:34 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/2 "2021-03-13T22:34:59Z")

</div>

Repeaters are notoriously bad in my experience (unless it's a good quality mesh).

Also, run top or htop on the pi. Are you getting periods of high CPU usage?

Lastly, install mosquitto & ditch aedes.

---

<div class="post-metadata">

**Author:** ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)\
**Post date:** [13 March 2021 22:53 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/3 "2021-03-13T22:53:08Z")

</div>

It's 15€ repeater, what am I expecting 🤦. But I thought it will be enough for mqtt. Well messages arrive, but not instant.

I don't think I have high cpu usage. Running only node red in the pi and it's not large.  
I will try mosquito, but I don't know what you mean with top or htop.

Thank you for your reply.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [13 March 2021 23:16 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/4 "2021-03-13T23:16:43Z")

</div>

> [@sfedo](#):
>
> but I don't know what you mean with top or htop.

node-RED is single threaded, so it only does one thing at once, which means that if the CPU is busy, there will be a backlog of commands for node-RED to execute.  
Because Aedes is running in node-RED, it's commands could be delayed in that backlog.

If you type `top` at the cmd prompt, it will show you the `%CPU` (how busy the CPU is) which may be a pointer if that is the problem.

It may also be worth adding a debug node to the Aedes node, to see if it disconnects it's subscription to your client.

---

<div class="post-metadata">

**Author:** ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)\
**Post date:** [14 March 2021 09:41 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/5 "2021-03-14T09:41:41Z")

</div>

Ok looks like it's repeater issue. Today morning I just connected the shelly relay to the router. I have terrible connection with -87dbm but still works without delay and without losing messages.

With the repeater it felt like it needs to wake up first, what takes 5-10seconds.

But I will install mosquito anyway, so I have the broker not running inside node red.

Thank you guys for your advices.

---

<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:** [28 March 2021 09:42 UTC](https://discourse.nodered.org/t/mqtt-takes-up-to-5-seconds/42597/6 "2021-03-28T09:42:18Z")

</div>

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