MQTT broker sending old messages

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

[
    {
        "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
    }
]

I suspect that it is 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.

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

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.

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.

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.

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

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 or node-red-contrib-persist (node) - Node-RED or node-red-contrib-state (node) - Node-RED

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

No

Yes

Let me test it and post it back in an hour

yes

yes

let me try this

thanks

[
    {
        "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
    }
]

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

Also the flow is showing test.mosquittto.org
Also you have an MQTT loop there, clear the passthrough checkbox in the text node.

I don't have professional License yet

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

In the Text node unclick the box that tells it to pass input messages to the output
image

In the debug nodes (one connected to the MQTT In and one to your Text node, as you already have it
image

But you said

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.

1 Like

image
After some time
image

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?

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