MQTT Integration Troubleshooting

I’m trying to set up MQTT in openHAB to control an LED via my NodeMCU, but I’m hitting a wall. Here’s what I’ve done so far:

  1. Setup: I’ve installed openHAB on my Raspberry Pi 3 and connected it to my LAN. My NodeMCU is on the same network with a static IP. MQTT is running, and I can control the LED using mosquitto_pub and mosquitto_sub commands.

  2. openHAB Configuration: In my openhab.cfg, I’ve added the MQTT settings:
    mqtt:lovronix.url=tcp://192.168.5.16:1883
    mqtt:lovronix.clientId=lovro

  3. Items File: My lovros.items file looks like this:
    Group All
    Group gGroundFloor (All)
    Group GF_Living “Living Room”

  4. Sitemap Configuration: In lovros.sitemap, I’ve set up the switch:
    sitemap lovros label=“MQTT” {
    Frame label=“NodeMCU MQTT upravljanje LEDicom” {
    Switch item=led {mqtt=“>[lovronix:espIn:command:ON:0],>[lovronix:espIn:command:OFF:1]”}
    }
    }

  5. NodeMCU Code: The NodeMCU is subscribed to espIn and publishes to espOut. It handles commands ‘0’ (OFF), ‘1’ (ON), and ‘2’ (toggle). The code seems solid, and manual testing via SSH works.

The Problem: Despite all this, the LED doesn’t respond when I toggle the switch in the openHAB UI. I’ve scoured tutorials and forums, but nothing seems to click. I suspect it’s a small oversight in the configuration, but I’m stuck.

Questions:

  • Could there be an issue with the MQTT client ID or broker setup?
  • Should the topics be prefixed with a ‘/’?
  • How can I troubleshoot the message flow between openHAB and the NodeMCU?

Any insights would be greatly appreciated! I’m eager to get this working and expand my MQTT setup for more devices.