Modify MQTTClient service to support tls certs #154

This commit is contained in:
Kendrick Chan 2018-07-06 23:46:02 +08:00
parent 6df440f887
commit 550d1e1e02
3 changed files with 6 additions and 3 deletions

View file

@ -26,5 +26,5 @@ RT_SHORTCODE=1234
# mosquitto client # mosquitto client
MQTT_IP_ADDRESS=localhost MQTT_IP_ADDRESS=localhost
MQTT_PORT=1883 MQTT_PORT=8883
MQTT_CERT=/location/of/cert/file.crt

View file

@ -69,3 +69,4 @@ services:
arguments: arguments:
$ip_address: "%env(MQTT_IP_ADDRESS)%" $ip_address: "%env(MQTT_IP_ADDRESS)%"
$port: "%env(MQTT_PORT)%" $port: "%env(MQTT_PORT)%"
$cert: "%env(MQTT_CERT)%"

View file

@ -12,9 +12,11 @@ class MQTTClient
protected $mclient; protected $mclient;
public function __construct($ip_address, $port) public function __construct($ip_address, $port, $cert)
{ {
$this->mclient = new MosquittoClient(); $this->mclient = new MosquittoClient();
$this->mclient->setTlsCertificates($cert);
$this->mclient->setTlsOptions(MosquittoClient::SSL_VERIFY_NONE, 'tlsv1');
$this->mclient->connect($ip_address, $port); $this->mclient->connect($ip_address, $port);
} }