diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index b4cf506..887c121 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'dart:math'; import 'package:isar/isar.dart'; @@ -130,12 +131,17 @@ class MqttCore { publishText(String subtopic, String text) { try { - var buffer = Uint8Buffer(); - buffer.addAll(text.codeUnits); + var textBuffer = Uint8Buffer(); + textBuffer.addAll(text.codeUnits); + + var compressedText = GZipCodec().encode(text.codeUnits); + + var mqttBuffer = Uint8Buffer(); + mqttBuffer.addAll(compressedText); var topic = "$_toServerTopic$subtopic/$_clientId"; - _mqttClient.publishMessage( topic, MqttQos.exactlyOnce, buffer); + _mqttClient.publishMessage( topic, MqttQos.exactlyOnce, mqttBuffer); Util.logInfo("send message $text to $topic"); } catch (e) {