hak / mqtt-broker
Mosquitto 客户端使用的 PHP 包。
1.0.0
2024-10-02 15:53 UTC
Requires
- php: ^8.0
- react/event-loop: ^1.5
- react/socket: ^1.16
Requires (Dev)
- phpunit/phpunit: ^9.0
README
安装
您可以通过 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)。有关更多信息,请参阅许可证文件。