public function testCryptedClientCreation() { // Try to establish connection to server $client = new LibMQTT\Client("test.mosquitto.org", 8883, "phpUnitClient"); $client->setCryptoProtocol("tls"); $client->setCAFile("tests/mosquitto.org.crt"); // $result = $client->connect(); $this->assertTrue($result); // Subscribe to 'libmqtt/test' and 'libmqtt/empty' channels $result = $client->subscribe(["libmqtt/test" => ["qos" => 1], "libmqtt/empty" => ["qos" => 0]]); $this->assertTrue($result); // $result = $client->publish("libmqtt/test", "testi", 0); $this->assertTrue($result); // $client->close(); }
<?php // File created by: composer dump-autoload -o require "../vendor/autoload.php"; // Try to establish connection to server $client = new LibMQTT\Client("serverName", 8883, "ThisIsYourUniqueClientID"); // Set connection protocol ("tls" = all tls versions) $client->setCryptoProtocol("tls"); // If server is running with self-signed certificate, provide CA file here #$client->setCAFile("path_to_cafile"); $result = $client->connect(); // Publish message to "topic1/topic2" $client->publish("topic1/topic2", "Test Message", 0); // Close the connection. $client->close();