MQTT Client
With MQTT Client, you can distribute and subscribe MQTT messages from text files within Visual Studio Code.
Usage
Write the following blocks in a file with the extension .mqtt
.
Each block starts on a line beginning with a unique string that starts with #
. The line beginning the block must not contain any additional characters, including spaces.
Broker connection block
Write connection information to the block that starts with # %%
to connect to the broker.
Click Connect
displayed above # %%
to connect to the server.
Name |
Required |
Default |
Description |
url |
✓ |
|
URL of MQTT broker |
user |
|
|
User ID |
password |
|
|
Password Please be careful as it is saved in plain text in the file. |
clientId |
|
"mqtt_vsc_" + 10 random digits |
Client ID |
Example
# %%
url: mqtt://broker:1883
user: user
password: password
Subscription block
Write one topic to subscribe per line in a block that starts with # $$
.
Click Subscribe all
or Subscribe
displayed above or next to # $$
to open a subscription tab and start subscribing.
Example
# $$
foo
bar/#
Publication block
Write a block starting with # ##
for each message you want to distribute.
Write the distribution target topic setting and leave a blank line before writing the message payload.
You cannot include the same line as the block starting line with # %%
or other blocks in the message payload. It will be considered the start of another block.
Click Publish Message
displayed above # ##
to distribute the message.
Name |
Required |
Default |
Description |
topic |
✓ |
|
Distribution destination topic |
qos |
|
0 |
QoS 0, 1, or 2 |
retain |
|
false |
Retain flag true/false |
Example
# ## Publish 'message'
topic: foo
qos: 0
retain: false
message
# ## Publish '{ "message": "hello" }'
topic: bar
qos: 1
retain: true
{
"message": "hello"
}
Variables
You can define variables that can be referenced in various places.
Write one variable per line in the file, in the form of name
=
value
, above all the above blocks.
To reference a variable, enclose the variable name in {{
}}
. If the variable is not defined, treat it as a string. If you want to use the string enclosed in {{
}}
, which refers to a variable that has already been defined, enclose it again with {{
}}
.
The places where variables can be referenced are as follows:
- Value part of the variable definition
You can only reference variables defined above.
- Value part of the setting in the form of
key
:
value
- Topic specification part of a Subscription block
- Message payload part of a Publication block
Example
host=broker
TopicLevel1=foo
TOPIC_FOO={{TopicLevel1}}/foo
message=Hello, world!
# %%
url: http://{{host}}:1883
# $$
{{TopicLevel1}}/#
# ## Publish '{ "message": "Hello, world!" }'
topic: {{TopicLevel1}}/bar
{
"message": "{{message}}"
}
# ## Publish '{{message}}'
topic: {{TOPIC_FOO}}
{{{{message}}}}
Descriptions that do not follow the rules of each block are ignored and do not affect the operation. They can be used as comments.
You cannot write comments in the message payload part of Subscription blocks or Publication blocks.
Example
comment
host=broker
comment
message=Hello, world!
# %%
comment
url: http://{{host}}:1883
comment
# $$
{{TopicLevel1}}/#
# ##
comment
topic: {{TopicLevel1}}/bar
comment
{
"message": "{{message}}"
}
not a comment
Settings
Key |
Default |
Description |
mqttclient.subscription.show.retain |
false |
Show if the message is retained in the subscription window. |
ThirdParty Notices
MQTT.js
Copyright (c) 2015-2016 MQTT.js contributors
Released under the MIT license
https://github.com/mqttjs/MQTT.js/blob/main/LICENSE.md
wait-queue
Copyright (c) 2017 flarestart
Released under the MIT license
https://github.com/flarestart/wait-queue/blob/master/LICENSE