Schema für Topic geändert

This commit is contained in:
Sven committed 2024-05-14 09:39:53 +02:00
1 parent 7c2f5369ab
commit 4b8ac028bc
3 files changed
+6 -24

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ Future<void> main() async {
LogEntrySchema, LogEntrySchema,
RankingSchema, RankingSchema,
PictureSchema PictureSchema
], directory: dir.path); ], directory: dir.path, name: "database_v1");
runZonedGuarded(() {}, (error, stackTrace) { runZonedGuarded(() {}, (error, stackTrace) {
_traceUncaughtExceptions(error, stackTrace); _traceUncaughtExceptions(error, stackTrace);
+4 -22
View File
@@ -136,25 +136,12 @@ class MqttCore {
} }
} }
publishBinary(String topic, List<int> data) {
if (_mqttClient != null) {
var buffer = Uint8Buffer();
buffer.addAll(data);
_mqttClient!.publishMessage(topic, MqttQos.exactlyOnce, buffer);
Util.logInfo("binary message send to $topic");
} else {
Util.logException("publishBinary called while offline!");
}
}
bool _publishText(String topic, String text, {bool enqueueOnError = true}) { bool _publishText(String topic, String text, {bool enqueueOnError = true}) {
try { try {
var buffer = Uint8Buffer(); var buffer = Uint8Buffer();
buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>); buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(text)) as Iterable<int>);
var messageTopic = "$_toServerTopic$topic/$_clientId"; var messageTopic = "$_toServerTopic$_clientId/$topic";
_mqttClient!.publishMessage(messageTopic, MqttQos.exactlyOnce, buffer); _mqttClient!.publishMessage(messageTopic, MqttQos.exactlyOnce, buffer);
@@ -178,13 +165,12 @@ class MqttCore {
try { try {
final MqttPublishMessage message = mqttMessage.payload as MqttPublishMessage; final MqttPublishMessage message = mqttMessage.payload as MqttPublishMessage;
if (message.variableHeader!.topicName.endsWith(_clientId)) {
var messageBytes = message.payload.message; var messageBytes = message.payload.message;
String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes)); String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes));
var topicArray = message.variableHeader?.topicName; var topicArray = message.variableHeader?.topicName;
var topicArraySplited = topicArray!.split("/"); var topicArraySplited = topicArray!.split("/");
var topic = topicArraySplited[3]; var topic = topicArraySplited[6];
Util.logInfo('message received\ntopic: $topic\nmessage: $payload'); Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
@@ -229,14 +215,13 @@ class MqttCore {
Util.logInfo('Unknown topic: $topic'); Util.logInfo('Unknown topic: $topic');
break; break;
} }
}
} catch (ex) { } catch (ex) {
Util.logException(ex.toString()); Util.logException(ex.toString());
} }
} }
}); });
var fromServerTopic = "$_fromServerTopic#"; var fromServerTopic = "$_fromServerTopic$_clientId/#";
if (await Util.preferencesContainsKey(Constants.prefsPreviousMqttSubscription)) { if (await Util.preferencesContainsKey(Constants.prefsPreviousMqttSubscription)) {
String previousMqttSubscription = await Util.preferencesGetString(Constants.prefsPreviousMqttSubscription, "") as String; String previousMqttSubscription = await Util.preferencesGetString(Constants.prefsPreviousMqttSubscription, "") as String;
@@ -376,11 +361,8 @@ class MqttCore {
deviceLog.entries = logEintries; deviceLog.entries = logEintries;
var json = jsonEncode(deviceLog.toJson()); var json = jsonEncode(deviceLog.toJson());
var stringBytes = utf8.encode(json);
var gzipBytes = GZipEncoder().encode(stringBytes);
var topic = "/log/${_toServerTopic.replaceAll("/app/", "").replaceAll("/to_server", "")}"; _publishText("device_log", json);
publishBinary(topic, gzipBytes!);
} }
void _startBootstrapReconnectTimer() { void _startBootstrapReconnectTimer() {
+1 -1
View File
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 306.0.0+306 version: 308.0.0+308
environment: environment:
sdk: '>=2.19.6 <3.0.0' sdk: '>=2.19.6 <3.0.0'