question

horemansp avatar image
horemansp asked

MQTT local & via MQTT broker

A little tutorial to connect to either the MQTT broker in the cloud (accessible from anywhere) or your local MQTT broker on the system itself via local LAN with MQTT Explorer.

Local

The system has a build in MQTT broker to which you can connect. In the console you will need to enable this MQTT broker to publish on local LAN.

Next find out the local IP address your system is using. You should find this under settings/Ethernet in the console.

Configure MQTT Explorer:
There is no certificate required, no username, no password.

1662544093243.png

1662544126710.png

You should see something like this:

1662544201666.png


Cloud MQTT broker

Your system publishes data to the cloud, which in turn is used for your web and mobile app.
There are several MQTT cloud brokers. There are maximum 128 systems connected to a cloud broker. The DNS address of the cloud broker will be something like: mqtt86.victronenergy.com

But how do you find out the broker you should use for your installation?
This can be calculated based on the portal ID you have.

Your portal ID can be found on either:

  • The console under settings/VRM Online Portal
  • The web application under settings/general

You can use this little python program to find your cloud broker DNS name: (replace the VRM_portal_ID with your ID) (it uses the ASCII code of each character, adds them together and divides by 128)

This should return something like the above example.

VRM_portal_ID = "d41243b50dfc"

def _get_vrm_broker_url(_system_id):
    sum = 0
    for character in _system_id.lower().strip():
        sum += ord(character)
    broker_index = sum % 128
    return "mqtt{}.victronenergy.com".format(broker_index)

print(_get_vrm_broker_url(VRM_portal_ID))

Now you know the MQTT broker address you can configure the MQTT Explorer.

You will need the following:

  • Username & password of your web portal
  • a certificate

1662544825185.png

You will need to add a valid certificate which you can find on this GitHub repository: https://github.com/victronenergy/dbus-mqtt

You can simply download the ZIP and extract the file:

1662545086645.png



Under the advanced section click on certificates

1662544919173.png

Add the certificate to the SERVER CERTIFICATE (CA) by clicking on the button.

1662545167877.png


Now connect and you should see the following:

1662545284721.png


Keep the connection alive: get the full content

It seems that you have to publish a "keepalive" message to the MQTT server every 55 seconds to keep on getting more information than just the system/serial information. If not it will stop receiving the full data.

1670885961405.png



Hope this helps.

Multiplus-IIMQTT
1662544093243.png (82.2 KiB)
1662544126710.png (59.6 KiB)
1662544201666.png (291.8 KiB)
1662544825185.png (95.6 KiB)
1662544919173.png (59.8 KiB)
1662545086645.png (289.6 KiB)
1662545167877.png (58.7 KiB)
1662545284721.png (206.4 KiB)
1670885961405.png (61.5 KiB)
mqttlocallan.mp4 (1.1 MiB)
2 |3000

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

8 Answers
yves2 avatar image
yves2 answered ·

Hello !

With MQTT Explorer, I have only "Keepalive" and "Serial" under the topic "N". How to get other informations ?

1669313518183.png


1669313518183.png (17.2 KiB)
3 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.

Martin avatar image Martin commented ·

The broker will send additional information when you publish an empty message to the topic 'R/<your VRM-Portal ID>/keepalive'.
I've added a NodeRed function to send this message every 50 seconds, since the broker will stop publishing to the other topics. It looks like this:
1669834799848.png1669834838123.png

1 Like 1 ·
1669834799848.png (5.6 KiB)
1669834838123.png (18.7 KiB)
taylortops avatar image taylortops commented ·

Read keep alive once every 55 seconds . For your case, that would be: "R/48e7da862479/keepalive ", nothing in the body.

0 Likes 0 ·
usernamepasswordbs avatar image usernamepasswordbs commented ·
A reboot of the Cerbo, or wherever Venus is running, might bring all the other stuff up.
0 Likes 0 ·
taylortops avatar image
taylortops answered ·

Can I publish custom data to my local broker and see bridge over to VRM? eg

W/<portal-id>/custom/test
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.

taylortops avatar image taylortops commented ·
Resolved this myself. The publishing device must be registered against the broker.
0 Likes 0 ·
jimslim avatar image jimslim taylortops commented ·

I like to do something similar.

My idea is to publish my own mqtt topics over the mqtt-out-node on the locally installed node red instance.

Could this be possible in any ways?

0 Likes 0 ·
tanksnipe avatar image
tanksnipe answered ·

Good day,

We are busy testing a Cerbo GX (v2.92) for a client and have it connected to the internet and can see it is a live on the VRM portal. However, when I connect to the mqtt cloud server, in this case mqtt7, I only see the server name and no other topics. I even tried sending the keep alive but no new info. Did I miss a setting? We don't have anything connected to it., could that be a problem?

1670568701141.png


1670568613999.png



1670568613999.png (28.4 KiB)
1670568701141.png (19.0 KiB)
5 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.

horemansp avatar image horemansp commented ·

Not sure, but from the screenshot of the VRM portal there seems not to be any data available yet. May that be the problem?

0 Likes 0 ·
tanksnipe avatar image tanksnipe horemansp commented ·

Hi horemansp,


I have turned on demo mode to send data to the VRM and have also enabled local broker to send keep alive. and can see values on local broker. but no change on cloud MQTT broker...

1670934873625.png

1670934896519.png

1670934943660.png

1670934958791.png

0 Likes 0 ·
1670934873625.png (35.0 KiB)
1670934896519.png (41.4 KiB)
1670934943660.png (50.2 KiB)
1670934958791.png (26.5 KiB)
Show more comments
goldriver avatar image
goldriver answered ·

Has anyone been able to find the longitude/latitude in the locat MQTT messages ?

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.

itsme avatar image itsme commented ·
if you have the large system with Node-Red, you can use the "MQTT" Node to push the LAT/LON Information to any MQTT Server you want form your GX device
0 Likes 0 ·
frankwalter avatar image
frankwalter answered ·

Have done all of these things > works fine exept ...

... when I use the created dashboard on external device this is very slow or hangs up. This happens at laptop or cellphone as well.

Result: Cannot use the nodeRed of the Cerbo

Any idea?

2 |3000

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

Simon Hackett avatar image
Simon Hackett answered ·

As this community post comes up pretty consistently for people starting out with MQTT and Venus, I wanted to add one remarkably useful improvement to the examples above, in terms of how to make the keepalive 'work'.

Instead of going to all the trouble of figuring out the VRM portal ID, you can derive the right strings to feed in to MQTT without knowing the VRM ID at all, and turn that into a keep alive topic subscription string.

The trick is to appreciate that you can use the MQTT wildcard character (+) in place of the VRM ID.

For retrieving actual data from the GX, you can also use that wildcard character to do all the work - so you never need to know the VRM ID, and you can create code that is independent of that VRM ID.

Just use a + in all spots where you would otherwise have used the VRM ID :)

Here (below) is an example flow that retrieves the serial number in this way, turns it in to a subscription to the serial number that can be used as a keepalive, and then retrieves updates of a few real-world values to show that it works... also some screen shots.

All you need to change is the IP address in the 'Venus GX' configuration inside this flow, to be the IP address of your own GX, and it should 'just work' for you, too :

Flow screen shot:

flow-screenshot.png

Change node that sets up the keepalive string:

change-node.png


flow-screenshot.png (196.3 KiB)
change-node.png (100.9 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.

Simon Hackett avatar image
Simon Hackett answered ·

And here is the actual flow, saved as a text file - rename to .json and upload into Node-RED:

mqtt-example copy.txt


2 |3000

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

thijsfranssen avatar image
thijsfranssen answered ·

Hi!

I am working on a installation management tool. I have two questions:

  • Is it possible to use the VRM Acces token for MQTT instead of username and password?
  • Is MQTT over VRM enabled by default or should this also be enabled? If I turn MQTT over LAN off in the settings menu it still works for me, but is this always the case?

Thanks!

2 |3000

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