Skip to content

Commit b059379

Browse files
Update README with instructions on how to set up MQTT broker
Signed-off-by: Kate Goldenring <[email protected]>
1 parent 8b2ea88 commit b059379

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,48 @@ To inject the Spin variable using environment variables:
6767
SPIN_VARIABLE_PASSWORD=password spin up
6868
```
6969

70+
To skip authentication, set the `username` and `password` fields to empty strings:
71+
72+
```toml
73+
[application.trigger.mqtt]
74+
address = "mqtt://localhost:1883"
75+
username = "admin"
76+
password = "public"
77+
keep_alive_interval = "30"
78+
```
79+
7080
## State of Play
7181

7282
1. Authenticates using anonymous and username/password to MQTT server.
7383
2. Receive messages from an MQTT topic per configured QoS.
7484

7585
[more MQTT client/subscription attributes will be available soon]
7686

87+
## Running an MQTT Broker
88+
89+
Download [MQTTX CLI](https://github.com/emqx/MQTTX/tree/main/cli)
90+
91+
```sh
92+
brew install emqx/mqttx/mqttx-cli
93+
```
94+
95+
Run the EMQX broker: https://mqttx.app/docs/get-started
96+
97+
```sh
98+
docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx
99+
```
100+
101+
The default username and password of the broker is `admin` and `public`.
102+
103+
> Alternatively, use [Mosquitto's public MQTT broker](https://test.mosquitto.org/) without authentication by setting the broker hostname to `test.mosquitto.org`.
104+
77105
## Dev Loop [Build and Install from Source]
78106

107+
For this simple dev loop, make sure you have access to an MQTT broker. The following steps assume you followed the section to [run an MQTT broker locally](#running-an-mqtt-broker).
108+
79109
* Open the repo in Dev Container or in pre-configured GitHub [Codespace](https://codespaces.new/spinkube/spin-trigger-mqtt)
80110
* Run ```make``` to build and install the plugin locally.
81111
* Update ```examples/mqtt-app/spin.toml``` to reflect your MQTT server details and ensure it's accessible on the network.
82112
* Run ```spin build --up --from examples/mqtt-app/spin.toml``` to run the example Spin app.
83-
* Run ```mqttx pub -t 'messages-in01' -h '<mqtt server ip>' -p 1883 -u <user> -P <password> -m 'Hello to MQTT Spin Component!'``` with the hostname and credentials for your server, to publish the message which is then received by Spin app.
113+
* Run ```mqttx pub -t 'messages-in01' -h 'localhost' -p 1883 -u 'admin' -P 'public' -m 'Hello to MQTT Spin Component!'``` with the hostname and credentials for your server, to publish the message which is then received by Spin app.
84114
* Optionally, run ```make clean``` to clean up and rebuild and install the plugin locally.

examples/mqtt-app/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = ["Suneet Nangia <[email protected]>"]
88

99
[application.trigger.mqtt]
1010
address = "mqtt://localhost:1883"
11-
username = "user"
11+
username = "admin"
1212
password = "password"
1313
keep_alive_interval = "30"
1414

0 commit comments

Comments
 (0)