Package com.codename1.io.mqtt


package com.codename1.io.mqtt

A small MQTT 3.1.1 client.

MqttClient connects to a broker over plain TCP (tcp://) or over a WebSocket with the mqtt subprotocol (ws:// and wss://, which is how TLS is reached: the TCP transport has no TLS), publishes and subscribes at QoS 0 and QoS 1, and delivers every callback on the Codename One EDT.

MqttCodec and MqttPacket are the transport independent packet layer and work on plain streams. QoS 2 is not implemented: a client never asks a broker for it, and a packet that needs it is a protocol error.

MqttOptions o = new MqttOptions("tcp://broker.example.com:1883", "my-client");
MqttClient c = new MqttClient();
c.connect(o, new MqttListener() {
    public void connected() { c.subscribe("sensors/#", 1); }
    public void messageArrived(String topic, byte[] payload, boolean retained) { }
    public void connectionLost(String reason) { }
});