Mercurial > prosody-modules
annotate mod_pubsub_mqtt/mod_pubsub_mqtt.lua @ 5834:866a49f5aa61
mod_firewall: Fix to find scripts when installed with plugin installer
Extra resources are stored in a different path by luarocks, not
alongside the code as this code assumed.
Thanks eTaurus
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 11 Feb 2024 12:50:53 +0100 |
parents | 58df53eefa28 |
children |
rev | line source |
---|---|
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 module:set_global(); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local mqtt = module:require "mqtt"; |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
4 local id = require "util.id"; |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
7 local function tostring_content(item) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
8 return tostring(item[1]); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
9 end |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
10 |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
11 local data_translators = setmetatable({ |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
12 utf8 = { |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
13 from_item = function (item) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
14 return item:find("{https://prosody.im/protocol/data}data#"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
15 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
16 to_item = function (payload) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
17 return st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = id.medium() }) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
18 :text_tag("data", payload, { xmlns = "https://prosody.im/protocol/data" }) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
19 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
20 }; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
21 json = { |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
22 from_item = function (item) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
23 return item:find("{urn:xmpp:json:0}json#"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
24 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
25 to_item = function (payload) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
26 return st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = id.medium() }) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
27 :text_tag("json", payload, { xmlns = "urn:xmpp:json:0" }); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
28 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
29 }; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
30 atom_title = { |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
31 from_item = function (item) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
32 return item:find("{http://www.w3.org/2005/Atom}entry/title#"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
33 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
34 to_item = function (payload) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
35 return st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = id.medium() }) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
36 :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
37 :text_tag("title", payload, { type = "text" }); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
38 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
39 }; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
40 }, { |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
41 __index = function () return { from_item = tostring }; end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
42 }); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
43 |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 local pubsub_services = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 local pubsub_subscribers = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local packet_handlers = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 function handle_packet(session, packet) |
5112
9499b88f3453
mod_pubsub_mqtt: Fix some inappropriate log levels
Matthew Wild <mwild1@gmail.com>
parents:
5111
diff
changeset
|
49 module:log("debug", "MQTT packet received! Length: %d", packet.length); |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 for k,v in pairs(packet) do |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 module:log("debug", "MQTT %s: %s", tostring(k), tostring(v)); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 local handler = packet_handlers[packet.type]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 if not handler then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 module:log("warn", "Unhandled command: %s", tostring(packet.type)); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 return; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 handler(session, packet); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 function packet_handlers.connect(session, packet) |
5833
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
62 module:log("info", "MQTT client connected (sending connack)"); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
63 module:log("debug", "MQTT version: %02x", packet.version); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
64 if packet.version ~= 0x04 then -- Version mismatch |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
65 session.conn:write(mqtt.serialize_packet{ |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
66 type = "connack"; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
67 data = string.char(0x00, 0x01); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
68 }); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
69 return; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
70 end |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 session.conn:write(mqtt.serialize_packet{ |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 type = "connack"; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 data = string.char(0x00, 0x00); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 }); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 function packet_handlers.disconnect(session, packet) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 session.conn:close(); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 function packet_handlers.publish(session, packet) |
5112
9499b88f3453
mod_pubsub_mqtt: Fix some inappropriate log levels
Matthew Wild <mwild1@gmail.com>
parents:
5111
diff
changeset
|
82 module:log("info", "PUBLISH to %s", packet.topic); |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
83 local host, payload_type, node = packet.topic:match("^([^/]+)/([^/]+)/(.+)$"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
84 if not host then |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
85 module:log("warn", "Invalid topic format - expected: HOST/TYPE/NODE"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
86 return; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
87 end |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 local pubsub = pubsub_services[host]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 if not pubsub then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 module:log("warn", "Unable to locate host/node: %s", packet.topic); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 return; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 end |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
93 |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
94 local payload_translator = data_translators[payload_type]; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
95 if not payload_translator or not payload_translator.to_item then |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
96 module:log("warn", "Unsupported payload type '%s' on topic '%s'", payload_type, packet.topic); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
97 return; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
98 end |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
99 |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
100 local payload_item = payload_translator.to_item(packet.data); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
101 local ok, err = pubsub:publish(node, true, payload_item.attr.id, payload_item); |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 if not ok then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 module:log("warn", "Error publishing MQTT data: %s", tostring(err)); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 function packet_handlers.subscribe(session, packet) |
5833
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
108 local results = {}; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
109 for i, topic in ipairs(packet.topics) do |
5112
9499b88f3453
mod_pubsub_mqtt: Fix some inappropriate log levels
Matthew Wild <mwild1@gmail.com>
parents:
5111
diff
changeset
|
110 module:log("info", "SUBSCRIBE to %s", topic); |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
111 local host, payload_type, node = topic:match("^([^/]+)/([^/]+)/(.+)$"); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
112 if not host then |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
113 module:log("warn", "Invalid topic format - expected: HOST/TYPE/NODE"); |
5833
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
114 results[i] = 0x80; -- Failure |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
115 else |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
116 local pubsub = pubsub_subscribers[host]; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
117 if not pubsub then |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
118 module:log("warn", "Unable to locate host/node: %s", topic); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
119 results[i] = 0x80; -- Failure |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
120 else |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
121 local node_subs = pubsub[node]; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
122 if not node_subs then |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
123 node_subs = {}; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
124 pubsub[node] = node_subs; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
125 end |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
126 session.subscriptions[topic] = payload_type; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
127 node_subs[session] = payload_type; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
128 module:log("debug", "Successfully subscribed to %s", topic); |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
129 results[i] = 0x00; -- Success |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
130 end |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 end |
5833
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
133 local ack = mqtt.serialize_packet{ type = "suback", id = packet.id, results = results }; |
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
134 session.conn:write(ack); |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 function packet_handlers.pingreq(session, packet) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 session.conn:write(mqtt.serialize_packet{type = "pingresp"}); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 local sessions = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 local mqtt_listener = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 function mqtt_listener.onconnect(conn) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 sessions[conn] = { |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 conn = conn; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 stream = mqtt.new_stream(); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 subscriptions = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 }; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 function mqtt_listener.onincoming(conn, data) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 local session = sessions[conn]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 if session then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 local packets = session.stream:feed(data); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 for i = 1, #packets do |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 handle_packet(session, packets[i]); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 function mqtt_listener.ondisconnect(conn) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 local session = sessions[conn]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 for topic in pairs(session.subscriptions) do |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 local host, node = topic:match("^([^/]+)/(.+)$"); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 local subs = pubsub_subscribers[host]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 if subs then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 local node_subs = subs[node]; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 if node_subs then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 node_subs[session] = nil; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 sessions[conn] = nil; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 module:log("debug", "MQTT client disconnected"); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 module:provides("net", { |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 default_port = 1883; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 listener = mqtt_listener; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 }); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 |
5831
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
184 module:provides("net", { |
5832
5afc8273c5ef
mod_pubsub_mqtt: Fix syntax error
Matthew Wild <mwild1@gmail.com>
parents:
5831
diff
changeset
|
185 name = "pubsub_mqtt_tls"; |
5831
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
186 encryption = "ssl"; |
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
187 default_port = 8883; |
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
188 listener = mqtt_listener; |
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
189 }); |
801f64e6d4e9
mod_pubsub_mqtt: Add TLS port (default 8883) for MQTT connections
Matthew Wild <mwild1@gmail.com>
parents:
5113
diff
changeset
|
190 |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 function module.add_host(module) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 local pubsub_module = hosts[module.host].modules.pubsub |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 if pubsub_module then |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 module:log("debug", "MQTT enabled for %s", module.host); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 module:depends("pubsub"); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 pubsub_services[module.host] = assert(pubsub_module.service); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 local subscribers = {}; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 pubsub_subscribers[module.host] = subscribers; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 local function handle_publish(event) |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 -- Build MQTT packet |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
201 local packet_types = setmetatable({}, { |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
202 __index = function (self, payload_type) |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
203 local packet = mqtt.serialize_packet{ |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
204 type = "publish"; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
205 id = "\000\000"; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
206 topic = module.host.."/"..payload_type.."/"..event.node; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
207 data = data_translators[payload_type].from_item(event.item) or ""; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
208 }; |
5833
58df53eefa28
mod_pubsub_mqtt: Update to MQTT 3.1.1
Matthew Wild <mwild1@gmail.com>
parents:
5832
diff
changeset
|
209 rawset(self, payload_type, packet); |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
210 return packet; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
211 end; |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
212 }); |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 -- Broadcast to subscribers |
5113
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
214 module:log("debug", "Broadcasting PUBLISH to subscribers of %s/*/%s", module.host, event.node); |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
215 for session, payload_type in pairs(subscribers[event.node] or {}) do |
85a7304cfea1
mod_pubsub_mqtt: Support atom_title payload type
Matthew Wild <mwild1@gmail.com>
parents:
5112
diff
changeset
|
216 session.conn:write(packet_types[payload_type]); |
1240
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 module:log("debug", "Sent to %s", tostring(session)); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 pubsub_services[module.host].events.add_handler("item-published", handle_publish); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 function module.unload() |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 module:log("debug", "MQTT disabled for %s", module.host); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 pubsub_module.service.remove_handler("item-published", handle_publish); |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 pubsub_services[module.host] = nil; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 pubsub_subscribers[module.host] = nil; |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 end |
e0d97eb52ab8
mod_pubsub_mqtt: MQTT (a lightweight binary pubsub protocol) interface for mod_pubsub
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 end |