hak/mqtt-broker

Mosquitto 客户端使用的 PHP 包。

1.0.0 2024-10-02 15:53 UTC

This package is auto-updated.

Last update: 2024-10-03 08:08:01 UTC


README

Total Downloads GitHub Actions

安装

您可以通过 composer 安装此包

composer require hak/mqtt-broker

用法

// Usage description here
use Hak\Broker\Client;

$host = 'localhost'; // Your MQTT broker host
$port = 1883;        // Your MQTT broker port
$clientId = 'test_client'; // Unique client ID for your MQTT client
$username = 'your_username'; // Your MQTT username (if required)
$password = 'your_password'; // Your MQTT password (if required)

// Create a new Client instance
$client = new Client($host, $port, $clientId);

// Connect to the MQTT broker
$client->connect($username, $password);

// Subscribe to a topic and handle incoming messages
$client->subscribe('test/topic', function ($topic, $message) {
    echo "Received message on topic [$topic]: $message\n";
});

// Publish a message to the topic
$client->publish('test/topic', 'Hello MQTT!');

// Run indefinitely to keep the connection alive and listening for messages
// Note: This is already handled in the connect method due to the loop->run()

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全

如果您发现任何安全问题,请通过hakhant21@gmail.com发送电子邮件,而不是使用问题跟踪器。

致谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅许可证文件