Erweiterungen
This commit is contained in:
1 parent
3dab4025e7
commit
3d7ae9de2a
16 files changed
+438
-327
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data' as typed;
|
||||
|
||||
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
||||
import 'package:mqtt_client/mqtt_client.dart';
|
||||
@@ -9,9 +10,12 @@ import 'package:stadtbote/model/bootstrap_request.dart';
|
||||
import 'package:stadtbote/model/bootstrap_response_payload.dart';
|
||||
import 'package:stadtbote/model/device_object.dart';
|
||||
import 'package:stadtbote/model/job.dart';
|
||||
import 'package:stadtbote/model/start_session_message.dart';
|
||||
import 'package:stadtbote/tools/connection_status.dart';
|
||||
import 'package:stadtbote/tools/session_info_update.dart';
|
||||
import 'package:typed_data/typed_buffers.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../main.dart';
|
||||
import '../model/status.dart';
|
||||
@@ -64,6 +68,8 @@ class MqttCore {
|
||||
_reconnectDelay = 0;
|
||||
|
||||
_setupSubscriptions();
|
||||
|
||||
_initSession();
|
||||
} else {
|
||||
Util.logInfo('Verbindung zum MQTT-Broker fehlgeschlagen!');
|
||||
|
||||
@@ -146,6 +152,8 @@ class MqttCore {
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.status.put(statusMessage);
|
||||
});
|
||||
|
||||
BroadcastReceiver().publish<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdate, arguments: StatusInfoUpdate(status: statusMessage));
|
||||
}
|
||||
|
||||
void _jobMessageReceived(payloadData) async {
|
||||
@@ -211,4 +219,64 @@ class MqttCore {
|
||||
_startReconnectTimer();
|
||||
}
|
||||
}
|
||||
|
||||
_initSession() {
|
||||
var playload = Payload();
|
||||
playload.startSession = "true";
|
||||
|
||||
var startSessionMessage = StartSessionMessage();
|
||||
startSessionMessage.recv = "server";
|
||||
startSessionMessage.store = true;
|
||||
startSessionMessage.messageId = const Uuid().v4();;
|
||||
startSessionMessage.payload = playload;
|
||||
|
||||
var jsonMap = startSessionMessage.toJson();
|
||||
var json = jsonEncode(jsonMap);
|
||||
Util.logInfo("json: $json");
|
||||
|
||||
final builder = MqttClientPayloadBuilder();
|
||||
builder.addString(json);
|
||||
var payload = builder.payload;
|
||||
|
||||
var topic = "$_toServerTopic/init";
|
||||
Util.logInfo("topic: $topic");
|
||||
|
||||
var messageId = _mqttClient.publishMessage(topic, MqttQos.exactlyOnce, payload!);
|
||||
Util.logInfo("messageId: $messageId");
|
||||
}
|
||||
|
||||
/*
|
||||
private async void StartSession()
|
||||
{
|
||||
App.Logger.Debug("StartSession called");
|
||||
|
||||
App.Logger.Debug("Setting state to start session");
|
||||
_mqttState = MqttStateEnum.StartSession;
|
||||
|
||||
var startSession = new JObject
|
||||
{
|
||||
new JProperty("recv", "server"),
|
||||
new JProperty("store", true),
|
||||
new JProperty("id", Guid.NewGuid().ToString()),
|
||||
new JProperty("payload", new JObject(
|
||||
new JProperty("start_session", "true")))
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(startSession);
|
||||
|
||||
var topic = _toServerTopic + "/init";
|
||||
var message = new MqttApplicationMessage()
|
||||
{
|
||||
Topic = topic,
|
||||
Payload = Encoding.UTF8.GetBytes(json),
|
||||
QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce,
|
||||
Retain = true,
|
||||
MessageExpiryInterval = 3600,
|
||||
};
|
||||
await _mqttClient.PublishAsync(message);
|
||||
App.Logger.Debug("StartSession message " + json + " published to " + topic);
|
||||
|
||||
SendEnqueuedMessages();
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in new issue
Block a user