This module implements the viam-labs pubsub API in a viam-labs:service:mqtt-grpc model. With this service, you can interact with MQTT brokers to publish and subscribe to topics in your Viam projects.
Typically, you would need to have an MQTT broker like Mosquitto or EMQ X running somewhere that is reachable by this module over the network.
In some use-cases, you might use this module for inter-process communication locally. In those scenarios, you can set the local_mosquitto attribute to true and the module will attempt to install mosquitto locally and interface with it.
To use this module, follow these instructions to add a module from the Viam Registry and select the viam-labs:pubsub:viam-labs:service:mqtt-grpc
model from the viam-labs:service:mqtt-grpc
module.
Note
Before configuring your mqtt-grpc service, you must create a machine.
Navigate to the Config tab of your robot’s page in the Viam app.
Click on the Services subtab and click Create service.
Select the pubsub
type, then select the viam-labs:service:mqtt-grpc
model.
Enter a name for your pubsub and click Create.
On the new component panel, copy and paste the following attribute template into your pubsub’s Attributes box:
{
"broker": "my.mqtt.broker",
"port": 1883,
"username": "username_if_required",
"password": "password_if_required"
}
Note
For more information, see Configure a Robot.
The following attributes are available for viam-labs:pubsub:viam-labs:service:mqtt-grpc
pubsubs:
Name | Type | Inclusion | Description |
---|---|---|---|
broker |
string | Required | Address of MQTT broker, required unless local_mosquitto is set to true |
port |
int | Optional | MQTT broker port, defaults to 1883 |
mqtt_version |
int | Optional | MQTT protocol version, defaults to 3 |
mqtt_transport |
string | Optional | MQTT transport (tcp or websockets), defaults to tcp |
username |
string | Optional | mqtt broker username |
password |
string | Optional | mqtt broker password |
local_mosquitto |
boolean | Optional | Defaults to false, if true will attempt to install and use a local mosquitto instance |
A typical configuration might look like:
{
"broker": "192.168.0.140",
"port": 1883,
"username": "mqttclient",
"password": "mysupers3cur3Password!"
}
To interact with the your configured service with Viam SDKs, see the viam-labs pubsub API documentation.
- TLS is not currently supported.