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.

4 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)
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.

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

0 Likes 0 ·
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 ·
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
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.

taylortops avatar image taylortops commented ·
Resolved this myself. The publishing device must be registered against the broker.
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)
horemansp avatar image horemansp tanksnipe commented ·
So connecting to your local mqtt works?! Sure your mqqt cloud broker is mqtt7? What is your portal ID?
0 Likes 0 ·
horemansp avatar image horemansp horemansp commented ·
yes, the cloud mqtt broker is indeed mqtt7.victronenergy.com .... I have no idea to be honest...


0 Likes 0 ·
tanksnipe avatar image tanksnipe horemansp commented ·

Hi horemansp, I got it working, I enabled the VRM two-way communication and now it is showing all the data.

Thank you.

1671626593701.png

1671626602266.png


0 Likes 0 ·
1671626593701.png (31.7 KiB)
1671626602266.png (72.0 KiB)
goldriver avatar image
goldriver answered ·

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

2 |3000

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