This n8n workflow automates publishing messages to MQTT topics, supporting single or batch messages with configurable QoS levels. Key nodes include Webhook Trigger (receives POST requests), Validate Input (checks topic, message, QoS), Prepare Message Data (sets message parameters), Check Publish Mode (single or batch), Generate Batch Messages (creates batch messages), Route by QoS Level, Publish QoS 0/1/2, Publish Batch Message (MQTT interactions), Success Response, Publish Error Response, and Return Response (handle outputs). Set up Requirements and Configuration: Install n8n by downloading from n8n.io for self-hosting or sign up at cloud.n8n.io for cloud setup. Follow installation prompts or create a cloud account. Set up an MQTT broker (e.g., Mosquitto) locally or use a cloud service like HiveMQ. Obtain MQTT credentials: broker URL, port (default 1883), and optional username/password from your broker provider. In n8n, import the provided JSON to create the workflow. Configure MQTT nodes (Publish QoS 0/1/2, Publish Batch Message) with your broker details under 'Credentials,' selecting 'MQTT.' Set the Webhook Trigger node’s path to 'mqtt-publish,' ensure it accepts POST requests, and optionally enable header authentication with a secure key. The Validate Input node checks for valid topic, message, and QoS (0, 1, or 2). Testing and Deployment Steps: Test by sending a POST request to the Webhook URL (from the Webhook Trigger node) using Postman. Example JSON body: {'topic': 'test/topic', 'message': 'Hello MQTT', 'qos': '1', 'publishMode': 'single'} or {'topic': 'test/batch', 'message': 'Batch Msg', 'qos': '1', 'publishMode': 'batch', 'batchSize': 3} with the authentication header if enabled. The 'Success Response' node returns a 200 status with publish details, or 'Error Response' (400 status) for invalid inputs like missing topics. Monitor logs for errors like incorrect broker credentials or connection issues, and verify broker settings or input formats if issues occur. Activate the workflow in n8n’s interface for deployment. Validate outputs to confirm message delivery and QoS level.
$5.49
Workflow steps: 15
Integrated apps: webhook, if, set