Hello Ruvi
Thank you for your tutorial on EMQTT & SQL it was really helpful!
I have had an issue though where:
When I post through HTTP API the log is saved fine into SQL fine.
When I connect to the broker and publish using MQTTfx to the topic it gets saved fine into SQL as well.
When my beacon scanner gateway publishes to the topic the published messages aren’t logged into the SQL, but I can see them all well (subscribed with MQTTfx & also the vast majority is retained fine from what i can see in EMQ dashboad).
Plugin compiles with no errors,EMQ restarted, plugin enabled on the board and it runs smoothly. I am also subscribed to the correct topic of course.
DB is really simple just one field in the table which can be null and it’s just a string (null allowed):
on_message_publish(Message, _Env) ->
io:format(“publish ~s~n”, [emqttd_message:format(Message)]),MessageBin = element(12, Message),
MessageStr = binary_to_list(MessageBin),
inets:start(),
Method = post,
URL = “———“,
Header = [{“X-DreamFactory-Api-Key”, “———"}],
Type = “application/json”,
Body = “{“resource”:[{“TagRAW”:”" ++ MessageStr ++ “”}]}",
HTTPOptions = [],
Options = [],
R = httpc:request(Method, {URL, Header, Type, Body},HTTPOptions,Options),
{ok, Message}.
An example of the gateway’s MessageStr (and as received on the broker) which is saved fine from MQTTfx publish/inside json form Postman:
$GPRP,7150668DC5FF,ED16CDFC3FFC,-54,02010613FF4C000C0E0082D8A80EFD6EAD1E9A1B132BE1,1536581626
Thank you again for your tutorial and any help