comfyui-mqtt-node
A ComfyUI custom node for publishing images to MQTT brokers with support for TLS encryption and authentication.
Be warned, this is AI-generated, but I have edited it and seems to be functional
ComfyUI MQTT Node
A ComfyUI custom node for publishing images to MQTT brokers with support for TLS encryption and authentication.
Features
- Publish images directly from ComfyUI workflows to MQTT brokers
- Support for JPEG and PNG image formats
- Configurable image quality
- TLS/SSL encryption support
- Username/password authentication
- QoS (Quality of Service) levels 0, 1, and 2
- Retain flag support
- JSON metadata publishing for image information without binary payload
- Pass-through design: outputs the image unchanged for further processing
Nodes Included
1. MQTT Publish Image
Publishes the full image binary data to an MQTT topic.
Inputs:
image(required): The image tensor from ComfyUIbroker_url(required): MQTT broker hostname or IP (default: "localhost")broker_port(required): MQTT broker port (default: 1883, for TLS typically 8883)topic(required): MQTT topic to publish to (default: "comfyui/image")use_tls(required): Enable TLS/SSL encryption (default: False)image_format(required): JPEG or PNG (default: JPEG)quality(required): JPEG quality 1-100 (default: 95)username(optional): MQTT authentication usernamepassword(optional): MQTT authentication passwordclient_id(optional): MQTT client identifier (default: "comfyui_mqtt_client")qos(optional): Quality of Service level 0-2 (default: 1)retain(optional): Retain message flag (default: False)
Outputs:
image: Pass-through of the input imagestatus: String indicating success or error message
2. MQTT Publish Image Metadata (JSON)
Publishes image dimensions and metadata as JSON without the binary image data.
Inputs:
image(required): The image tensor from ComfyUIbroker_url(required): MQTT broker hostname or IPbroker_port(required): MQTT broker porttopic(required): MQTT topic to publish to (default: "comfyui/metadata")use_tls(required): Enable TLS/SSL encryptionusername(optional): MQTT authentication usernamepassword(optional): MQTT authentication passwordclient_id(optional): MQTT client identifierqos(optional): Quality of Service level 0-2custom_data(optional): Additional JSON data to include
Outputs:
image: Pass-through of the input imagestatus: String indicating success or error message
Installation
Kubernetes/Helm Installation
For Kubernetes deployments, see the detailed guide: KUBERNETES_INSTALL.md
Quick summary:
- Apply the ConfigMap:
kubectl apply -f kubernetes/configmap.yaml - Add initContainer configuration to your Helm values (see
kubernetes/helm-values-example.yaml) - Deploy/upgrade your Helm chart
- The node will be automatically installed at pod startup
Method 1: Manual Installation
- Navigate to your ComfyUI custom nodes directory:
cd /path/to/ComfyUI/custom_nodes
- Clone or copy this repository:
git clone <repository-url> comfyui-mqtt-node
# OR copy the directory manually
cp -r /path/to/comfyui-mqtt-node .
- Install dependencies:
cd comfyui-mqtt-node
pip install -r requirements.txt
- Restart ComfyUI
Method 2: Direct Installation (if ComfyUI is already running)
- Copy this directory to ComfyUI's custom_nodes:
cp -r /home/jeff/comfyui-mqtt-node /path/to/ComfyUI/custom_nodes/
- Install dependencies in ComfyUI's Python environment:
# If using venv
source /path/to/ComfyUI/venv/bin/activate
pip install -r /path/to/ComfyUI/custom_nodes/comfyui-mqtt-node/requirements.txt
# If using system Python
pip install -r /path/to/ComfyUI/custom_nodes/comfyui-mqtt-node/requirements.txt
- Restart ComfyUI
Configuration
Basic Configuration (No TLS, No Auth)
For a local MQTT broker without security:
broker_url: "localhost" or your broker's IPbroker_port: 1883topic: Your desired topic (e.g., "home/images")use_tls: False- Leave
usernameandpasswordempty
Secure Configuration (With TLS)
For encrypted connections:
broker_url: Your broker's hostname (must match certificate)broker_port: 8883 (common TLS port)use_tls: Trueusername: Your MQTT usernamepassword: Your MQTT password
Note: For TLS, ensure your broker has valid certificates. The node uses CERT_REQUIRED and TLSv1.2.
Advanced Configuration
QoS Levels:
0: At most once (fire and forget)1: At least once (acknowledged delivery) - Recommended2: Exactly once (guaranteed delivery, higher overhead)
Retain Flag:
True: The broker stores the message and sends it to new subscribersFalse: Message is only sent to current subscribers
Image Format:
JPEG: Smaller size, lossy compression, good for photographsPNG: Larger size, lossless, good for graphics with transparency
Usage Examples
Example 1: Basic Local Publishing
- Add the "MQTT Publish Image" node to your workflow
- Connect an image output to its
imageinput - Configure:
- broker_url: "localhost"
- broker_port: 1883
- topic: "comfyui/output"
- use_tls: False
- Run your workflow
Example 2: Secure Cloud Broker
- Add the "MQTT Publish Image" node
- Configure:
- broker_url: "your-broker.cloud"
- broker_port: 8883
- topic: "studio/renders"
- use_tls: True
- username: "your-username"
- password: "your-password"
- image_format: "JPEG"
- quality: 90
Example 3: Publishing Metadata Only
- Add the "MQTT Publish Image Metadata (JSON)" node
- Configure the broker settings
- Optionally add custom data:
{
"workflow": "portrait_generation",
"timestamp": 1234567890,
"tags": ["AI", "portrait"]
}
Testing Your Installation
Test with Mosquitto Broker
- Install Mosquitto (MQTT broker and client):
# Ubuntu/Debian
sudo apt-get install mosquitto mosquitto-clients
# macOS
brew install mosquitto
- Start the broker:
mosquitto -v
- In another terminal, subscribe to test the topic:
mosquitto_sub -h localhost -t "comfyui/image" -F "%I" > received_image.jpg
-
Run your ComfyUI workflow with the MQTT node configured for localhost
-
Check that the image was received:
file received_image.jpg
Test Metadata Node
mosquitto_sub -h localhost -t "comfyui/metadata" -v
You should see JSON output with image dimensions.
Troubleshooting
Connection Refused
- Verify MQTT broker is running:
netstat -an | grep 1883 - Check firewall settings
- Verify broker_url and broker_port are correct
TLS/SSL Errors
- Ensure broker has valid certificates
- Verify broker_url matches certificate CN/SAN
- Check that broker is configured for TLS on the specified port
- Try connecting with mosquitto_sub to verify broker:
mosquitto_sub -h broker -p 8883 --cafile ca.crt -t test
Authentication Failures
- Verify username and password are correct
- Check broker's authentication configuration
- Ensure user has publish permissions for the topic
Image Not Publishing
- Check ComfyUI console for error messages
- Verify the image tensor is valid
- Try with a simpler workflow to isolate the issue
- Check broker logs for rejected messages
Node Not Appearing in ComfyUI
- Verify the directory is in
custom_nodes/ - Check for Python syntax errors:
python -m py_compile mqtt_node.py - Ensure requirements are installed in the correct Python environment
- Restart ComfyUI completely
Requirements
- ComfyUI
- Python 3.8+
- paho-mqtt >= 1.6.1
- Pillow >= 9.0.0
- numpy >= 1.20.0
License
MIT License - Feel free to use and modify as needed.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Support
For issues and questions:
- Check the troubleshooting section above
- Review ComfyUI console output for error messages
- Test your MQTT broker with standard tools (mosquitto_pub/sub)
- Open an issue with details about your setup and the error