question

Joe avatar image
Joe asked

Keepalive via NodeRed to Venus

All,

for establishing a MQTT based solution for a power reducer box I am step by step getting there.

Sending an R/<ID>/keepalive even with filtering for example to ["settings/#"] works from scratch via MQTT broker, but I am not getting it up with NodeRed. As I want to shoot every 60 seconds, Node-Red would be the perfect solution.

It can only be a "JSON Format" issue, but whatever data format I chose (string, JSON, ..) it does not work.


Can anybody please educate me, what I am doing wrong? I have literally tried everything (with brackets {[]}, w/o, etc.


1679072742178.png


Venus OSNode-REDMQTT
1679072742178.png (89.6 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

5 Answers
gerard-van-seventer avatar image
gerard-van-seventer answered ·

The keepalive is just to tell Venus to keep sending MQTT messages. If you don't the MQTT messages are cleared after a short amount of time.

I use an inject, a function and a mqtt out node. There are no return messages on a mqtt out node.

screenshot-2023-03-17-221332.jpgIf you want the read values on node-red you have to use a mqtt in node and subscribe to the topic you want and read the values you are interested on.


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

becker avatar image
becker answered ·

kannst du die Frage im deutschen Bereich noch mal stellen ? Verstehe nicht was du da machen willst.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Joe avatar image Joe commented ·
erledigt...
0 Likes 0 ·
gerard-van-seventer avatar image
gerard-van-seventer answered ·

I use a (very) simple function node which is triggered every 20 seconds (could be a little longer).

msg.topic = 'R/cxxxxxxxxx4/keepalive'
msg.payload = ''
return msg;
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Joe avatar image
Joe answered ·

Thank you Gerard!

What format is the data you send? String, JSON, ...?

How to get the return msg in Node-Red done?

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

marc-hd avatar image
marc-hd answered ·

Dear Joe,

this is my very first answer in this forum. So don`t be too harsh to me;-)

All information about the keep-alive of the mqtt broker of the victronOS you'll find at: https://github.com/victronenergy/dbus-mqtt.

I send the keep-alive within a Node-RED flow (attached at the end of my answer).

XXXXXXXXXXX

needs to be adopted to your venusOS installation. As well as the broker address:

"broker": "XXX.XXX.XXX.XXX",

which corresponds to the ip-address of your venusOS. BTW in my case it is a venusOS on a Raspberry PI.

The main difference with the suggested:

  
                  
  1. msg.topic = 'R/cxxxxxxxxx4/keepalive'
  2. msg.payload = ''
  3. return msg;

is:

I only "request" the topics I am interested in. If you send only an empty string as payload you'll get ALL topics send.

The payload needs to be a json list as listed below:

"payload": "[\"system/0/Dc/Battery/#\",\"system/0/Ac/Consumption/#\",\"system/0/Timers/#\",\"battery/1/#\",\"solarcharger/#\"]"

The topics I am interested in I checked manually with the complete topic-list:

(I personally do NOT use Microsoft products... so this is done on an xterm)

mosquitto_pub -h XXX.XXX.XXX.XXX -m '' -t 'R/XXXXXXXXXXX/keepalive
mosquitto_sub -v -I myclient_ -t "#" -h XXX.XXX.XXX.XXX > all.txt

In all.txt ALL topics are collected.

Some screenshots:

node-red-keepalive-victron-1.pngThe flow.

node-red-keepalive-victron-2.pngThe list of topics.

node-red-keepalive-victron-3.pngInterval set to 50 seconds.


I hope for someone is this post usefull...

Best regards


Marc


[
    {
        "id": "11e7538c7954de75",
        "type": "tab",
        "label": "keepAlive",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9f8ba7eb9957abd1",
        "type": "inject",
        "z": "11e7538c7954de75",
        "name": "keepAlive",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "50",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[\"system/0/Dc/Battery/#\",\"system/0/Ac/Consumption/#\",\"system/0/Timers/#\",\"battery/1/#\",\"solarcharger/#\"]",
        "payloadType": "json",
        "x": 230,
        "y": 160,
        "wires": [
            [
                "34c4a2c6e0eeda47",
                "c234e95aac810b09"
            ]
        ]
    },
    {
        "id": "34c4a2c6e0eeda47",
        "type": "mqtt out",
        "z": "11e7538c7954de75",
        "name": "",
        "topic": "R/XXXXXXXXXXX/keepalive",
        "qos": "2",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "0aa70d5af5427c60",
        "x": 660,
        "y": 160,
        "wires": []
    },
    {
        "id": "c234e95aac810b09",
        "type": "debug",
        "z": "11e7538c7954de75",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 240,
        "wires": []
    },
    {
        "id": "0aa70d5af5427c60",
        "type": "mqtt-broker",
        "name": "VenusOSmqtt",
        "broker": "XXX.XXX.XXX.XXX",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

2 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Joe avatar image Joe commented ·

Marc, even though we're both German, let's keep it English:

YOU ARE MY HERO!

The solution is:

- Send payload with inject, keep format as per official Victron docu: ["settings/#"]:

1679223131030.png

- Send topic in MQTT-Out and NOT in inject:

1679223178315.png


Result, captured w/ MQTT Explorer:

1679223079330.png

So, keepalive request send from Node-Red, limited to the topics of interest which means my FHEM server doesn't get killed ;)

0 Likes 0 ·
1679223079330.png (26.4 KiB)
1679223131030.png (28.6 KiB)
1679223178315.png (46.6 KiB)
marc-hd avatar image marc-hd Joe commented ·
Dear Joe,


I am happy that the stuff I wrote was helpful.

Have fun,


Marc


0 Likes 0 ·