Skip to main content

MQTT

The MQTT component handles configuration and status of the outbound MQTT connection. Here, you can find how to configure your device to connect to an MQTT server. More about the MQTT channel itself, as well as information about the topics available can be found here. This component supports the following methods:

Mqtt.GetStatus#

This method returns the status of the component instance.

Request#

This method takes no parameters.

http://192.168.33.1/rpc/Mqtt.GetStatus

Response#

Attributes in the result:

  • connected: boolean, true if the device is MQTT connected, false otherwise
{
"connected": false
}

Mqtt.GetConfig#

This method returns the configuration of the component instance.

Request#

This method takes no parameters.

http://192.168.33.1/rpc/Mqtt.GetConfig

Response#

Attributes in the result:

  • enable: boolean, true if MQTT connection is enabled, false otherwise
  • server: string or null, name of the server to which the device is connected
  • user: string or null, username
  • pass: string or null, password
  • ssl_ca: string or null, type of the TCP socket
    • null - plain TCP connection
    • * - TLS with disabled certificate validation
    • "user_ca.pem" - TLS connection verified by the user-provided CA, see Shelly.PutUserCA
    • "ca.pem" - TLS connection verified by the built-in CA bundle
  • topic_prefix: string or null, prefix of the topics on which device publish/subscribe. Limited to 300 characters. Could not start with $ and #, +, %, ? are not allowed.
    • null - device id is used as topic prefix
  • rpc_ntf: boolean, if true notifications are published on <device_id|topic_prefix>/events/rpc, false disables publishing. Default true.
  • status_ntf: boolean, if true notifications are published on <device_id|topic_prefix>/status/<component:[id]>, false disables publishing. Default false.
{
"enable": false,
"server": null,
"user": null,
"pass": null,
"ssl_ca": null,
"topic_prefix": null,
"rpc_ntf": true,
"status_ntf": false
}

Mqtt.SetConfig#

This method makes changes in the configuration of the component instance.

Request#

  • config: JSON object, configuration to be applied. This object should be identical in structure to the JSON returned by Eth.GetConfig, containing only the keys that need to be modified. Required
Set username for MQTT user to user_1.
curl -X POST -d '{"id":1, "src":"user_1", "method":"Mqtt.SetConfig",
"params":{"config":{"user":"user_1"}}}' http://${SHELLY}/rpc

Response#

Attributes in the result:

  • restart_required: boolean, true if restart is required to apply the changes, false otherwise.
{
"id": 1,
"src": "shellypro4pm-f008d1d8b8b8",
"dst": "user_1",
"result": {
"restart_required": true
}
}