Extensions/comfyui-mqtt-node
ComfyUI Extension

comfyui-mqtt-node

A ComfyUI custom node for publishing images to MQTT brokers with support for TLS encryption and authentication.

By eljefe80·Created 7 months ago·Updated 7 months ago· 0
eljefe80/comfyui-mqtt-node
Nodes
On cloudLocal install
Stars0
Updated7 months ago
Readme

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 ComfyUI
  • broker_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 username
  • password (optional): MQTT authentication password
  • client_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 image
  • status: 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 ComfyUI
  • broker_url (required): MQTT broker hostname or IP
  • broker_port (required): MQTT broker port
  • topic (required): MQTT topic to publish to (default: "comfyui/metadata")
  • use_tls (required): Enable TLS/SSL encryption
  • username (optional): MQTT authentication username
  • password (optional): MQTT authentication password
  • client_id (optional): MQTT client identifier
  • qos (optional): Quality of Service level 0-2
  • custom_data (optional): Additional JSON data to include

Outputs:

  • image: Pass-through of the input image
  • status: String indicating success or error message

Installation

Kubernetes/Helm Installation

For Kubernetes deployments, see the detailed guide: KUBERNETES_INSTALL.md

Quick summary:

  1. Apply the ConfigMap: kubectl apply -f kubernetes/configmap.yaml
  2. Add initContainer configuration to your Helm values (see kubernetes/helm-values-example.yaml)
  3. Deploy/upgrade your Helm chart
  4. The node will be automatically installed at pod startup

Method 1: Manual Installation

  1. Navigate to your ComfyUI custom nodes directory:
cd /path/to/ComfyUI/custom_nodes
  1. Clone or copy this repository:
git clone <repository-url> comfyui-mqtt-node
# OR copy the directory manually
cp -r /path/to/comfyui-mqtt-node .
  1. Install dependencies:
cd comfyui-mqtt-node
pip install -r requirements.txt
  1. Restart ComfyUI

Method 2: Direct Installation (if ComfyUI is already running)

  1. Copy this directory to ComfyUI's custom_nodes:
cp -r /home/jeff/comfyui-mqtt-node /path/to/ComfyUI/custom_nodes/
  1. 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
  1. Restart ComfyUI

Configuration

Basic Configuration (No TLS, No Auth)

For a local MQTT broker without security:

  • broker_url: "localhost" or your broker's IP
  • broker_port: 1883
  • topic: Your desired topic (e.g., "home/images")
  • use_tls: False
  • Leave username and password empty

Secure Configuration (With TLS)

For encrypted connections:

  • broker_url: Your broker's hostname (must match certificate)
  • broker_port: 8883 (common TLS port)
  • use_tls: True
  • username: Your MQTT username
  • password: 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) - Recommended
  • 2: Exactly once (guaranteed delivery, higher overhead)

Retain Flag:

  • True: The broker stores the message and sends it to new subscribers
  • False: Message is only sent to current subscribers

Image Format:

  • JPEG: Smaller size, lossy compression, good for photographs
  • PNG: Larger size, lossless, good for graphics with transparency

Usage Examples

Example 1: Basic Local Publishing

  1. Add the "MQTT Publish Image" node to your workflow
  2. Connect an image output to its image input
  3. Configure:
    • broker_url: "localhost"
    • broker_port: 1883
    • topic: "comfyui/output"
    • use_tls: False
  4. Run your workflow

Example 2: Secure Cloud Broker

  1. Add the "MQTT Publish Image" node
  2. 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

  1. Add the "MQTT Publish Image Metadata (JSON)" node
  2. Configure the broker settings
  3. Optionally add custom data:
{
  "workflow": "portrait_generation",
  "timestamp": 1234567890,
  "tags": ["AI", "portrait"]
}

Testing Your Installation

Test with Mosquitto Broker

  1. Install Mosquitto (MQTT broker and client):
# Ubuntu/Debian
sudo apt-get install mosquitto mosquitto-clients

# macOS
brew install mosquitto
  1. Start the broker:
mosquitto -v
  1. In another terminal, subscribe to test the topic:
mosquitto_sub -h localhost -t "comfyui/image" -F "%I" > received_image.jpg
  1. Run your ComfyUI workflow with the MQTT node configured for localhost

  2. 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:

  1. Check the troubleshooting section above
  2. Review ComfyUI console output for error messages
  3. Test your MQTT broker with standard tools (mosquitto_pub/sub)
  4. Open an issue with details about your setup and the error