11![ mqtt-elements] ( https://raw.githubusercontent.com/mqttjs/mqtt-elements/67266290fe6a0b6b3ff51418efb7c1c0662c78c5/assets/mqtt-elements.png )
22=======
33
4- Polymer elements to establish a MQTT connection to an MQTT broker.
4+ Polymer elements to establish a MQTT connection to a MQTT broker.
55
66## API
77
@@ -10,7 +10,7 @@ Polymer elements to establish a MQTT connection to an MQTT broker.
1010## Install
1111
1212```
13- bower install --save mqttjs/ mqtt-elements
13+ bower install --save mqtt-elements
1414```
1515
1616## Import
@@ -22,7 +22,7 @@ bower install --save mqttjs/mqtt-elements
2222## Usage
2323
2424```
25- <mqtt-connection auto url="ws://127.0.0.1:3005 ">
25+ <mqtt-connection auto url="ws://HOST:PORT ">
2626 <mqtt-subscription
2727 topic="foo/bar"
2828 number-of-messages="Infinity"
@@ -38,6 +38,101 @@ bower install --save mqttjs/mqtt-elements
3838 </mqtt-connection>
3939```
4040
41+ ### Connect
42+
43+ ```
44+ <mqtt-connection url="ws://HOST:PORT"></mqtt-connection>
45+ ```
46+
47+ The method ` <mqtt-connection>#connect ` has to be called manually to establish the MQTT connection to the MQTT broker.
48+ Set ` <mqtt-connection>#auto ` flag to make the MQTT connection as soon as possible.
49+
50+
51+ ### Connect with Username / Password
52+
53+ ```
54+ <mqtt-connection
55+ url="ws://HOST:PORT"
56+ options='{"username": "USERNAME", "password": "PASSWORD"}'
57+ with-credentials
58+ auto>
59+ </mqtt-connection>
60+ ```
61+
62+ OR
63+
64+ ```
65+ <mqtt-connection
66+ url="ws://HOST:PORT"
67+ username="USERNAME"
68+ password="PASSWORD"
69+ with-credentials
70+ auto>
71+ </mqtt-connection>
72+ ```
73+
74+ The flag ` <mqtt-connection>#withCredentials ` indecates the MQTT connection to wait until a username and password for
75+ the connection is supplied.
76+
77+ ### Publish
78+
79+ The following example will publish on the topic »mqtt/elements« with the payload »Publishing via a HTML element«.
80+ Every time when ` <mqtt-publish>#payload ` changes the element will publish a new MQTT message to the topic »mqtt/elements«.
81+ If the ` <mqtt-publish>#auto ` flag is not set - ` <mqtt-publish>#publish ` has to be called to publish a MQTT message to the topic
82+
83+ ```
84+ <mqtt-connection
85+ url="ws://HOST:PORT"
86+ auto>
87+ <mqtt-publish topic="mqtt/elements" payload="Publishing via a HTML element" auto></mqtt-publish>
88+ </mqtt-connection>
89+ ```
90+
91+ #### Publish on multiple topic
92+
93+ A ` <mqtt-connection> ` element can hold any number of ` <mqtt-publish> ` elements to publish to different topics.
94+
95+ ```
96+ <mqtt-connection
97+ url="ws://HOST:PORT"
98+ auto>
99+ <mqtt-publish topic="foo/bar" payload="this is easy" auto></mqtt-publish>
100+ <mqtt-publish topic="client/status" payload="online" qos="1" auto></mqtt-publish>
101+ <mqtt-publish topic="client/location" payload="{'foo': 'bar'}" auto></mqtt-publish>
102+ </mqtt-connection>
103+ ```
104+
105+ #### Publish a retained message
106+
107+ To publish a message with the RETAINED flag set to true add the ` <mqtt-publish>#retained ` flag.
108+
109+ ```
110+ <mqtt-connection
111+ url="ws://HOST:PORT"
112+ auto>
113+ <mqtt-publish topic="foo/bar" payload="this is easy" retained auto></mqtt-publish>
114+ </mqtt-connection>
115+ ```
116+
117+ ### Subscribe
118+
119+ ```
120+ <mqtt-connection
121+ url="ws://HOST:PORT"
122+ auto>
123+ <mqtt-subscription topic="foo/bar"></mqtt-subscription>
124+ </mqtt-connection>
125+ ```
126+
127+ The last message to the topic will be save in ` <mqtt-subscription>#lastMessage ` . The ` <mqtt-subscription> ` stores the
128+ last ` n ` messages within the ` <mqtt-subscription>#messages ` array. Set ` <mqtt-subscription>#numberOfMessages ` to the
129+ number of messages that should be saved in ` <mqtt-subscription>#messages ` . To save every message received on the topic
130+ set ` <mqtt-subscription>#numberOfMessages ` to ` Infinity ` .
131+
132+ ## Media
133+
134+ * [ MQTT Client Library Encyclopedia] ( http://www.hivemq.com/blog/mqtt-client-library-encyclopedia-mqttelements?utm_medium=social&utm_source=github-mqttjs )
135+
41136## Development
42137
43138```
@@ -51,15 +146,10 @@ grunt serve
51146```
52147
53148
54- #### Update annd bundel MQTT.js
149+ #### Bundel MQTT.js, MQEmitter and Store
55150
56151```
57- browserify node_modules/mqtt/mqtt .js -o dist/mqtt.js
152+ browserify -r ./ node_modules/mqtt/lib/store .js:Store -r mqtt -r MQEmitter > dist/mqtt-elements-bundle .js
58153
59154```
60155
61- #### Update and bundel mqemitter
62- ```
63- browserify node_modules/mqemitter/mqemitter.js --standalone MQEmitter -o dist/mqemitter.js
64-
65- ```
0 commit comments