MqTt connection requests
# umh-support
s
Does anyone know why the UMH MQTT Broker would reject connection requests of some devices as not authorized, but accept others? They connected to a standalone hivemq-ce instance without problem. The HiveMQ log (via
kubectl
) doesn't list any connection requests at all, but it does tell me there's no authentication or authorisation.
l
For some Tasmota Smart Sockets of mine this took me ages to figure it out, but HiveMQ config map by default rejects retained messages and enforces UTF 8 validation. I’m on the road but will share my guide below that I tinkered with
- Disable UTF-8 Validation: Modified the
hivemq.xml
configuration file:
Copy code
xml
    <utf8-validation>
        <enabled>false</enabled>
    </utf8-validation>
- Enable Retained Messages: Configured HiveMQ to support retained messages:
Copy code
xml
    <retained-messages>
        <enabled>true</enabled>
    </retained-messages>
- Allow Empty Client IDs (Optional): Although not the direct issue, we allowed empty client IDs for flexibility:
Copy code
xml
    <allow-empty-client-id>
        <enabled>true</enabled>
    </allow-empty-client-id>
The config map can be best edited using Lens / UMHLens
For example my tasmota would always send a retained message and I could not deactivate that, so I had to change that. Also your user / password could be required to be strong, even while it is not needed 🤷‍♂️ for example StrongPass!12345 would make it connect, but that was more a firmware issue on my end
j
@Ferdinand I remember there was something about those MQTT options that we changed, do you have some background infos on this?
f
s
OK, so I was able to reproduce this in Node-Red. I set a retained last will message, and the connection was refused - with both MQTT 3.1.1 and 5. The 3.1 error message now makes sense - because it doesn't have a more appropriate error code that it can send. Changing the client's retained setting to
false
allows the connection to succeed, but of course breaks the last will strategy. How can I change Hive's
config.xml
permanently on my UMH system? Changes inside the container will be gone when it restarts, right?
j
FYI: If I remember correctly, HiveMQ stores all of those retained messages, which can result in very high memory usage (or something similar). @Ferdinand @Luke van Enkhuizen do you know how we can change the config permanently? i know its possible, but don't remember how exactly. i assume some configmap
f
I don't think that setting is exposed via helm, but you can change it in the configmap directly. (united-manufacturing-hub-hivemqce-hive in the united-manufacturing-hub namespace)
l
Yes config maps but be sure to backup in case of updates! In the hivemq xml file.
Indeed it’s not recommended for large amount of tags
s
Thanks for the tips. I patched the configmap and restarted HiveMQ (deleted the pod so Kubernetes recreated it). Now it's doing what I want. Yay!
FYI... after restarting HiveMQ, I noticed the tag browser in the online management console could no longer see any tags. Rebooting my VM made that work again. I guess some component didn't feel like auto-reconnecting. Please feel free to add this to the ToDo list!
BTW, does anybody need the commands used to alter the configmap?
j
Feel free to post them, I can then create maybe later an article for it 🙂
s
OK, here's what I did. I hope Discord copes with the formatting...
Copy code
# Look at current HiveMQ configuration
sudo $(which kubectl) exec --stdin --tty \
    -n united-manufacturing-hub united-manufacturing-hub-hivemqce-0 --kubeconfig /etc/rancher/k3s/k3s.yaml \
    -- \
    cat /opt/hivemq-ce-2024.1/conf/config.xml

# List available ConfigMaps
sudo $(which kubectl) get configmaps \
    -n united-manufacturing-hub --kubeconfig /etc/rancher/k3s/k3s.yaml

# Get current configmap
sudo $(which kubectl) get configmap \
    -n united-manufacturing-hub --kubeconfig /etc/rancher/k3s/k3s.yaml \
    united-manufacturing-hub-hivemqce-hive \
    --output yaml > united-manufacturing-hub-hivemqce-hive.yaml
    
# Create a patch file containing the changed YAML (ie: data->config.xml, set retained messages enabled to true)
sudo $(which kubectl) patch configmap \
    -n united-manufacturing-hub --kubeconfig /etc/rancher/k3s/k3s.yaml \
    united-manufacturing-hub-hivemqce-hive \
    --patch-file united-manufacturing-hub-hivemqce-hive.patch.yaml

# The config.xml file inside the pod will have now been changed.

# Restart HiveMQ by deleting the pod (and having Kubernetes recreate it)
sudo $(which kubectl) delete pod \
    -n united-manufacturing-hub --kubeconfig /etc/rancher/k3s/k3s.yaml \
    united-manufacturing-hub-hivemqce-0
2 Views