MqttClient

An MQTT client

package

Default

Methods

__construct

__construct() 

clientId

clientId() : string

Response

string

the client identifier

Set a handler that will be called when the connection with server is closed

closeHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Connects to an MQTT server calling connectHandler after connection

connect( $arg0,  $arg1,  $arg2,  $arg3 = null) : $this

param $port [integer] port of the MQTT server param $host [string] hostname/ip address of the MQTT server param $connectHandler [callable] handler called when the asynchronous connect call ends connect($port, $host, $connectHandler)

Connects to an MQTT server calling connectHandler after connection

param $port [integer] port of the MQTT server param $host [string] hostname/ip address of the MQTT server param $serverName [string] the SNI server name param $connectHandler [callable] handler called when the asynchronous connect call ends connect($port, $host, $serverName, $connectHandler)

Arguments

$arg0

integer

$arg1

string

$arg2

callable | string

$arg3

callable

Response

$this

current MQTT client instance

Return an MQTT client instance using the default options

create( $arg0,  $arg1 = null) : \io\vertx\jphp\mqtt\MqttClient
static

param $vertx [Vertx] Vert.x instance create($vertx)

Return an MQTT client instance

param $vertx [Vertx] Vert.x instance param $options [MqttClientOptions | array] MQTT client options create($vertx, $options)

Arguments

$arg0

Vertx

$arg1

array | MqttClientOptions

Response

\io\vertx\jphp\mqtt\MqttClient

MQTT client instance

Disconnects from the MQTT server

disconnect( $arg0 = null) : $this

disconnect()

Disconnects from the MQTT server calling disconnectHandler after disconnection

param $disconnectHandler [callable] handler called when asynchronous disconnect call ends disconnect($disconnectHandler)

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Set an exception handler for the client, that will be called when an error happens in internal netty structures.

exceptionHandler( $arg0) : $this

io.netty.handler.codec.DecoderException can be one of the cause

Arguments

$arg0

callable

Response

$this

current MQTT client instance

isConnected

isConnected() : boolean

Response

boolean

if the connection between client and remote server is established/open

This method is needed by the client in order to avoid server closes the connection due to the keep alive timeout if client has no messages to send

ping() : $this

Response

$this

current MQTT client instance

Sets handler which will be called after PINGRESP packet receiving

pingResponseHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Sends the PUBLISH message to the remote MQTT server

publish( $arg0,  $arg1,  $arg2,  $arg3,  $arg4,  $arg5 = null) : $this

param $topic [string] topic on which the message is published param $payload [Buffer] message payload param $qosLevel [string] QoS level param $isDup [boolean] if the message is a duplicate param $isRetain [boolean] if the message needs to be retained publish($topic, $payload, $qosLevel, $isDup, $isRetain)

Sends the PUBLISH message to the remote MQTT server

param $topic [string] topic on which the message is published param $payload [Buffer] message payload param $qosLevel [string] QoS level param $isDup [boolean] if the message is a duplicate param $isRetain [boolean] if the message needs to be retained param $publishSentHandler [callable] handler called after PUBLISH packet sent with packetid (not when QoS 0) publish($topic, $payload, $qosLevel, $isDup, $isRetain, $publishSentHandler)

Arguments

$arg0

string

$arg1

Buffer

$arg2

string

$arg3

boolean

$arg4

boolean

$arg5

callable

Response

$this

current MQTT client instance

Sets handler which will be called each time publish is completed

publishCompletionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Sets handler which will be called each time server publish something to client

publishHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Subscribes to the topics with related QoS levels

subscribe( $arg0,  $arg1 = null,  $arg2 = null) : $this

param $topics [array] topics and related QoS levels to subscribe to subscribe($topics)

Subscribes to the topic with a specified QoS level

param $topic [string] topic you subscribe on param $qos [integer] QoS level subscribe($topic, $qos)

Subscribes to the topic and adds a handler which will be called after the request is sent

param $topics [array] topics you subscribe on param $subscribeSentHandler [callable] handler called after SUBSCRIBE packet sent with packetid subscribe($topics, $subscribeSentHandler)

Subscribes to the topic with a specified QoS level

param $topic [string] topic you subscribe on param $qos [integer] QoS level param $subscribeSentHandler [callable] handler called after SUBSCRIBE packet sent with packetid subscribe($topic, $qos, $subscribeSentHandler)

Arguments

$arg0

string | array

$arg1

callable | integer

$arg2

callable

Response

$this

current MQTT client instance

Sets handler which will be called after SUBACK packet receiving

subscribeCompletionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance

Unsubscribe from receiving messages on given topic

unsubscribe( $arg0,  $arg1 = null) : $this

param $topic [string] Topic you want to unsubscribe from unsubscribe($topic)

Unsubscribe from receiving messages on given topic

param $topic [string] Topic you want to unsubscribe from param $unsubscribeSentHandler [callable] handler called after UNSUBSCRIBE packet sent unsubscribe($topic, $unsubscribeSentHandler)

Arguments

$arg0

string

$arg1

callable

Response

$this

current MQTT client instance

Sets handler which will be called after UNSUBACK packet receiving

unsubscribeCompletionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

current MQTT client instance