How to config MQTT Message

Hi to all,

I was looking for some solution but with no success:

I have a device which sends information thru MQTT. What I wish is, when I receive command or status, only update OH UI. Only when I change item in Oh UI, is should send an corresponded command.

Next i want a button element for sending any free text thru MQTT (i.e. hello world) either ON or OFF.

My item config till now:

Switch java_text “Text from MQTT” (gRaspPi1) { mqtt="<[localbroker:command/IoTDemo/openHAB/java_text:state:default]"}
Switch java_send “Text to MQTT” (gRaspPi1) { mqtt=">[localbroker:command/IoTDemo/openHAB/java_text:command:testmeldung:default]", autoupdate=“false”}

config for sitemap:

Switch item=java_text icon="text"
Switch item=java_send icon=“text” mappings=[ON=“Los”]

I hope anybody can help me.
Best wishes

Do either of the two items work? What are you using as a the localbroker? Have you installed the MQTT binding?

Broker and MQTT works well. My point is only, i.e. when I click on Switch 'java_text ’ my broker receives command as expected but also state and this I don’t want. State should only send from corresponding device.

Other item generates two pair of command and status:

Switch led_rt “LED rot” <led_rt> (gRaspPi1) { mqtt=">[localbroker:command/IoTDemo/openHAB/led_rt:command:*:default],<[localbroker:command/IoTDemo/openHAB/led_rt:state:default]", autoupdate=“false”}

Log file:

1490081938: Received PUBLISH from openHABservice (d0, q1, r0, m21, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBACK to openHABservice (Mid: 21)
1490081938: Sending PUBLISH to mosqsub/5740-it-AIO-PC (d0, q0, r0, m0, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBLISH to openHABservice (d0, q1, r0, m15, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Received PUBLISH from openHABservice (d0, q1, r0, m22, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBACK to openHABservice (Mid: 22)
1490081938: Sending PUBLISH to mosqsub/5740-it-AIO-PC (d0, q0, r0, m0, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBLISH to openHABservice (d0, q1, r0, m17, ‘command/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Received PUBACK from openHABservice (Mid: 15)
1490081938: Received PUBLISH from openHABservice (d0, q1, r0, m23, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBACK to openHABservice (Mid: 23)
1490081938: Sending PUBLISH to mosqsub/5740-it-AIO-PC (d0, q0, r0, m0, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBLISH to openHABservice (d0, q1, r0, m19, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Received PUBACK from openHABservice (Mid: 17)
1490081938: Received PUBLISH from openHABservice (d0, q1, r0, m24, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBACK to openHABservice (Mid: 24)
1490081938: Sending PUBLISH to mosqsub/5740-it-AIO-PC (d0, q0, r0, m0, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))
1490081938: Sending PUBLISH to openHABservice (d0, q1, r0, m20, ‘state/IoTDemo/openHAB/led_rt’, … (3 bytes))

Next question: how can I send a string like Hello World by click on Switch?

Ok, I see the problem and if you get a solution let us all know. I use two tags, one for writing and one for reading. Then I choose which one I display by having another tag Read_or_Write. If set the write tag and value shows and if clear it displays the read value.

What you experience is correct behavior - although I understand it is not what you want, :slight_smile:

The following tells OpenHAB to subscribe to a topic in your MQTT broker, meaning that messages published to this topic will be sent to OpenHAB:

mqtt="<...

and, the following tells OpenHAB to publish a message to a topic in your MQTT broker:

mqtt=">

Since both item definitions point to the same topic, you will receive what you send. Both OpenHAB and the MQTT broker simply does what they are told to do.

To fix this, you need to use two different topics towards your device; one for state updates (that you subscribe to) and one for commands (that you publish to).

Hi, thank you for your hinds. I’ll give a try it.