phpMQTT connection refused

382 views
Skip to first unread message

Andrew Hickey

unread,
Oct 18, 2017, 4:33:46 PM10/18/17
to MQTT
I'm stuck trying to use phpMQTT to publish to a broker.

I have the web script on one server and the MQTT set up on another remote server.

and I've tested it from the command line with things like:
mosquitto_pub -h mqtt.widgiot.co.uk -t test -m "hello again" -p 8883 --cafile /etc/ssl/certs/ca-bundle.crt -u "[username]" -P "[password]"
and it works great. Message received

But from the phpMQTT I'm just getting this in my error logs:
PHP Warning:  stream_socket_client(): unable to connect to tls://mqtt.widgiot.co.uk:8883 (Connection refused)...

This is the function that uses mqtt:
public function onUserLoginFailure($response)
{

require("phpMQTT/phpMQTT.php");

        $server = "mqtt.widgiot.co.uk";    
        $port = 8883;                   
        $username = "[username]";            
        $password = "[password]";               
        $client_id = "phpMQTT-publisher";
        $cafile = '/etc/ssl/certs/ca-bundle.crt';
        $mqtt = new phpMQTT($server, $port, $client_id , $cafile);
        if ($mqtt->connect(true, NULL, $username, $password)) {
            $mqtt->publish("test", "Hello World! at " . date("r"), 0);
            $mqtt->close();
        } else {
            echo "Time out!\n";
        }
}

The username/password details are correct. I'm just not sure about how to reference the $cacert. I've used the same location as in the terminal (which works). 

Any ideas what might be the issue? Firewall? How to check where the blockage is coming from? I have root access on both servers (the one with the phpmqtt script and the mqtt broker server).
Reply all
Reply to author
Forward
0 new messages