Erweiterungen
This commit is contained in:
1 parent
279f6cb868
commit
5b3dead325
14 files changed
+114
-52
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:mqtt_client/mqtt_client.dart';
|
||||
@@ -13,7 +15,8 @@ import 'package:stadtbote/model/status.dart';
|
||||
import 'package:stadtbote/protocoll_messages/acknowledge_job.dart';
|
||||
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
||||
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
||||
import 'package:stadtbote/protocoll_messages/device_log.dart';
|
||||
import 'package:stadtbote/protocoll_messages/device_log_request.dart';
|
||||
import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
||||
import 'package:stadtbote/model/job.dart';
|
||||
import 'package:stadtbote/model/message.dart';
|
||||
@@ -133,13 +136,22 @@ class MqttCore {
|
||||
}
|
||||
}
|
||||
|
||||
publishBinary(String topic, List<int> data) {
|
||||
var buffer = Uint8Buffer();
|
||||
buffer.addAll(data);
|
||||
|
||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||
|
||||
Util.logInfo("binary message send to $topic");
|
||||
}
|
||||
|
||||
publishText(String topic, String text) {
|
||||
var buffer = Uint8Buffer();
|
||||
buffer.addAll(utf8.encode(text));
|
||||
|
||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||
|
||||
Util.logInfo("message\n$text\nsend to $topic");
|
||||
//Util.logInfo("message\n$text\nsend to $topic");
|
||||
}
|
||||
|
||||
publishPayloadMessage(String topic, Map<String, dynamic> payload) {
|
||||
@@ -274,8 +286,8 @@ class MqttCore {
|
||||
for (var foundJobData in payloadData) {
|
||||
Job newJob = Job.fromJson(foundJobData);
|
||||
|
||||
MyApp.isarInstance.writeTxnSync(() async {
|
||||
MyApp.isarInstance.jobs.putSync(newJob);
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.put(newJob);
|
||||
});
|
||||
|
||||
if (newJob.state == Constants.stateAssigned) {
|
||||
@@ -325,12 +337,21 @@ class MqttCore {
|
||||
}
|
||||
|
||||
void _messageDeviceLogReceived(payloadData) async {
|
||||
var logEintries = await MyApp.isarInstance.logEntrys.where().findAll();
|
||||
var deviceLogRequest = DeviceLogRequest.fromJson(payloadData);
|
||||
|
||||
var deviceLog = DeviceLog();
|
||||
var logEintries = await MyApp.isarInstance.logEntrys.filter().timeGreaterThan(deviceLogRequest.startDateTime).findAll();
|
||||
|
||||
var deviceLog = DeviceLogResponse();
|
||||
deviceLog.entries = logEintries;
|
||||
|
||||
MqttCore.instance.publishPayloadMessage("device_log", deviceLog.toJson());
|
||||
//MqttCore.instance.publishPayloadMessage("device_log", 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", "")}";
|
||||
publishBinary(topic, gzipBytes!);
|
||||
}
|
||||
|
||||
void _startReconnectTimer() {
|
||||
|
||||
+3
-3
@@ -86,14 +86,14 @@ class Util {
|
||||
pattern.allMatches(text).forEach((match) => debugPrint(match.group(0)));
|
||||
}
|
||||
|
||||
static void _persistLogMessage(String text, LogEntrySeverityEnum severity) {
|
||||
static void _persistLogMessage(String text, LogEntrySeverityEnum severity) async {
|
||||
var logEntry = LogEntry();
|
||||
logEntry.time = DateTime.now();
|
||||
logEntry.text = text;
|
||||
logEntry.severity = severity;
|
||||
|
||||
MyApp.isarInstance.writeTxnSync(() {
|
||||
MyApp.isarInstance.logEntrys.putSync(logEntry);
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.logEntrys.put(logEntry);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user