[SOLVED] Not able to publish messages in a rule with mqtt

Dear all
I am trying to publish a message with mqtt when a countdown arrives a 0 from 10.
The rule is the following

rule "Panic_Button_Entered"
when 
    Item PanicButton received command
then
    if(PanicButton.state == 1){
        logInfo("loggerName", "Starting count")
        Countdown.postUpdate(10)
        if (tMyTimer !=null) 
        tMyTimer.cancel
        tMyTimer = createTimer(now.plusSeconds(1),[
        Countdown.postUpdate((Countdown.state as Number).intValue - 1)
        if ((Countdown.state as Number).intValue >=0){
            tMyTimer.reschedule(now.plusSeconds(1))}
        else{
            logInfo("loggerName", "ALLARME")
            publish("tcp://localhost:1883", "product/device", "panic")
            MqttPanicMessage.sendCommand("Panic")
        }])  
    }else{
        logInfo("loggerName", "Disactivate it")
    }
end   

I have in the mqtt.config
broker.url=tcp://localhost:1883

and in the item
String MqttPanicMessage "MqttPanicMessage is [%s]" {mqtt=">[broker:product/device:command:*:default]" }

I have a mosquitto_sub -d -t product/device/# running on the raspberry but no messages are published

Neither publish("tcp://localhost:1883", "product/device", "panic") and MqttPanicMessage.sendCommand("Panic") work

Anyone has an idea of what is wrong

Thank you
Dev

Is this the first time using MQTT or first time with a rule?

You can open another terminal on the same server to publish a message and receive the message on the other terminal window. This will verify the broker is installed and working.

Also try changing localhost to the server IP address or use 127.0.0.1

What error’s do you see in the logs?

Hi first time with a rule a little of knowldedge of Mqtt
I does not have error on the log but the mosquitto_sub -d -t product/device/# that I run on the raspberry where openhab runs is not able to subscribe meanwhile if I use mosquitto_pub -t "product/device/alert" -m "ON" everything works fine, I am able to see ON on the terminal. I would like to send a message panic from the topic “mentorage/device” but when I enter in the else where ALLARME is printed my terminal does not receive the message I publish

Dev

You publish ON and see it in what terminal?

Raspberry terminal

Dev

In fact I can receive messages with
Switch MQTT_Test "Testing..." { mqtt="<;[broker:mentorage/device/alert:state:default], >[broker:mentorage/device/alert:command:*:default]" }and if I publish on the raspberry terminal a message the state of this switch changes but I am not able to do the opposite.

Is this a typo?
Should be like this, without the ; between < and [

{ mqtt="<[broker:mentorage/device/alert:state:default], >[broker:mentorage/device/alert:command:*:default]" }

Sorry it was a typo, the ; is not there in the code

Do you have the MQTT Action installed?

Yes in the addons.cfg I have action = mqtt
and during the installation I have
2018-12-04 18:21:44.723 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.

2018-12-04 18:21:44.726 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'

2018-12-04 18:21:45.028 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

2018-12-04 18:21:45.266 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:broker

2018-12-04 18:21:45.268 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:topic

2018-12-04 18:21:45.271 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:message
[t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'

2018-12-04 18:21:45.028 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

Make sure no < > are on the ends of your broker name in the mqtt.cfg file.

When sending mqtt messages from one terminal to another, if the message is more than one word, then single quotes are needed.

Your message is a single word, but test publishing using single quotes like below.

publish('tcp://localhost:1883', 'product/device', 'panic')

Your error comes from your use of the MQTT action. It should be:

publish("broker", "product/device", "panic")

As per the docs:

As broker is defined in your mqtt.cfg as: broker.url=tcp://localhost:1883

Thank you very much
Dev