diff --git a/libraries/mqtt.xml b/libraries/mqtt.xml
index 78996d55..57f73e5c 100644
--- a/libraries/mqtt.xml
+++ b/libraries/mqtt.xml
@@ -1 +1 @@
-Connect to a broker
The options are not required but can be filled if needed
1. username (some brokers need this)
2. password (some brokers need this)
3. keepalive (default time is 60 seconds but some brokers need a shorter time)
4. connection callback (ringed set of scripts to be run when connection is made or remade)
Note: The connection callback doesn''t have to be the 4th option - it just has to be the last (or only) option.
ADVANCED: The brokers offered in the menu are accessed using default ports and basepaths (if needed). If accessing other brokers, the complete urls should be formed like this:
siteURL:port/basepath
e.g mqtt.eclipseprojects.io:443/mqtt
broker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netconnection statuscallbackconnection statusconnectingcallbackoptionsusername1password2keepalive3mqt_connect(broker,callback,options)connectingconnectedPublish a message to an MQTT broker
The options are not required but can be filled if needed
1. qos (quality of service 0,1 or 2)
2. retain flag (boolean)
broker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamehellooptionsqos1retain2mqt_pub(broker,topic,message,options)Subscribe to a topic on a broker
Make sure you have already run an MQTT connect block before using this one
You should add a script to be run inside he grey ring.
It will be run each time a message is received
If you click on the arrow on the grey ring twice, you can use #1 and #2 inside yoiru script.
#1 will contain the received message
#2 will contain the received topic namebroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamebroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameallall
broker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netbroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamereceived messagereceived topicbroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameidCallhelloreceived messagereceived topic/idCall-namehellobroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameidCallhelloreceived messagereceived topic/idCall-1
+Connect to a broker
The options are not required but can be filled if needed
1. username (some brokers need this)
2. password (some brokers need this)
3. keepalive (default time is 60 seconds but some brokers need a shorter time)
4. connection callback (ringed set of scripts to be run when connection is made or remade)
Note: The connection callback doesn''t have to be the 4th option - it just has to be the last (or only) option.
ADVANCED: The brokers offered in the menu are accessed using default ports and basepaths (if needed). If accessing other brokers, the complete urls should be formed like this:
siteURL:port/basepath
e.g mqtt.eclipseprojects.io:443/mqtt
broker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netconnection statuscallbackconnection statusconnectingcallbackoptionsusername1password2keepalive3mqt_connect(broker,callback,options)connectingconnectedPublish a message to an MQTT broker
The options are not required but can be filled if needed
1. qos (quality of service 0,1 or 2)
2. retain flag (boolean)
broker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamehellooptionsqos1retain2mqt_pub(broker,topic,payload,options)Subscribe to a topic on a broker
Make sure you have already run an MQTT connect block before using this one
You should add a script to be run inside he grey ring.
It will be run each time a message is received
If you click on the arrow on the grey ring twice, you can use #1 and #2 inside yoiru script.
#1 will contain the received message
#2 will contain the received topic namebroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamebroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameallall
broker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netbroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnamereceived messagereceived topicbroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameidCallhelloreceived payloadreceived topic/idCall-namehellobroker.emqx.iobroker.emqx.io
mqtt.eclipseprojects.io
test.mosquitto.org
broker.xmqtt.netnameidCallhelloreceived messagereceived topic/idCall-1
diff --git a/libraries/mqttExtension.js b/libraries/mqttExtension.js
index 7cde442e..73b15289 100644
--- a/libraries/mqttExtension.js
+++ b/libraries/mqttExtension.js
@@ -4,6 +4,7 @@
* Modified by Simon Walters
* and converted into an extension
* November 2021
+ * V1.1 - change back to using standard naming e.g payload not message
*/
@@ -68,6 +69,8 @@ SnapExtensions.primitives.set(
wsbroker = wsbroker + ':8084'
} else if (wsbroker == 'ws://simplesi.cloud') {
wsbroker = wsbroker + ':8083'
+ } else if (wsbroker == 'ws://localhost') {
+ wsbroker = wsbroker + ':9001'
}
//log(wsbroker)
try {
@@ -110,8 +113,8 @@ SnapExtensions.primitives.set(
SnapExtensions.primitives.set(
- 'mqt_pub(broker,topic,message,options)',
- function (broker,topic,message,options) {
+ 'mqt_pub(broker,topic,payload,options)',
+ function (broker,topic,payload,options) {
/* original code from github.com/pixavier/mqtt4snap */
/* adapted into extension by cymplecy 26Nov21 */
/* modified 5 Sep2021 by cymplecy to add parameters for qos and retain flag */
@@ -122,7 +125,7 @@ SnapExtensions.primitives.set(
broker = broker ? broker.trim() : broker;
topic = topic ? topic.trim() : topic;
//payload not trimmed as might have real leading/trailing spaces
- console.log(options)
+ //console.log(options)
options = JSON.parse(options);
const opts = {};
if (options['qos']) {
@@ -150,10 +153,10 @@ SnapExtensions.primitives.set(
try{
let client = stage.mqtt[broker];
- client.publish(topic, '' + message, opts);
- console.log(opts)
+ client.publish(topic, '' + payload, opts);
+ //console.log(opts)
} catch(e) {
- log('Failed to publish message ' + message);
+ log('Failed to publish payload ' + payload);
// console.log(e);
throw e;
}
@@ -293,3 +296,4 @@ SnapExtensions.primitives.set(
}
}
)
+