bluerhinos / phpMQTT

a simple php class to connect/publish/subscribe to a MQTT broker
Other
772 stars 460 forks source link

Can't connect to Azure IoT Hub #78

Closed rsre closed 5 years ago

rsre commented 5 years ago

Hello,

I want to use this library but I can't connect to Azure IoT Hub. I tried to connect to mosquitto in localhost without TLS and it works fine, but when I try to connect to Azure using TLS it fails.

This is my code:

$server = "<iothub>.azure-devices.net"; 
$port = 8883;
$username = "<iothub>.azure-devices.net/"."<deviceId>"."/?api-version=2018-06-30";
$password = "SharedAccessSignature sr=<iothub>.azure-devices.net%2Fdevices%2F<deviceId>&sig=zUf0BtTqLCtuWfAW1sdfgsdfhsdfMlYn%2BVNhJ4Maw%3D&se=1554473449";
$client_id = "<deviceId>";
$cafile = './BaltimoreCyberTrustRoot.crt';

$mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id, $cafile);

Command line shows:

PHP Notice:  Uninitialized string offset: 0 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 156

Notice: Uninitialized string offset: 0 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 156
PHP Notice:  Uninitialized string offset: 0 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 160

Notice: Uninitialized string offset: 0 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 160
PHP Notice:  Uninitialized string offset: 3 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 160

Notice: Uninitialized string offset: 3 in /Users/rsre/Downloads/phpMQTT-master/phpMQTT.php on line 160
Connection failed! (Error: 0x00 0x00)