EMQ-SQL: Published Messages from gateway not saved (MQTTfx publish + API post works fine)

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 :slight_smile:

Hi,
Glad that the tutorial helped :slight_smile:
But i don’t know basics of Erlang also , I just got only that patch working by asking question on stack overflow and debugging for a few days. If its a Erlang question then StackOverflow is the right place.

Mostly it will be QOS values mismatch, it has troubled me. And observe the data from both clients byte by byte, Or else it should be fine.
I am not sure if you can send comma in JSON fields. Check it once.

Thank you for your reply Ravi,

I have confirmed QOS (QOS 0 messages) topic subscribe is correct should i check somewhere else for a mismatch? Same QOS from MQTTfx saved fine though and messages are already acknowledged and published.

I have tried removing commas when i receive the message (and the $ in one of the attempts) with no luck unfortunately :confused: . (separate attempts below)

%%lists:delete($$,MessageStr),
%%lists:flatten(MessageStr), %%tried without flattening it as well
%%Segmented = string:tokens(MessageStr, “,”),
%%lists:flatten(Segmented),

%%IOMessageStr = io_lib:format("~w",[MessageStr]),
%%Segmented = lists:flatten(IOMessageStr),

I will try StackOverflow as well thank you for your time, will post back if i get it working :smiley:

Yes, stackoverflow is the place. I have no clue on erlang :slightly_smiling_face:
Please do update if you get it working