From dbe821b08df9d61899a0af46c3d3fe433c48c14c Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Fri, 19 Jan 2024 11:24:09 +0100 Subject: [PATCH] Erweiterungen --- lib/tools/mqtt_core.dart | 50 ++++++---------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index e6f8f51..5412adb 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -48,7 +48,6 @@ class MqttCore { try { String clientId = await Util.getAppUuid(); Util.logInfo("client id: $clientId"); - Util.logInfo("broker uri: $_brokerUri"); Util.logInfo("broker port: $_brokerPort"); @@ -59,10 +58,10 @@ class MqttCore { _mqttClient.onDisconnected = _clientDisconnected; _mqttClient.connectionMessage = MqttConnectMessage() - .withClientIdentifier('clientId') + .withClientIdentifier(await Util.getAppUuid()) .withWillQos(MqttQos.atMostOnce) - //.withWillTopic('willTopic') - //.withWillMessage('willMessage') + .withWillTopic('willTopic') + .withWillMessage('willMessage') .authenticateAs("app", "apppwd"); await _mqttClient.connect(); @@ -215,7 +214,7 @@ class MqttCore { var handshakeMessage = BootstrapRequest(); handshakeMessage.app = "sb"; - handshakeMessage.mqttClientId = "12345"; + handshakeMessage.mqttClientId = await Util.getAppUuid(); handshakeMessage.deviceObject = deviceObject; handshakeMessage.ver = 200; @@ -253,51 +252,16 @@ class MqttCore { var jsonMap = startSessionMessage.toJson(); var json = jsonEncode(jsonMap); - Util.logInfo("json: $json"); + Util.logInfo("send start session json: $json"); final builder = MqttClientPayloadBuilder(); builder.addString(json); var payload = builder.payload; var topic = "$_toServerTopic/init"; - Util.logInfo("topic: $topic"); + Util.logInfo("send start session json to topic: $topic"); var messageId = _mqttClient.publishMessage(topic, MqttQos.exactlyOnce, payload!); - Util.logInfo("messageId: $messageId"); + Util.logInfo("send start session json with 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(); - } - */ }