Erweiterungen
This commit is contained in:
1 parent
86414f4d0e
commit
dbe821b08d
1 file changed
+7
-43
@@ -48,7 +48,6 @@ class MqttCore {
|
|||||||
try {
|
try {
|
||||||
String clientId = await Util.getAppUuid();
|
String clientId = await Util.getAppUuid();
|
||||||
Util.logInfo("client id: $clientId");
|
Util.logInfo("client id: $clientId");
|
||||||
|
|
||||||
Util.logInfo("broker uri: $_brokerUri");
|
Util.logInfo("broker uri: $_brokerUri");
|
||||||
Util.logInfo("broker port: $_brokerPort");
|
Util.logInfo("broker port: $_brokerPort");
|
||||||
|
|
||||||
@@ -59,10 +58,10 @@ class MqttCore {
|
|||||||
_mqttClient.onDisconnected = _clientDisconnected;
|
_mqttClient.onDisconnected = _clientDisconnected;
|
||||||
|
|
||||||
_mqttClient.connectionMessage = MqttConnectMessage()
|
_mqttClient.connectionMessage = MqttConnectMessage()
|
||||||
.withClientIdentifier('clientId')
|
.withClientIdentifier(await Util.getAppUuid())
|
||||||
.withWillQos(MqttQos.atMostOnce)
|
.withWillQos(MqttQos.atMostOnce)
|
||||||
//.withWillTopic('willTopic')
|
.withWillTopic('willTopic')
|
||||||
//.withWillMessage('willMessage')
|
.withWillMessage('willMessage')
|
||||||
.authenticateAs("app", "apppwd");
|
.authenticateAs("app", "apppwd");
|
||||||
|
|
||||||
await _mqttClient.connect();
|
await _mqttClient.connect();
|
||||||
@@ -215,7 +214,7 @@ class MqttCore {
|
|||||||
|
|
||||||
var handshakeMessage = BootstrapRequest();
|
var handshakeMessage = BootstrapRequest();
|
||||||
handshakeMessage.app = "sb";
|
handshakeMessage.app = "sb";
|
||||||
handshakeMessage.mqttClientId = "12345";
|
handshakeMessage.mqttClientId = await Util.getAppUuid();
|
||||||
handshakeMessage.deviceObject = deviceObject;
|
handshakeMessage.deviceObject = deviceObject;
|
||||||
handshakeMessage.ver = 200;
|
handshakeMessage.ver = 200;
|
||||||
|
|
||||||
@@ -253,51 +252,16 @@ class MqttCore {
|
|||||||
|
|
||||||
var jsonMap = startSessionMessage.toJson();
|
var jsonMap = startSessionMessage.toJson();
|
||||||
var json = jsonEncode(jsonMap);
|
var json = jsonEncode(jsonMap);
|
||||||
Util.logInfo("json: $json");
|
Util.logInfo("send start session json: $json");
|
||||||
|
|
||||||
final builder = MqttClientPayloadBuilder();
|
final builder = MqttClientPayloadBuilder();
|
||||||
builder.addString(json);
|
builder.addString(json);
|
||||||
var payload = builder.payload;
|
var payload = builder.payload;
|
||||||
|
|
||||||
var topic = "$_toServerTopic/init";
|
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!);
|
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();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user