-
public interface IMqttServer
Enables an android application to communicate with an MQTT server.
-
-
Method Summary
Modifier and Type Method Description abstract void
subscribe(String topic, IResultCallback callback)
Subscribe to a topic. abstract void
subscribe(String topic, int qos, IResultCallback callback)
Subscribe to a topic with qos. abstract void
subscribe(Array<String> topicIds, IResultCallback callback)
Subscribe topics to MQTT server. abstract void
subscribe(Array<String> topic, Array<int> qos, IResultCallback callback)
Subscribes to multiple topics, each topic may include wildcards. abstract void
unSubscribe(String topic, IResultCallback callback)
Requests the server unsubscribe the client from a topic. abstract IMqttDeliveryToken
publish(String topic, Array<byte> data, IResultCallback callback)
Publishes a message to a topic on the server. abstract IMqttDeliveryToken
publish(String topicId, Array<byte> data, int qos, boolean retained, IResultCallback callback)
Publishes a message to a topic on the server. abstract void
publishDevice(MqttControlBuilder builder, IResultCallback callback)
Publish message to specified device to control it on mqtt server. abstract void
publishDevice(MqttControlBuilder builder, PublishAndDeliveryCallback callback, IResultCallback resultCallback)
Publish message to specified device to control it on mqtt server. abstract void
registerMqttCallback(IMqttServerStatusCallback callback)
Register mqtt connect callback. abstract void
unRegisterMqttCallback(IMqttServerStatusCallback callback)
Unregister mqtt connect callback. abstract void
connect()
Connects to an MQTT server and init MQTT config. abstract void
close()
Close the client. abstract void
justConnect()
Just connects to an MQTT server. abstract void
justClose()
Just close connection, not releases all resource. abstract boolean
isRealConnect()
Determines if this client is currently connected to the server. abstract void
registerMqttMessageParserListener(MqttMessageRespParseListener listener)
Register mqtt message listener, callback message of specify topic. abstract void
unRegisterMqttMessageParserListener(MqttMessageRespParseListener listener)
Unregister mqtt message listener, callback message of specify topic. abstract void
registerMqttFlowRespParseListener(MqttFlowRespParseListener listener)
Register flow response listener, just for sweeper device. abstract void
unRegisterMqttFlowRespParseListener(MqttFlowRespParseListener listener)
Unregister flow response listener, just for sweeper device. abstract void
rawConnect()
Connects to an MQTT server , direct connect. abstract void
setMqttConfigTransfer(IThingGetBaseConfig iThingMQTTConfig)
MQTT connect config abstract void
publishLinkWithTopic(MqttControlBuilder builder, IResultCallback resultCallback)
Publish message to specified device to control it on mqtt server. abstract boolean
isSubscribe(String topicId)
是否已经订阅 -
-
Method Detail
-
subscribe
abstract void subscribe(String topic, IResultCallback callback)
Subscribe to a topic.
- Parameters:
topic
- the topic to subscribe to, which can include wildcards.callback
- optional listener that will be notified when subscribe hascompleted
-
subscribe
abstract void subscribe(String topic, int qos, IResultCallback callback)
Subscribe to a topic with qos.
- Parameters:
topic
- the topic to subscribe to, which can include wildcards.qos
- the maximum quality of service at which to subscribe.callback
- optional listener that will be notified when subscribe hascompleted
-
subscribe
abstract void subscribe(Array<String> topicIds, IResultCallback callback)
Subscribe topics to MQTT server.
If you need to register a listener, please see registerMqttMessageParserListener
- Parameters:
topicIds
- Topic ids which you want to subscribe.callback
- Callback whether the subscription is successful
-
subscribe
abstract void subscribe(Array<String> topic, Array<int> qos, IResultCallback callback)
Subscribes to multiple topics, each topic may include wildcards.
Provides an optimized way to subscribe to multiple topics compared tosubscribing to each one individually.
The registerMqttMessageParserListener method should be called beforethis method, otherwise any received messages will be discarded.
If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true,when connecting to the server, the subscription remains in place untileither:
- The client disconnects
- An unsubscribe method is called to unsubscribe the topic
If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false,when connecting to the server, the subscription remains in placeuntil either:
- An unsubscribe method is called to unsubscribe the topic
- The next time the client connects with cleanSession set to true
With cleanSession set to false the MQTT server will store messageson behalf of the client when the client is not connected. The next timethe client connects with the same client ID the server willdeliver the stored messages to the client.
The "topic filter" string is used when subscription may contain specialcharacters, which allows you to subscribe to multiple topics at once.
- Parameters:
topic
- one or more topics to subscribe to, which can includewildcardsqos
- the maximum quality of service to subscribe each topicat.Messages published at a lower quality of service will bereceived at the published QoS.callback
- optional listener that will be notified when subscribe hascompleted
-
unSubscribe
abstract void unSubscribe(String topic, IResultCallback callback)
Requests the server unsubscribe the client from a topic.
- Parameters:
topic
- the topic to unsubscribe from.callback
- optional listener that will be notified when unsubscribe hascompleted
-
publish
abstract IMqttDeliveryToken publish(String topic, Array<byte> data, IResultCallback callback)
Publishes a message to a topic on the server.
Once this method has returned cleanly, the message has been accepted forpublication by the client and will be delivered on a background thread.In the event the connection fails or the client stops, Messages will bedelivered to the requested quality of service once the connection isre-established to the server on condition that:
- The connection is re-established with the same clientID
- The original connection was made with (@linkMqttConnectOptions#setCleanSession(boolean)} set to false
- The connection is re-established with (@linkMqttConnectOptions#setCleanSession(boolean)} set to false
- Depending when the failure occurs QoS 0 messages may not bedelivered.
When building an application, the design of the topic tree should takeinto account the following principles of topic name syntax and semantics:
- A topic must be at least one character long.
- Topic names are case sensitive. For example, ACCOUNTS andAccounts are two different topics.
- Topic names can include the space character. For example,Accountspayable is a valid topic.
- A leading "/" creates a distinct topic. For example,/finance is different from finance. /financematches "+/+" and "/+", but not "+".
- Do not include the null character (Unicode \x0000) in any topic.
The following principles apply to the construction and content of a topictree:
- The length is limited to 64k but within that there are no limits tothe number of levels in a topic tree.
- There can be any number of root nodes; that is, there can be anynumber of topic trees.
- Parameters:
topic
- to deliver the message to, for example "finance/stock/ibm".data
- to deliver to the servercallback
- optional listener that will be notified when message deliveryhas completed to the requested quality of service
-
publish
abstract IMqttDeliveryToken publish(String topicId, Array<byte> data, int qos, boolean retained, IResultCallback callback)
Publishes a message to a topic on the server.
- Parameters:
topicId
- to deliver the message to, for example "finance/stock/ibm".data
- to deliver to the serverqos
- the Quality of Service to deliver the message at.retained
- whether or not this message should be retained by the server.callback
- optional listener that will be notified when message deliveryhas completed to the requested quality of service
-
publishDevice
abstract void publishDevice(MqttControlBuilder builder, IResultCallback callback)
Publish message to specified device to control it on mqtt server.
- Parameters:
builder
- MqttControlBuilder Control device message buildercallback
- Listener that will be notified when message deliveryhas completed to the requested quality of service
-
publishDevice
abstract void publishDevice(MqttControlBuilder builder, PublishAndDeliveryCallback callback, IResultCallback resultCallback)
Publish message to specified device to control it on mqtt server.
- Parameters:
builder
- MqttControlBuilder Control device message buildercallback
- PublishAndDeliveryCallback Listener that will be notified when message deliveryhas completed to the requested quality of service
-
registerMqttCallback
abstract void registerMqttCallback(IMqttServerStatusCallback callback)
Register mqtt connect callback.
- Parameters:
callback
- mqtt connect callback.
-
unRegisterMqttCallback
abstract void unRegisterMqttCallback(IMqttServerStatusCallback callback)
Unregister mqtt connect callback.
- Parameters:
callback
- mqtt connect callback.
-
connect
abstract void connect()
Connects to an MQTT server and init MQTT config.
It is recommended to call registerMqttCallback prior toconnecting in order that messages destined for the client can be acceptedas soon as the client is connected.
-
close
abstract void close()
Close the client. Releases all resource associated with the client. Afterthe client has been closed it cannot be reused. For instance attempts toconnect will fail.
-
justConnect
abstract void justConnect()
Just connects to an MQTT server. connect also initialize the configuration.
Only call the justClose method can call this method.
It is recommended to call registerMqttCallback prior toconnecting in order that messages destined for the client can be acceptedas soon as the client is connected.
-
justClose
abstract void justClose()
Just close connection, not releases all resource.If you need to reconnect, just call justConnect
-
isRealConnect
abstract boolean isRealConnect()
Determines if this client is currently connected to the server.
-
registerMqttMessageParserListener
abstract void registerMqttMessageParserListener(MqttMessageRespParseListener listener)
Register mqtt message listener, callback message of specify topic.
- Parameters:
listener
- MqttMessageRespParseListener
-
unRegisterMqttMessageParserListener
abstract void unRegisterMqttMessageParserListener(MqttMessageRespParseListener listener)
Unregister mqtt message listener, callback message of specify topic.
- Parameters:
listener
- MqttMessageRespParseListener
-
registerMqttFlowRespParseListener
abstract void registerMqttFlowRespParseListener(MqttFlowRespParseListener listener)
Register flow response listener, just for sweeper device.
- Parameters:
listener
- MqttFlowRespParseListener
-
unRegisterMqttFlowRespParseListener
abstract void unRegisterMqttFlowRespParseListener(MqttFlowRespParseListener listener)
Unregister flow response listener, just for sweeper device.
- Parameters:
listener
- MqttFlowRespParseListener
-
rawConnect
abstract void rawConnect()
Connects to an MQTT server , direct connect.
-
setMqttConfigTransfer
abstract void setMqttConfigTransfer(IThingGetBaseConfig iThingMQTTConfig)
MQTT connect config
-
publishLinkWithTopic
abstract void publishLinkWithTopic(MqttControlBuilder builder, IResultCallback resultCallback)
Publish message to specified device to control it on mqtt server.
- Parameters:
builder
- MqttControlBuilder Control device message builderresultCallback
- IResultCallback Listener that has completed to the requested quality of service
-
isSubscribe
abstract boolean isSubscribe(String topicId)
是否已经订阅
-
-
-
-