kinnow_mqtt 0.0.2
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}"),
);
}