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:
-
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_pubandmosquitto_subcommands. -
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 -
Items File: My
lovros.itemsfile looks like this:
Group All
Group gGroundFloor (All)
Group GF_Living “Living Room” -
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]”}
}
} -
NodeMCU Code: The NodeMCU is subscribed to
espInand publishes toespOut. 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.