Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zafron MQTT Python Library

A Python library for connecting to Zafron using MQTT protocol. This library provides a simple interface for sending data to Zafron's MQTT broker and handling device communications.

Features

  • Simple, Pythonic API for Zafron MQTT communication
  • Automatic connection management
  • Type-safe implementation with Python 3.6+ support
  • Built-in error handling
  • Support for both virtual and sensor data types
  • Asynchronous operation for non-blocking I/O

Installation

pip install zafron-mqtt

Usage Example

from zafron_mqtt import ZafronConfig, ZafronMQTT

# Create configuration
config = ZafronConfig(
    username="your_username",
    password="your_password",
    client_id="your_client_id"
)

# Initialize Zafron client
zafron = ZafronMQTT(config)

# Connect to Zafron
if zafron.connect():
    # Send temperature data
    zafron.send_sensor_data(1, 22.5, "°C")
    
    # Send humidity data
    zafron.send_sensor_data(2, 65.2, "%")
    
    # Send custom data
    zafron.send_data(3, {"status": "online"})
    
    # Disconnect when done
    zafron.disconnect()

Requirements

  • Python 3.6+
  • paho-mqtt library (automatically installed)

API Documentation

ZafronConfig

@dataclass
class ZafronConfig:
    username: str        # Zafron MQTT username
    password: str        # Zafron MQTT password
    client_id: str       # Unique client identifier
    broker: str = "mqtt.zafron.dev"  # MQTT broker address
    port: int = 1883     # MQTT port

ZafronMQTT

class ZafronMQTT:
    def __init__(self, config: ZafronConfig) -> None:
        """Initialize Zafron MQTT client"""
        
    def connect(self) -> bool:
        """Connect to Zafron MQTT broker"""
        
    def disconnect(self) -> None:
        """Disconnect from Zafron MQTT broker"""
        
    def send_data(self, channel: int, value: Any, data_type: str = "virtual") -> bool:
        """Send data to Zafron"""
        
    def send_sensor_data(self, channel: int, value: float, unit: str) -> bool:
        """Send sensor data with unit information"""

Contributing

Contributions are welcome! Please submit a pull request with:

  1. Clear description of changes
  2. Updated documentation if applicable
  3. Tests for new functionality

License

MIT License

Support

For issues or feature requests, please use the issue tracker.

Versioning

This library follows semantic versioning. Major version changes may include breaking API changes.

Testing

# Install test dependencies
pip install -r requirements-dev.txt

# Run tests
pytest

About

Zafron IoT

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

Used by

Contributors

Languages