I want to convert an HTTP request to an MQTT request. Therefore, for this I received an HTTP request, which consists of information similar to the topic and the message for publication. I have to post the provided message in the provided topic.
I can post a message, but the problem is that I can provide the theme and payload of the function I used. Here is a snippet of code that I write to post:
Data = mochiweb_request:parse_post(Req),
{RegisterFun, PublishFun, SubscribeFun} = vmq_reg:direct_plugin_exports(http_to_mqtt),
Topic = get_value("topic", Data),
List_of_topics = string:tokens(Topic, "/"),
Lot = lists:map(fun(X) -> list_to_binary(X) end, List_of_topics),
Payload = list_to_binary(get_value("message", Data)),
error_logger:info_msg("Topics: ~p~nPayload: ~p",[Lot, Payload]),
PublishFun(Lot,Payload),
Req:ok({"text/html", [], "<p>Thank you. <p>"})
Here, PublishFun, which I get from vmq_reg, can only allow the subject and message. Is there any other way to post a message giving the meaning of Qos, Retain and Dup.
I create a server using mochiweb and use it as a plugin in vernemq.
source
share