I have a HW config which consists of a Raspberry 3 (running the node-red and the mosquitto broker), and on the same network, I have an ESP8266, communicating via mqtt. To the ESP, there is a DHT11 temperature sensor attached. Now I faced a problem here. Until now, the ESP node measured the temp & humidity periodically (every 30 sec, let's say), published the value to the mosquitto, and the node-red mqtt subscribe node had put it into a local variable inside node-red. When a request by the user came via telegram, to get the temperature, simply these local variables had been sent back to the telegram.
Since the DH11 is quite slow sensor, during the measurement, it blocks the ESP to response to other (also user initiated) commands, like turning the lamp on or off.
So I tried to achieve that node-red gets the request via telegram that the user wants to have the temp&humidity values. This works. Then, node-red publishes via mqtt that we need a fresh value of them. This works too. Then, ESP is subscribed, so it is triggered to measure, this works, too. The ESP publishes the new values after its measurement, that's also OK. Then, back to the node-red flow, I could get the value via the mqtt subscribe node. The problem appears here: after the measurement is triggered, how to wait for the result before I run the mqtt subscribe node? The mqtt subscribe node and publish node have only input / output connector respectively, so they cannot be connected neither after each other, nor with a script node between them. If I could place a script node between them, maybe with some handshaking logic this could be done.
So is there a solution or best practice to publish an mqtt request, run some code to create the response then show the response for the user?