MQTT RPC icon

MQTT RPC

Push messages to MQTT and receive results with MQTT RPC

Overview

This node allows you to publish messages to an MQTT topic and receive responses using the MQTT RPC (Remote Procedure Call) pattern. It is useful for scenarios where you need to send a request to an MQTT-enabled device or service and wait for a response, such as querying IoT devices, triggering remote actions, or integrating with systems that communicate over MQTT.

Practical examples:

  • Sending a command to a smart home device and waiting for its status update.
  • Requesting sensor data from an IoT gateway and processing the result in n8n.
  • Orchestrating workflows that require synchronous communication with MQTT services.

Properties

Name Meaning
Topic The topic to publish to. This is the MQTT topic where your message will be sent.
Send Input Data Whether to send the data the node receives as JSON. If enabled, the incoming data is sent; if disabled, you must provide a custom message.
Message The message to publish. Only shown if "Send Input Data" is disabled. You can enter any string to be sent as the message payload.
Options Additional options for publishing:
- QoS: Quality of Service level. Options: Received at Most Once (0), Received at Least Once (1), Exactly Once (2).
- Retain: Whether to retain the last message.

Output

The node outputs an array of objects, each with the following structure:

{
  "json": {
    "topic": "<response_topic>",
    "message": "<response_message_as_string>"
  }
}
  • topic: The MQTT topic on which the response was received.
  • message: The content of the response message as a string.

Note: The node does not output binary data.

Dependencies

  • External Service: Requires access to an MQTT broker.
  • Credentials: Needs MQTT credentials configured in n8n under the name mqttrpcApi. These may include host, port, username, password, SSL certificates, etc.
  • n8n Configuration: Ensure the MQTT credential type is set up and tested.

Troubleshooting

Common Issues:

  • Connection Errors: If the node cannot connect to the MQTT broker, check your credentials, network connectivity, and broker availability.
  • Timeouts: If no response is received within 5 seconds, the connection will close. Ensure the target service responds promptly.
  • Authentication Failures: Incorrect username/password or missing SSL certificates can prevent successful connections.

Error Messages:

  • "Connection successful!" – Indicates a successful connection during credential testing.
  • "Error: <error message>" – Details about why the connection failed (e.g., invalid credentials, unreachable host).

How to resolve:

  • Double-check all credential fields.
  • Verify the broker address and port.
  • Ensure the broker supports the selected protocol (mqtt, mqtts, etc.).
  • For SSL connections, ensure all certificate files are correct and accessible.

Links and References

Discussion