ottopaulsen / MMM-MQTT

MQTT Client module for MagicMirror2
MIT License
57 stars 29 forks source link

MQTT - many, many "reconnecting" messages in pm2-out.log #67

Open spitzlbergerj opened 11 months ago

spitzlbergerj commented 11 months ago

Hi, I have moved my MQTT broker to HiveMQ in the cloud. However, I now have an infinite number of "reconnecting" messages in the pm2-out.log. However, I think that subscribed MQTT messages are still read and processed.

Here is my config ` module: 'MMM-MQTT',

    position: 'top_right',

    header: 'Solarpanels',

    config: {

        logging: false,

        useWildcards: false,

        mqttServers: [

            {

                address: 'blabla.s1.eu.hivemq.cloud',  // Server address or IP address

                port: '8883',          // Port number if other than default

                user: 'StarTrekHiveMQTT',

                password: 'blablabla',

                clientId: 'mirror-mqtt-solarpanels',

                subscriptions: [

.... `

And here are the log entries ` [04.12.2023 14:47.26.719] [LOG] MMM-MQTT: Starting client for blabla.s1.eu.hivemq.cloud:8883 user StarTrekHiveMQTT

[04.12.2023 14:47.26.726] [LOG] MMM-MQTT: Connecting to mqtt://blabla.s1.eu.hivemq.cloud:8883

[04.12.2023 14:47.36.216] [LOG] MMM-MQTT: blabla.s1.eu.hivemq.cloud:8883StarTrekHiveMQTT reconnecting

[04.12.2023 14:47.41.047] [LOG] MMM-MQTT: blabla.s1.eu.hivemq.cloud:8883StarTrekHiveMQTT reconnecting

[04.12.2023 14:47.43.546] [LOG] MMM-MQTT: blabla.s1.eu.hivemq.cloud:8883StarTrekHiveMQTT reconnecting

.... `

How can I track down the cause?

Could it be because HiveMQ requires the login with TLS?

Greetings and thanks Sepp

ottopaulsen commented 11 months ago

Are you sure your connection data works? Have you tried using another tool?

spitzlbergerj commented 11 months ago

Hi, I have now tried different cloud MQTT brokers. The connection cannot be established with any of the services, as all cloud brokers require a TLS connection. Can I activate TLS in the module? Unfortunately, I haven't found anything about this.

I log in to NodeRED like this and it works:

noderedMQTTBrokerVerbindung noderedMQTTBrokerSicherheit

Thank you very much Greetings Sepp

ottopaulsen commented 11 months ago

If you look at the config, there is config for using a certificate file. You can try that. I am not too familiar with this myself, as it was developed by someone else.

stevemason commented 11 months ago

If the problem is indeed related to TLS, then potentially all you need to do is modify your config file to look something like:

mqttServers: [ { address: 'mqtts://blabla.s1.eu.hivemq.cloud', // Server address or IP address port: '8883', // Port number if other than default user: 'StarTrekHiveMQTT', password: 'blablabla', ca: '/path/to/ca/cert.crt', // Path to trusted CA certificate file clientId: 'mirror-mqtt-solarpanels',

It has been a while since I worked on this. Maybe just adding mqtts:// to the address will fix it, or you may also need to add the CA certificate file line.

Looks like hivemq uses LetsEncrypt, so this page may help you identify the correct ca file to use: https://letsencrypt.org/certificates/