Erlang MQTT-SN Gateway
Erlang Makefile
Latest commit dac865f Jan 20, 2017 @emqplus emqplus committed on GitHub Merge pull request #10 from emqtt/emq20
Version 0.2.7
Permalink
Failed to load latest commit information.
etc emq_sn Oct 13, 2016
examples upgrade emqtt-sn gateway code Nov 19, 2016
include add cuttlefish config Oct 7, 2016
priv emq_sn_* Oct 14, 2016
src Copyright (c) 2016-2017 Jan 11, 2017
test Copyright (c) 2016-2017 Jan 11, 2017
.gitignore emq_sn Oct 9, 2016
LICENSE Initial commit Jun 27, 2016
Makefile Version 0.2.7 Jan 20, 2017
README.md Packet Nov 19, 2016
erlang.mk first commit Jun 27, 2016

README.md

emq_sn

MQTT-SN Gateway for The EMQ Broker

Configure Plugin

File: etc/emq_sn.conf

mqtt.sn.port = 1884

Usage

simple

examples/simple_example.erl

%% create udp socket
{ok, Socket} = gen_udp:open(0, [binary]),

%% connect to broker
Packet = gen_connect_package(ClientId),
ok = gen_udp:send(Socket, ?HOST, ?PORT, Packet),

%% register topic_id
RegisterPacket = gen_register_package(<<"TopicA">>, 1),
ok = gen_udp:send(Socket, ?HOST, ?PORT, RegisterPacket),

%% subscribe
SubscribePacket = gen_subscribe_package(1),
ok = gen_udp:send(Socket, ?HOST, ?PORT, SubscribePacket),

%% publish
PublishPacket = gen_publish_package(1, <<"Payload...">>),
ok = gen_udp:send(Socket, ?HOST, ?PORT, PublishPacket),

%% receive message
receive
    {udp, Socket, _, _, Bin} ->
        case Bin of
            <<_Len:8, ?SN_PUBLISH, _:1, _Flag:8, TopicId:16, MsgId:16, Data/binary>> ->
                io:format("recv publish Qos: ~p, TopicId: ~p, MsgId: ~p, Data: ~p~n", [Qos, TopicId, MsgId, Data]);
            _ ->
                ok
        end
after
    1000 ->
        io:format("Error: receive timeout!~n")
end,

%% disconnect from broker
DisConnectPacket = gen_disconnect_package(),
ok = gen_udp:send(Socket, ?HOST, ?PORT, DisConnectPacket).

Load Plugin

./bin/emqttd_ctl plugins load emq_sn

License

Apache License Version 2.0

Author

Feng Lee feng@emqtt.io