Handling MQTT communication inside HTTP request in Node-Red

心不动则不痛 提交于 2019-12-08 14:07:25

This is somewhat breaking the asynchronous nature of MQTT, while Pub/Sub can be used it's not it's strong point.

You have to consider what happens if there is no response message, since there is no way to know if the other MQTT client is connected.

Where is the HTTP request coming from? If it's from a web page then you could use MQTT over Websockets to make the request directly or plain Websockets , removing the need for the HTTP call all together.

Having said that you should be able to store the msg object in the context, there is no need to convert it to a string as the default context storage engine is just a in memory object store. So just add object to the context and retrieve it when the response comes in.

You may be able to do something with the trigger node to deal with the time out issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!