Umbau MQTT

This commit is contained in:
Sven committed 2024-04-08 10:22:12 +02:00
1 parent a683ea0ff1
commit 31a292e8d0
6 files changed
+1160 -21

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
{
"broker": "mqtt://18.156.72.225:1883",
"id": "100/1/104400",
"to_server": "/appserver/to_server/",
"from_server": "/appserver/from_server/"
}
+41
View File
@@ -0,0 +1,41 @@
import 'package:isar/isar.dart';
import 'package:json_annotation/json_annotation.dart';
part 'rank.g.dart';
@collection
@JsonSerializable()
class Ranking {
late Id id;
late String zip;
late String area;
late int time;
late List<Vehicle> vehicles;
Ranking();
factory Ranking.fromJson(Map<String, dynamic> json) => _$RankingFromJson(json);
Map<String, dynamic> toJson() => _$RankingToJson(this);
}
@embedded
@JsonSerializable()
class Vehicle {
late int id;
late int type;
@JsonKey(name: 'self', defaultValue: false)
late bool? self;
Vehicle();
factory Vehicle.fromJson(Map<String, dynamic> json) => _$VehicleFromJson(json);
Map<String, dynamic> toJson() => _$VehicleToJson(this);
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,4 @@
class RefreshBadgesMessage {
RefreshBadgesMessage();
}
+22 -20
View File
@@ -97,14 +97,14 @@ class MqttCore {
_mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort); _mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort);
_mqttClient.logging(on: false); _mqttClient.logging(on: false);
_mqttClient.keepAlivePeriod = 20; _mqttClient.keepAlivePeriod = 5;
_mqttClient.autoReconnect = false; _mqttClient.disconnectOnNoResponsePeriod = 10;
_mqttClient.autoReconnect = true;
_mqttClient.onDisconnected = _clientDisconnected; _mqttClient.onDisconnected = _clientDisconnected;
_mqttClient.onAutoReconnect = _clientDisconnected;
_mqttClient.onAutoReconnected = _clientConnected;
_mqttClient.connectionMessage = MqttConnectMessage() _mqttClient.connectionMessage = MqttConnectMessage()
.withClientIdentifier(await Util.getAppUuid()) .withClientIdentifier(await Util.getAppUuid())
.withWillQos(MqttQos.atMostOnce)
.withWillTopic('willTopic')
.withWillMessage('willMessage')
.authenticateAs("app", "apppwd"); .authenticateAs("app", "apppwd");
await _mqttClient.connect(); await _mqttClient.connect();
@@ -121,13 +121,9 @@ class MqttCore {
Util.logInfo('Verbindung zum MQTT-Broker fehlgeschlagen!'); Util.logInfo('Verbindung zum MQTT-Broker fehlgeschlagen!');
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected)); MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
_startReconnectTimer();
} }
} catch (ex) { } catch (ex) {
_startReconnectTimer();
Util.logInfo('Verbindung zum MQTT-Broker fehlgeschlagen!: $ex'); Util.logInfo('Verbindung zum MQTT-Broker fehlgeschlagen!: $ex');
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected)); MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
@@ -350,7 +346,7 @@ class MqttCore {
publishBinary(topic, gzipBytes!); publishBinary(topic, gzipBytes!);
} }
void _startReconnectTimer() { void _startBootstrapReconnectTimer() {
connectionState = ConnectionStateEnum.notConnected; connectionState = ConnectionStateEnum.notConnected;
if (!_disconnectInProgress) { if (!_disconnectInProgress) {
@@ -371,17 +367,23 @@ class MqttCore {
} }
void _clientDisconnected() { void _clientDisconnected() {
connectionState = ConnectionStateEnum.notConnected;
_cancelTrackTimer();
Util.logInfo("_clientDisconnected called"); Util.logInfo("_clientDisconnected called");
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected)); connectionState = ConnectionStateEnum.notConnected;
if (!_disconnectInProgress) { _startTrackTimer();
_startReconnectTimer();
} MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
}
void _clientConnected() {
Util.logInfo("_clientDisconnected called");
connectionState = ConnectionStateEnum.connected;
_initSession();
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
} }
void _processBootstrap() async { void _processBootstrap() async {
@@ -405,7 +407,7 @@ class MqttCore {
var jsonMap = handshakeMessage.toJson(); var jsonMap = handshakeMessage.toJson();
var json = jsonEncode(jsonMap); var json = jsonEncode(jsonMap);
var uri = "https://init-x.assecutor.de/bootstrap?get_mqtt_broker=$json"; String uri = "https://init-x.assecutor.de/bootstrap?get_mqtt_broker=$json";
Util.logInfo("Bootstrap request: $uri"); Util.logInfo("Bootstrap request: $uri");
var response = await http.get(Uri.parse(uri)); var response = await http.get(Uri.parse(uri));
@@ -421,7 +423,7 @@ class MqttCore {
_connectToBroker(); _connectToBroker();
} catch (ex) { } catch (ex) {
_startReconnectTimer(); _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: 220.0.0+11 version: 221.0.0+12
environment: environment:
sdk: '>=2.19.6 <3.0.0' sdk: '>=2.19.6 <3.0.0'