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
+42 -60

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);
+40 -58
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,57 +165,55 @@ 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');
switch (topic) { switch (topic) {
case 'session': case 'session':
_sessionMessageReceived(jsonDecode(payload)); _sessionMessageReceived(jsonDecode(payload));
break; break;
case 'status': case 'status':
_statusMessageReceived(jsonDecode(payload)); _statusMessageReceived(jsonDecode(payload));
break; break;
case 'ranking': case 'ranking':
_rankingMessageReceived(jsonDecode(payload)); _rankingMessageReceived(jsonDecode(payload));
break; break;
case 'job': case 'job':
_jobMessageReceived(jsonDecode(payload)); _jobMessageReceived(jsonDecode(payload));
break; break;
case 'job_del': case 'job_del':
_jobDeleteReceived(jsonDecode(payload)); _jobDeleteReceived(jsonDecode(payload));
break; break;
case 'sync_request': case 'sync_request':
_syncRequestReceived(jsonDecode(payload)); _syncRequestReceived(jsonDecode(payload));
break; break;
case 'location_status': case 'location_status':
_locationStatusMessageReceived(jsonDecode(payload)); _locationStatusMessageReceived(jsonDecode(payload));
break; break;
case "mssg": case "mssg":
_messageMessageReceived(jsonDecode(payload)); _messageMessageReceived(jsonDecode(payload));
break; break;
case "upload_device_log": case "upload_device_log":
_messageUploadDeviceLogReceived(jsonDecode(payload)); _messageUploadDeviceLogReceived(jsonDecode(payload));
break; break;
default: default:
Util.logInfo('Unknown topic: $topic'); Util.logInfo('Unknown topic: $topic');
break; break;
}
} }
} catch (ex) { } catch (ex) {
Util.logException(ex.toString()); Util.logException(ex.toString());
@@ -236,7 +221,7 @@ class MqttCore {
} }
}); });
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'