# MQTT broker sending old messages

**URL:** https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114
**Category:** General
**Created:** [5 March 2021 19:03 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114 "2021-03-05T19:03:19Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [5 March 2021 19:03 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/1 "2021-03-05T19:03:19Z")

</div>

Hi,  
I am using MQTT to retain the comments using text file after power cycle of R Pi. Initially when i enter comments it save perfectly fine. But after approximately 1 hours, it resets to the 2 days old message which is probably the same as i entered when i set this up.

That's my flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/d/3d402847ae54aa27d8ebf44abe99cd380fde1996.png)

```auto
[
    {
        "id": "1466334c.fd9ffd",
        "type": "ui_text_input",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "Enter Comments Here",
        "tooltip": "",
        "group": "64754f4c.b5122",
        "order": 7,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "text",
        "delay": "5000",
        "topic": "FP04",
        "x": 1540,
        "y": 360,
        "wires": [
            [
                "262c1319.c5459c"
            ]
        ]
    },
    {
        "id": "262c1319.c5459c",
        "type": "mqtt out",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/comments/fp04",
        "qos": "2",
        "retain": "true",
        "broker": "b90d0ecc.41907",
        "x": 1820,
        "y": 360,
        "wires": []
    },
    {
        "id": "d5f76e5d.feebc",
        "type": "mqtt in",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/comments/fp04",
        "qos": "2",
        "datatype": "auto",
        "broker": "b90d0ecc.41907",
        "x": 1270,
        "y": 360,
        "wires": [
            [
                "1466334c.fd9ffd"
            ]
        ]
    },
    {
        "id": "64754f4c.b5122",
        "type": "ui_group",
        "z": "",
        "name": "FP-04",
        "tab": "520d4e1.6420bb",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "b90d0ecc.41907",
        "type": "mqtt-broker",
        "name": "",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "520d4e1.6420bb",
        "type": "ui_tab",
        "z": "",
        "name": "FORKLIFTS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

```

---

<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: [5 March 2021 21:20 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/2 "2021-03-05T21:20:34Z")

</div>

I suspect that it is [test.mosquitto.org](http://test.mosquitto.org) messing you about. Possibly it is restarting and has not properly persisted your recent values.  
Install a local copy of mosquitto and see if it is ok then.

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [8 March 2021 11:46 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/3 "2021-03-08T11:46:57Z")

</div>

> [@Colin](#):
>
> I suspect that it is [test.mosquitto.org](http://test.mosquitto.org) messing you about. Possibly it is restarting and has not properly persisted your recent values.

Is it because i am using alot of MQTT nodes and it's just test version?

---

<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: [8 March 2021 15:45 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/4 "2021-03-08T15:45:22Z")

</div>

I have no idea why it might be happening, but I wouldn't worry about it. Once you switch to the broker you are going to use after you finish testing then it will probably be ok.

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 13:50 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/5 "2021-03-09T13:50:18Z")

</div>

I am still getting the same old message after like 1 hour when i send a new message. Initially i am getting the new message but when i try it after 1 hours it's the old message that i first injected when i set it up.

---

<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: [9 March 2021 14:08 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/6 "2021-03-09T14:08:09Z")

</div>

When if goes back to the old value have you been disconnected from the broker (or node red not running or similar)?

Are you using exactly the same flow that you showed at the start? If not post the current flow please.

Add debug nodes showing what is being published and what is being received from MQTT. When it fails show us what the debug shows.

---

<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: [9 March 2021 14:24 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/7 "2021-03-09T14:24:52Z")

</div>

Silly question (but someone has to ask)...

Have you updated the broker connection to point to your local mosquitto broker?

Another silly question...

Is mosquitto installed on the same RPi as node-red?

NOTE: Retained messages will not survive a reboot (by default mosquitto retained messages are held in memory). [See here](https://pagefault.blog/2020/02/05/how-to-set-up-persistent-storage-for-mosquitto-mqtt-broker/#:~:text=Retained%20messages&text=When%20a%20client%20subscribes%2C%20the,the%20persistence%20option%20is%20set.)

Another solution might be to have file backed context (see docs) & store the value in flow or global context

Or use one of the file backed nodes  
e.g. [node-red-contrib-key-value-store (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-key-value-store) or [node-red-contrib-persist (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-persist) or [node-red-contrib-state (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-state)

I have used key-value-store in the past.

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 14:26 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/8 "2021-03-09T14:26:30Z")

</div>

> [@Colin](#):
>
> When if goes back to the old value have you been disconnected from the broker (or node red not running or similar)?

No

> [@Colin](#):
>
> Are you using exactly the same flow that you showed at the start? If not post the current flow please.

Yes

> [@Colin](#):
>
> Add debug nodes showing what is being published and what is being received from MQTT. When it fails show us what the debug shows.

Let me test it and post it back in an hour

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 14:27 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/9 "2021-03-09T14:27:56Z")

</div>

> [@Steve-Mcl](#):
>
> Have you updated the broker connection to point to your local mosquitto broker?

yes

> [@Steve-Mcl](#):
>
> Is mosquitto installed on the same RPi as node-red?

yes

> [@Steve-Mcl](#):
>
> NOTE: Retained messages will not survive a reboot (by default mosquitto retained messages are held in memory). [See here](https://pagefault.blog/2020/02/05/how-to-set-up-persistent-storage-for-mosquitto-mqtt-broker/#:~:text=Retained%20messages&text=When%20a%20client%20subscribes%2C%20the,the%20persistence%20option%20is%20set.)
> 
> Another solution might be to have file backed context (see docs) & store the value in flow or global context
> 
> Or use one of the file backed nodes  
> e.g. [node-red-contrib-key-value-store (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-key-value-store) or [node-red-contrib-persist (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-persist) or [node-red-contrib-state (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-state)
> 
> I have used key-value-store in the past.

let me try this

thanks

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 14:45 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/10 "2021-03-09T14:45:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aeac1d9fbdcfcbab4f2d8fca7cb00e35ca6be54f.png)

```auto
[
    {
        "id": "a8c8c4cb.1ce258",
        "type": "ui_text_input",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "Enter Comments Here",
        "tooltip": "",
        "group": "219d8573.b713ea",
        "order": 7,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "text",
        "delay": "5000",
        "topic": "FE06",
        "x": 520,
        "y": 340,
        "wires": [
            [
                "db15d2a1.e8b78",
                "aff8290b.0e2278"
            ]
        ]
    },
    {
        "id": "db15d2a1.e8b78",
        "type": "mqtt out",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/comments/fe06",
        "qos": "",
        "retain": "true",
        "broker": "b90d0ecc.41907",
        "x": 940,
        "y": 340,
        "wires": []
    },
    {
        "id": "8963fa15.28d3a8",
        "type": "mqtt in",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/comments/fe06",
        "qos": "2",
        "datatype": "auto",
        "broker": "b90d0ecc.41907",
        "x": 210,
        "y": 340,
        "wires": [
            [
                "a8c8c4cb.1ce258"
            ]
        ]
    },
    {
        "id": "aff8290b.0e2278",
        "type": "debug",
        "z": "935db92.1ef9548",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 870,
        "y": 400,
        "wires": []
    },
    {
        "id": "49b41361.4833fc",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 220,
        "y": 300,
        "wires": [
            [
                "a8c8c4cb.1ce258"
            ]
        ]
    },
    {
        "id": "219d8573.b713ea",
        "type": "ui_group",
        "z": "",
        "name": "FE-06",
        "tab": "520d4e1.6420bb",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "b90d0ecc.41907",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "520d4e1.6420bb",
        "type": "ui_tab",
        "z": "",
        "name": "FORKLIFTS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/eaeda1a39dcd34f49357c94a94a2973403009eea.png)

---

<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: [9 March 2021 15:04 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/11 "2021-03-09T15:04:45Z")

</div>

You haven't configured a node showing what is coming out of the MQTT node.  
Set them both to show Complete Message

---

<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: [9 March 2021 15:07 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/12 "2021-03-09T15:07:57Z")

</div>

Also the flow is showing [test.mosquittto.org](http://test.mosquittto.org)  
Also you have an MQTT loop there, clear the passthrough checkbox in the text node.

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 15:12 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/13 "2021-03-09T15:12:15Z")

</div>

> [@Colin](#):
>
> Also the flow is showing [test.mosquittto.org](http://test.mosquittto.org)

I don't have professional License yet

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 15:19 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/14 "2021-03-09T15:19:22Z")

</div>

> [@Colin](#):
>
> You haven't configured a node showing what is coming out of the MQTT node.  
> Set them both to show Complete Message

Please explain little bit. I am doing this for first time. Still learning. Thanks

---

<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: [9 March 2021 15:29 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/15 "2021-03-09T15:29:25Z")

</div>

In the Text node unclick the box that tells it to pass input messages to the output  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/418b1cde1e6a5374dca096fa2d21eea89e47c546.png)

In the debug nodes (one connected to the MQTT In and one to your Text node, as you already have it  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e5bd69601f3f81fd0b1bc6de6edc0e69a6a16b55.png)

> [@HZB](#):
>
> I don't have professional License yet

But you said

> [@HZB](#):
>
> > [@Steve-Mcl](#):
> >
> > Have you updated the broker connection to point to your local mosquitto broker?
> 
> yes

However, I am confident now that it is not the broker that is the problem. It is the fact that you have an mqtt loop, so you send a message to MQTT, that immediately comes back in on the MQTT In node, it passes through the text node and gets sent to MQTT again and so on for ever. Since you are using an external broker there are messages in transit all the time which is causing the problem.

---

<div class="post-metadata">

### Author: ![HZB](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@HZB](https://discourse.nodered.org/u/HZB)
#### Post date: [9 March 2021 16:01 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/16 "2021-03-09T16:01:23Z")

</div>

> [@Colin](#):
>
> However, I am confident now that it is not the broker that is the problem. It is the fact that you have an mqtt loop, so you send a message to MQTT, that immediately comes back in on the MQTT In node, it passes through the text node and gets sent to MQTT again and so on for ever. Since you are using an external broker there are messages in transit all the time which is causing the problem.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5b5cb89ae720da2f4262b4f92c8bdb4bf4f64989.png)  
After some time  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/299a798d42e8987494465660a45bb2e6ac941cf3.png)

---

<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: [9 March 2021 16:14 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/17 "2021-03-09T16:14:09Z")

</div>

Why do you think I asked you to add the debug nodes? Could it possibly be so that you can show us what they show when you enter data?

---

<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: [8 May 2021 16:14 UTC](https://discourse.nodered.org/t/mqtt-broker-sending-old-messages/42114/18 "2021-05-08T16:14:10Z")

</div>

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