Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/mqtt.xml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "@prefix@/share/@PACKAGE_NAME@/@DTD@">
<tsung loglevel="debug" version="1.0">
<clients>
<client host="ubuntu" maxusers="5"></client>
</clients>

<servers>
<server host="127.0.0.1" port="5672" type="tcp" />
</servers>

<load>
<user session="mqtt_subscriber" start_time="10" unit="second"></user>
<arrivalphase phase="1" duration="3" unit="second">
<users maxnumber="1" arrivalrate="1" unit="second"/>
</arrivalphase>
</load>

<sessions>
<session name="mqtt_publisher" probability="100" type="ts_mqtt">
<request>
<mqtt type="connect" clean_start="true" keepalive="10" will_topic="will_topic" will_qos="0" will_msg="will_msg" will_retain="false"></mqtt>
</request>

<for from="1" to="10" incr="1" var="loops">
<request subst="true">
<mqtt type="publish" topic="test_topic" qos="1" retained="true">test_message</mqtt>
</request>
</for>

<request>
<mqtt type="disconnect"></mqtt>
</request>
</session>
<session name="mqtt_subscriber" probability="0" type="ts_mqtt">
<request>
<mqtt type="connect" clean_start="true" keepalive="10"></mqtt>
</request>

<request subst="true">
<mqtt type="subscribe" topic="test_topic" qos="1"></mqtt>
</request>

<request>
<!-- wait for 60s -->
<mqtt type="waitForMessages" timeout="60"></mqtt>
</request>

<request subst="true">
<mqtt type="unsubscribe" topic="test_topic"></mqtt>
</request>

<request>
<mqtt type="disconnect"></mqtt>
</request>
</session>
</sessions>
</tsung>
94 changes: 94 additions & 0 deletions include/mqtt.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
%% The MIT License (MIT)
%%
%% Copyright (c) <2013> <[email protected]>
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.
%%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.

%%
%% An erlang client for MQTT (http://www.mqtt.org/)
%%

-define(LOG(Msg), io:format("{~p:~p ~p}: ~p~n", [?MODULE, ?LINE, self(), Msg])).

-define(MQTT_PORT, 1883).

-define(PROTOCOL_NAME, "MQIsdp").
-define(PROTOCOL_VERSION, 3).

-define(UNUSED, 0).

-define(USERNAME, undefined).
-define(PASSWORD, undefined).

-define(DEFAULT_KEEPALIVE, 120).
-define(DEFAULT_RETRY, 120).
-define(DEFAULT_CONNECT_TIMEOUT, 5).

-define(CONNECT, 1).
-define(CONNACK, 2).
-define(PUBLISH, 3).
-define(PUBACK, 4).
-define(PUBREC, 5).
-define(PUBREL, 6).
-define(PUBCOMP, 7).
-define(SUBSCRIBE, 8).
-define(SUBACK, 9).
-define(UNSUBSCRIBE, 10).
-define(UNSUBACK, 11).
-define(PINGREQ, 12).
-define(PINGRESP, 13).
-define(DISCONNECT, 14).

-record(connect_options, {
protocol_name = ?PROTOCOL_NAME,
protocol_version = ?PROTOCOL_VERSION,
client_id,
clean_start = true,
will,
keepalive = ?DEFAULT_KEEPALIVE,
username = ?USERNAME,
password = ?PASSWORD,
retry = ?DEFAULT_RETRY,
connect_timeout = ?DEFAULT_CONNECT_TIMEOUT
}).

-record(mqtt, {
id,
type,
dup = 0,
qos = 0,
retain = 0,
arg
}).

-record(sub, {
topic,
qos = 0
}).

-record(publish_options, {
qos = 0,
retain = 0
}).

-record(will, {
topic,
message,
publish_options = #publish_options{}
}).
56 changes: 56 additions & 0 deletions include/ts_mqtt.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%%% This code was developped by Zhihui Jiao([email protected]).
%%%
%%% Copyright (C) 2013 Zhihui Jiao
%%%
%%% This program is free software; you can redistribute it and/or modify
%%% it under the terms of the GNU General Public License as published by
%%% the Free Software Foundation; either version 2 of the License, or
%%% (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%%% GNU General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
%%%
%%% In addition, as a special exception, you have the permission to
%%% link the code of this program with any library released under
%%% the EPL license and distribute linked combinations including
%%% the two; the MPL (Mozilla Public License), which EPL (Erlang
%%% Public License) is based on, is included in this exception.


-vc('$Id$ ').
-author('[email protected]').

%% use by the client to create the request
-record(mqtt_request, {
type,
clean_start = true,
keepalive = 10, % 10s
will_topic,
will_qos,
will_msg,
will_retain,
topic,
qos = 0,
retained = false,
payload
}).

-record(mqtt_dyndata, {
none
}
).

-record(mqtt_session, {
ack_buf = <<>>,
ping_pid,
keepalive,
curr_id = 0,
wait, % wait code
status % connection status
}).
Loading