kinnow_mqtt 0.0.2 copy "kinnow_mqtt: ^0.0.2" to clipboard
kinnow_mqtt: ^0.0.2 copied to clipboard

A Mqtt 5 client designed with lifecycle management and IoT in mind.

example/kinnow_mqtt_example.dart

import 'package:kinnow_mqtt/kinnow_mqtt.dart';

void main() async {
  final client = KinnowMqttClient(
      TcpMqttNetworkConnection("your.brokers.address.here.com", 1883));
  final connPkt = ConnectPacket(
    cleanStart: true,
    lastWill: null,
    keepAliveSeconds: 60,
    username: null,
    password: null,
  );
  final eventStream = client.begin(connPkt);
  eventStream.listen(
    (event) => print(event.runtimeType),
  );
  await client.publishQos0(TxPublishPacket(
    false,
    "zainTestTopic",
    StringOrBytes.fromString(
        "joe mama so fat, she wouldn't fit in the mqtt size limit"),
  ));

  final puback = await client.publishQos1(TxPublishPacket(
      false,
      "zainTestTopic",
      StringOrBytes.fromString(
          "joe mama so old, she still using mqtt v3.1.1")));

  if (puback != null) {
    print("puback received");
  }

  /*
  final qos2res = await client.publishQos2(TxPublishPacket(
      false,
      "zainTestTopic",
      StringOrBytes.fromString(
          "joe mama so dumb, her mqtt client needs to be connected to send messages")));

  if (qos2res != null) {
    print("pubrec and pubcomp received");
  }
   */

  final suback = await client.subscribe(SubscribePacket([
    TopicSubscription("likeShareAndSubscribe", MqttQos.atMostOnce),
    TopicSubscription("MistOrBeast", MqttQos.atLeastOnce),
  ]));
  if (suback != null) {
    print("suback received");
    int idx = 0;
    for (final reason in suback.reasonCodes) {
      print("topic $idx success ${reason.name}");
      idx++;
    }
  }

  client.receivedMessagesStream.listen(
    (event) => print("Packet Received "
        "\n \t topic: ${event.topic},"
        "\n \t qos: ${event.qos},"
        "\n \t payload: ${event.payload.asString}"),
  );
}
2
likes
0
points
178
downloads

Publisher

unverified uploader

Weekly Downloads

A Mqtt 5 client designed with lifecycle management and IoT in mind.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async, isar, path

More

Packages that depend on kinnow_mqtt