# Connection lost in Raspberry PI Zero W

**URL:** https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307
**Category:** Hardware
**Created:** [6 April 2020 07:49 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307 "2020-04-06T07:49:36Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [6 April 2020 07:49 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/1 "2020-04-06T07:49:36Z")

</div>

Hello Guys  
I am working on large node-red project in Raspberry PI Zero W.  
That project contains over 1900 nodes and MQTT communication with C application.  
But I see connection lost almost of time.  
Also I have many 'time interval' nodes, but real time interval is irregular.

I tested it on RPI4, it works well without any connection lost and I can see regular time interval in same node-red flow.  
I need to implement this project on RPI zero W.  
Following is CPU usage on RPI zero W.

```auto
 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  258 daytech 25 5 343200 241920 26368 R 77.8 54.6 66:08.55 node-red
  993 root 20 0 19220 1928 1688 S 17.4 0.4 6:16.56 i2c_publisher
 1024 daytech 20 0 10184 3044 2560 R 1.9 0.7 0:35.83 top
 1059 root 20 0 0 0 0 I 1.3 0.0 0:01.32 kworker/0:2-events_power_efficient
  896 daytech 20 0 12856 4540 3204 S 0.6 1.0 0:05.20 sshd
 1010 daytech 20 0 12188 4212 3432 S 0.6 1.0 0:07.36 sshd
    7 root 20 0 0 0 0 S 0.3 0.0 0:36.22 ksoftirqd/0
  128 root 20 0 0 0 0 S 0.3 0.0 1:35.25 spi0
  277 avahi 20 0 5888 2888 2572 S 0.3 0.7 0:07.47 avahi-daemon
  300 root 20 0 27640 1344 1216 S 0.3 0.3 0:05.08 rngd
 1025 root 20 0 0 0 0 I 0.3 0.0 0:20.38 kworker/0:1-events
    1 root 20 0 33564 7600 6228 S 0.0 1.7 0:09.07 systemd
    2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd

```

Can you help me for it?

Thank you.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 April 2020 08:13 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/2 "2020-04-06T08:13:51Z")

</div>

If that is a typical output from top then it is unlikely to work as you are at 78% cpu and 55% memory just for Node-RED. Usually you should be aiming for less than 10% . As we have no idea what you flow is trying to do - all we can suggest is that you do less of it... either less scale (fewer nodes) or less speed (fewer messages) or less complex (again fewer nodes).

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [6 April 2020 09:44 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/3 "2020-04-06T09:44:31Z")

</div>

Hello dceejay  
Thank you for your reply.  
I have noticed when number of interval nodes is reduced, the frequency of it's connection lost is low a bit.  
But time interval is still irregular.

Is there not the solution for resolving this issue?

Thank you.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [6 April 2020 09:59 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/4 "2020-04-06T09:59:53Z")

</div>

> [@XiaoBin](#):
>
> Is there not the solution for resolving this issue?

So it runs fine on a Pi4 - an ARM v8, 1.5 GHz, 1GB, 2GB or 4GB machine (you didn't specify) but not so well on the Pi Zero W - an ARM1176, 1GHz, 512MB machine, or to put it another way, it works on the fast machine, but not the one that has half (or 1/4 or 1/8) the memory and runs 1/3 slower.

I would suggest that you try optimizing your flow as @dceejay suggested

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [6 April 2020 14:40 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/5 "2020-04-06T14:40:44Z")

</div>

Hello Zenofmud  
Thank you for your reply.  
I have just found the interested thing.  
Once I removed "Aedes MQTT broker" node in node-red flow, there is no connection lost.  
But CPU's usage is still 60%.

MQTT communication between node-red and C application is issue?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [6 April 2020 15:49 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/6 "2020-04-06T15:49:53Z")

</div>

Well if you removed the MQTT, you are not getting msg's from it so you have reduced the load on the Pi.

Where were you seeing the 'connection lost' message? in the editor? in the dashboard?

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [6 April 2020 16:01 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/7 "2020-04-06T16:01:11Z")

</div>

I am seeing "connection lost" at top right on dashboard.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [6 April 2020 16:30 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/8 "2020-04-06T16:30:35Z")

</div>

Well I would guess that remving the MQTT datta comng in reduced the load on the Pi Zero W allowing it to keep up the connection to the dashboard.

So now you are left with a choice - keep MQTT off or run it on a more powerful Pi.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [6 April 2020 17:48 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/9 "2020-04-06T17:48:37Z")

</div>

Are you running/viewing the dashboard on the pi 0 as well. It would be better to use a browser on a different machine.

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [6 April 2020 18:28 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/10 "2020-04-06T18:28:42Z")

</div>

I am connecting to RPI on other machine.

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [7 April 2020 03:47 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/11 "2020-04-07T03:47:35Z")

</div>

Hello Zenofmud and dceejay  
Thank you for your reply  
I need your help for data exchange between C application and node-red.  
I read the data from I2C slave in C application and then published to node-red using MQTT on current solution.  
But this has some issue on connection, as you knew.  
Before I use MQTT, I used file operation for it, but it missed some data because read/write synchronization.  
The data received from I2C data need to be processed within 30ms at least.

Besides of MQTT or file operation, what method can I use for my application?

Best regards.

XiaoBin.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 April 2020 08:48 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/12 "2020-04-07T08:48:11Z")

</div>

What makes you think that the problem is with MQTT?

There is no way on a pi zero running Raspbian that you will be able to guarantee 30ms action. It is not a real time operating system and sometimes it will be busy doing other things for longer than that.

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [7 April 2020 08:59 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/13 "2020-04-07T08:59:36Z")

</div>

Thank you Colin.  
If time is 100ms, is it possible?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 April 2020 10:11 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/14 "2020-04-07T10:11:07Z")

</div>

> [@XiaoBin](#):
>
> If time is 100ms, is it possible

There is no answer to that question because it depends on what else is going on, and what you mean by 'possible'. As I said, Raspbian (based on Debian) is not a Real Time OS, so nothing is guaranteed. I the Pi is not heavily loaded (I suspect yours _is_ heavily loaded) then usually response would be better than 10ms I think, but occasionally it may go away for large fractions of a second, or even more. There is no way of knowing whether it is good enough for your requirement other than trying it.

---

<div class="post-metadata">

### Author: ![XiaoBin](https://avatars.discourse-cdn.com/v4/letter/x/f04885/32.png) [@XiaoBin](https://discourse.nodered.org/u/XiaoBin)
#### Post date: [7 April 2020 16:23 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/15 "2020-04-07T16:23:59Z")

</div>

Hello Colin  
That's good.  
I want the stable communication between C application and Node-RED without connection lost.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 April 2020 17:06 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/16 "2020-04-07T17:06:19Z")

</div>

As has already been pointed out if the processor is working 100% then it is unlikely to work well.

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [7 April 2020 19:57 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/17 "2020-04-07T19:57:18Z")

</div>

Can you explain some more about your use case? For example you mention it runs fine on a pi4, but it has to run on a pi0. Why does it need to run on that pi0 specifically? Since it has far fewer capabilities than the other pi models, what you’re doing here (you mentioned a huge number of nodes in your opening post), might simply be too heavy to run on a pi0. What part of your use case makes it so important it runs on that, and would it be possible to delegate tasks instead?

I use a pi0w myself to test parts of flows for performance occasionally. If it still runs moderately smooth on it they’re good to go. But once you feel the delays in seconds, not just milliseconds, things have to be changed.

---

<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: [6 June 2020 19:57 UTC](https://discourse.nodered.org/t/connection-lost-in-raspberry-pi-zero-w/24307/18 "2020-06-06T19:57:19Z")

</div>

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