Skip to main content

๐Ÿ“ก MQTT Channel

PicoClaw supports any MQTT client as a chat channel. Devices or services publish requests to a broker; PicoClaw subscribes, processes them, and publishes responses back.

๐Ÿš€ Quick Startโ€‹

1. Add the channel to ~/.picoclaw/config.json:

{
"channel_list": {
"mqtt": {
"enabled": true,
"type": "mqtt",
"settings": {
"broker": "tcp://localhost:1883",
"agent_id": "assistant"
}
}
}
}

2. Start the gateway:

picoclaw gateway

3. Send a message from any MQTT client:

mosquitto_pub -t "/picoclaw/assistant/device1/request" \
-m '{"text": "What is the CPU usage?"}'

4. Subscribe to receive the response:

mosquitto_sub -t "/picoclaw/assistant/device1/response"

๐Ÿ“จ Topic Structureโ€‹

{prefix}/{agent_id}/{client_id}/request # Client โ†’ PicoClaw
{prefix}/{agent_id}/{client_id}/response # PicoClaw โ†’ Client
SegmentDescription
prefixTopic prefix, configured server-side. Default: /picoclaw
agent_idPicoClaw instance identifier, set in agent_id config field
client_idClient-defined session identifier โ€” use a stable ID per device to maintain conversation context

Message Payload (JSON)โ€‹

{ "text": "your message here" }

โš™๏ธ Configurationโ€‹

config.jsonโ€‹

{
"channel_list": {
"mqtt": {
"enabled": true,
"type": "mqtt",
"settings": {
"broker": "ssl://your-broker:8883",
"agent_id": "assistant",
"topic_prefix": "/picoclaw",
"client_id": "",
"keep_alive": 60,
"qos": 0
}
}
}
}

.security.yml (credentials)โ€‹

Username and password are stored in ~/.picoclaw/.security.yml, not in config.json:

channel_list:
mqtt:
settings:
username: your_username
password: your_password

Configuration Fieldsโ€‹

FieldLocationRequiredDefaultDescription
brokersettingsYesโ€”MQTT broker URL, e.g. tcp://host:1883, ssl://host:8883
agent_idsettingsYesโ€”Agent identifier, used as part of the topic path
topic_prefixsettingsNo/picoclawTopic namespace prefix
username.security.ymlNoโ€”Broker authentication username
password.security.ymlNoโ€”Broker authentication password
client_idsettingsNoauto-generatedPaho client ID sent to the broker. Auto-generated as picoclaw-mqtt-{agent_id}-{8-char hex} if not set; stays fixed for the process lifetime so reconnects reuse the same ID
keep_alivesettingsNo60MQTT keepalive interval in seconds
qossettingsNo0QoS level for publish and subscribe: 0, 1, or 2
tls_insecure_skip_verifysettingsNofalseSkip TLS certificate verification. Only enable for brokers with self-signed certificates on trusted networks

Environment Variablesโ€‹

All fields can be set via environment variables:

VariableField
PICOCLAW_CHANNELS_MQTT_BROKERbroker
PICOCLAW_CHANNELS_MQTT_AGENT_IDagent_id
PICOCLAW_CHANNELS_MQTT_TOPIC_PREFIXtopic_prefix
PICOCLAW_CHANNELS_MQTT_USERNAMEusername
PICOCLAW_CHANNELS_MQTT_PASSWORDpassword
PICOCLAW_CHANNELS_MQTT_CLIENT_IDclient_id
PICOCLAW_CHANNELS_MQTT_KEEP_ALIVEkeep_alive
PICOCLAW_CHANNELS_MQTT_QOSqos
PICOCLAW_CHANNELS_MQTT_TLS_INSECURE_SKIP_VERIFYtls_insecure_skip_verify

๐Ÿ”„ Reconnectionโ€‹

PicoClaw automatically reconnects to the broker if the connection is lost, with a 5-second retry interval. On reconnect, the subscription is re-established automatically. The broker-side client ID stays the same across reconnects so the broker correctly identifies it as the same session.


โš ๏ธ Notesโ€‹

  • TLS: SSL/TLS is supported (ssl:// broker URL). Certificate verification is performed by default; set tls_insecure_skip_verify: true only for brokers with self-signed certificates on trusted networks.
  • Streaming: Streaming responses send multiple messages to the response topic; concatenate them in order.
  • client_id vs session ID: The client_id in the topic path is set by your client application and identifies the conversation session. It is separate from the broker-level client ID used by PicoClaw's paho connection.
  • Multiple instances: If you run multiple PicoClaw instances against the same broker with the same agent_id, set distinct client_id values to avoid broker-level conflicts.