Basic Question on MQTT Binding

I am trying to test MQTT binding.
I put a simple test item in my test.items.
Number Temp1 "Temperature [%1,f]" {mqtt="<[broker:openhab/temp:state:default]"}

Now, suppose I would like to know from another MQTT client the state of the sensor, i.e. I would read
the temperature value. Which kind of message I have to publish on the topic openhab/temp?

The item label should probably be "Temperature [%.1f]". On the topic openhab/temp on the broker broker, you would publish a message like “23.2” or “0.6” or “93”, etc. (without the quote marks). Note that additional formatting, like spaces before or after the number, is not allowed, unless you also replace default with a transform that strips them off.

Thank you watou.
Maybe there is something I am missing. The pub message is sent by the sensor, by means of some script or persistence binding.
Let’s say every minute. But if I am on a client which submitted to the sensor channel (openhab/temp), there is a way to know which is the current value of the sensor? Is it possible by using MQTT or shall I use other mechanism, like REST?

I am asking this because I am making a webpage which connects to the borker via WebSocket. And I would know the reading of the sensor by publishing some message on the channel, like “send temperature reading to the borker”.

Regards

I’m not 100% certain I understand your question, but I did implement something similar to what you describe in my setup. I have a topic that all my sensors subscribe to. When a message is published to that topic the sensors publish their current readings to their respective topics. I mainly use this to give OH a way to poll for their current state in a System started rule so OH’s internal state matches the current state of the real world after a restart.

I think you got precisely what I would like to do.
Now I did it by doing a nodejs script on the openhab hosting platform which listens on a specific channel to send REST request to Openhab and publish the results back to the broker.
It will be great if could show me the details of what you did: Did you write a script or somethingelse?
Regards

All of my sensors are currently running off of Raspberry Pis (GPIO, network, and BT dongles). The script I use is published here:

The openHAB Item and Rule for requesting an update is:

Item:

Switch T_Update "Request update from MQTT sensors" <network>
String N_D_Update { mqtt=">[mosquitto:entry_sensors/getUpdate:state:*:default]" }

Rule:

rule "Get update at startup"
when
    System started or
    Item T_Update received command
then
    logInfo("entry", "Requesting an update from the MQTT sensors")
    N_D_Update.postUpdate("update")
end

Another developer added code to use the REST API instead of MQTT but I haven’t looked to see if it supports this request for status update feature.