Erweiterungen
This commit is contained in:
1 parent
fca152aa1e
commit
1a659be3b8
7 files changed
+72
-107
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"payload": {
|
||||||
|
"config": {
|
||||||
|
"broker": "mqtt://192.168.180.27:1883",
|
||||||
|
"topics": {
|
||||||
|
"to_server": "/appserver/to_server/100/1/104400",
|
||||||
|
"from_server": "/appserver/from_server/100/1/104400"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
"main_title": "Hauptseite"
|
||||||
|
},
|
||||||
|
"option": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@ part 'status.g.dart';
|
|||||||
@collection
|
@collection
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class Status {
|
class Status {
|
||||||
late Id? id;
|
@JsonKey(name: "id", defaultValue: 0)
|
||||||
|
Id? id;
|
||||||
|
|
||||||
late StatusPos pos;
|
late StatusPos pos;
|
||||||
|
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ extension StatusPosQueryObject
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
Status _$StatusFromJson(Map<String, dynamic> json) => Status()
|
Status _$StatusFromJson(Map<String, dynamic> json) => Status()
|
||||||
..id = json['id'] as int?
|
..id = json['id'] as int? ?? 0
|
||||||
..pos = StatusPos.fromJson(json['pos'] as Map<String, dynamic>);
|
..pos = StatusPos.fromJson(json['pos'] as Map<String, dynamic>);
|
||||||
|
|
||||||
Map<String, dynamic> _$StatusToJson(Status instance) => <String, dynamic>{
|
Map<String, dynamic> _$StatusToJson(Status instance) => <String, dynamic>{
|
||||||
|
|||||||
@@ -6,15 +6,7 @@ part 'start_session_message.g.dart';
|
|||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class StartSessionMessage {
|
class StartSessionMessage {
|
||||||
Id get isarId => Util.fastHash(messageId);
|
late bool startSession;
|
||||||
|
|
||||||
late String recv;
|
|
||||||
|
|
||||||
late bool store;
|
|
||||||
|
|
||||||
late String messageId;
|
|
||||||
|
|
||||||
late Payload payload;
|
|
||||||
|
|
||||||
StartSessionMessage();
|
StartSessionMessage();
|
||||||
|
|
||||||
@@ -22,15 +14,3 @@ class StartSessionMessage {
|
|||||||
|
|
||||||
Map<String, dynamic> toJson() => _$StartSessionMessageToJson(this);
|
Map<String, dynamic> toJson() => _$StartSessionMessageToJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable()
|
|
||||||
class Payload {
|
|
||||||
@JsonKey(name:'start_session')
|
|
||||||
late String startSession;
|
|
||||||
|
|
||||||
Payload();
|
|
||||||
|
|
||||||
factory Payload.fromJson(Map<String, dynamic> json) => _$PayloadFromJson(json);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$PayloadToJson(this);
|
|
||||||
}
|
|
||||||
@@ -7,24 +7,10 @@ part of 'start_session_message.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
StartSessionMessage _$StartSessionMessageFromJson(Map<String, dynamic> json) =>
|
StartSessionMessage _$StartSessionMessageFromJson(Map<String, dynamic> json) =>
|
||||||
StartSessionMessage()
|
StartSessionMessage()..startSession = json['startSession'] as bool;
|
||||||
..recv = json['recv'] as String
|
|
||||||
..store = json['store'] as bool
|
|
||||||
..messageId = json['messageId'] as String
|
|
||||||
..payload = Payload.fromJson(json['payload'] as Map<String, dynamic>);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$StartSessionMessageToJson(
|
Map<String, dynamic> _$StartSessionMessageToJson(
|
||||||
StartSessionMessage instance) =>
|
StartSessionMessage instance) =>
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'recv': instance.recv,
|
'startSession': instance.startSession,
|
||||||
'store': instance.store,
|
|
||||||
'messageId': instance.messageId,
|
|
||||||
'payload': instance.payload,
|
|
||||||
};
|
|
||||||
|
|
||||||
Payload _$PayloadFromJson(Map<String, dynamic> json) =>
|
|
||||||
Payload()..startSession = json['start_session'] as String;
|
|
||||||
|
|
||||||
Map<String, dynamic> _$PayloadToJson(Payload instance) => <String, dynamic>{
|
|
||||||
'start_session': instance.startSession,
|
|
||||||
};
|
};
|
||||||
+50
-68
@@ -2,15 +2,13 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:mqtt_client/mqtt_client.dart';
|
import 'package:mqtt_client/mqtt_client.dart';
|
||||||
import 'package:mqtt_client/mqtt_server_client.dart';
|
import 'package:mqtt_client/mqtt_server_client.dart';
|
||||||
import 'package:stadtbote/model/ranking.dart';
|
import 'package:stadtbote/model/ranking.dart';
|
||||||
import 'package:stadtbote/model/status.dart';
|
import 'package:stadtbote/model/status.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
|
||||||
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
|
||||||
import 'package:stadtbote/model/job.dart';
|
import 'package:stadtbote/model/job.dart';
|
||||||
import 'package:stadtbote/model/message.dart';
|
import 'package:stadtbote/model/message.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/job_del_message.dart';
|
import 'package:stadtbote/protocoll_messages/job_del_message.dart';
|
||||||
@@ -28,7 +26,6 @@ import 'package:stadtbote/tools/messages/session_info_update.dart';
|
|||||||
import 'package:stadtbote/tools/messages/status_info_update.dart';
|
import 'package:stadtbote/tools/messages/status_info_update.dart';
|
||||||
// ignore: depend_on_referenced_packages
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:typed_data/typed_buffers.dart';
|
import 'package:typed_data/typed_buffers.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
@@ -137,7 +134,7 @@ class MqttCore {
|
|||||||
|
|
||||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||||
|
|
||||||
Util.logInfo("message $text send to $topic");
|
Util.logInfo("send message $text to $topic");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Util.logException(e.toString());
|
Util.logException(e.toString());
|
||||||
}
|
}
|
||||||
@@ -170,58 +167,53 @@ class MqttCore {
|
|||||||
|
|
||||||
Util.logInfo('message received');
|
Util.logInfo('message received');
|
||||||
Util.logInfo('topic: $topic');
|
Util.logInfo('topic: $topic');
|
||||||
Util.logInfo('payload: $payload');
|
Util.logInfo('mesage: $payload');
|
||||||
|
|
||||||
|
var topicArray = topic!.split('/');
|
||||||
|
var messageType = topicArray[topicArray.length - 1];
|
||||||
|
|
||||||
Map<String, dynamic> messageData = jsonDecode(payload);
|
Map<String, dynamic> messageData = jsonDecode(payload);
|
||||||
|
|
||||||
for (var entry in messageData.keys) {
|
switch(messageType) {
|
||||||
if (entry == 'payload') {
|
case 'session':
|
||||||
var payload = messageData[entry];
|
_sessionMessageReceived(messageData);
|
||||||
for (var payloadEntry in payload.keys) {
|
break;
|
||||||
var payloadData = payload[payloadEntry];
|
|
||||||
|
|
||||||
switch(payloadEntry) {
|
case 'status':
|
||||||
case 'session':
|
_statusMessageReceived(messageData);
|
||||||
_sessionMessageReceived(payloadData);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'status':
|
case 'ranks':
|
||||||
_statusMessageReceived(payloadData);
|
//_rankingMessageReceived(payloadData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ranks':
|
case 'jobs':
|
||||||
_rankingMessageReceived(payloadData);
|
//_jobMessageReceived(payloadData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'jobs':
|
case 'job_del':
|
||||||
_jobMessageReceived(payloadData);
|
//_jobDeleteReceived(payloadData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'job_del':
|
case 'sync_request':
|
||||||
_jobDeleteReceived(payloadData);
|
//_syncRequestReceived(payloadData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sync_request':
|
case "mssg":
|
||||||
_syncRequestReceived(payloadData);
|
//_messageMessageReceived(payloadData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "mssg":
|
default:
|
||||||
_messageMessageReceived(payloadData);
|
Util.logInfo('Unknown topic: $messageType');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
Util.logInfo('Unknown topic: $payloadEntry');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
Util.logException(ex.toString());
|
Util.logException(ex.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_mqttClient.subscribe(_fromServerTopic, MqttQos.exactlyOnce);
|
_mqttClient.subscribe(_fromServerTopic + "/session", MqttQos.exactlyOnce);
|
||||||
|
_mqttClient.subscribe(_fromServerTopic + "/status", MqttQos.exactlyOnce);
|
||||||
Util.logInfo('subscribed to topic: $_fromServerTopic');
|
Util.logInfo('subscribed to topic: $_fromServerTopic');
|
||||||
|
|
||||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
|
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
|
||||||
@@ -355,7 +347,7 @@ class MqttCore {
|
|||||||
|
|
||||||
void _processBootstrap() async {
|
void _processBootstrap() async {
|
||||||
try {
|
try {
|
||||||
var deviceObject = DeviceObject();
|
/*var deviceObject = DeviceObject();
|
||||||
deviceObject.manufacturer = "sven";
|
deviceObject.manufacturer = "sven";
|
||||||
deviceObject.model = "emulator";
|
deviceObject.model = "emulator";
|
||||||
deviceObject.os = "hat es";
|
deviceObject.os = "hat es";
|
||||||
@@ -375,6 +367,10 @@ class MqttCore {
|
|||||||
var response = await http.get(Uri.parse(uri));
|
var response = await http.get(Uri.parse(uri));
|
||||||
var responseText = response.body;
|
var responseText = response.body;
|
||||||
|
|
||||||
|
Util.logInfo("Bootstrap response: $responseText");*/
|
||||||
|
|
||||||
|
var responseText = await rootBundle.loadString('assets/json/bootstrap_response.json');
|
||||||
|
|
||||||
var bootstrapResponsePayload = BootstrapResponsePayload.fromJson(jsonDecode(responseText)["payload"]);
|
var bootstrapResponsePayload = BootstrapResponsePayload.fromJson(jsonDecode(responseText)["payload"]);
|
||||||
|
|
||||||
var brokerUriAndPortArray = bootstrapResponsePayload.config.broker.replaceFirst("mqtt://", "").split(":");
|
var brokerUriAndPortArray = bootstrapResponsePayload.config.broker.replaceFirst("mqtt://", "").split(":");
|
||||||
@@ -390,28 +386,14 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_initSession() {
|
_initSession() {
|
||||||
var playload = Payload();
|
|
||||||
playload.startSession = "true";
|
|
||||||
|
|
||||||
var startSessionMessage = StartSessionMessage();
|
var startSessionMessage = StartSessionMessage();
|
||||||
startSessionMessage.recv = "server";
|
startSessionMessage.startSession = true;
|
||||||
startSessionMessage.store = true;
|
|
||||||
startSessionMessage.messageId = const Uuid().v4();
|
var topic = "$_toServerTopic/session";
|
||||||
startSessionMessage.payload = playload;
|
|
||||||
|
|
||||||
var jsonMap = startSessionMessage.toJson();
|
var jsonMap = startSessionMessage.toJson();
|
||||||
var json = jsonEncode(jsonMap);
|
var json = jsonEncode(jsonMap);
|
||||||
Util.logInfo("send start session json: $json");
|
publishText(topic, json);
|
||||||
|
|
||||||
final builder = MqttClientPayloadBuilder();
|
|
||||||
builder.addString(json);
|
|
||||||
var payload = builder.payload;
|
|
||||||
|
|
||||||
var topic = "$_toServerTopic/init";
|
|
||||||
Util.logInfo("send start session json to topic: $topic");
|
|
||||||
|
|
||||||
var messageId = _mqttClient.publishMessage(topic, MqttQos.exactlyOnce, payload!);
|
|
||||||
Util.logInfo("send start session json with messageId: $messageId");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendSyncMessage() async
|
_sendSyncMessage() async
|
||||||
@@ -430,21 +412,21 @@ class MqttCore {
|
|||||||
answer.sync.jobs.add(syncJob);
|
answer.sync.jobs.add(syncJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage("server", answer.toJson());
|
MqttCore.instance.publishText("/appserver/to_server/100/1/104400/sync", jsonEncode(answer.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startTrackTimer() {
|
void _startTrackTimer() {
|
||||||
_trackTimer ??= Timer.periodic(const Duration(seconds: 60), (Timer t) {
|
_trackTimer ??= Timer.periodic(const Duration(seconds: 60), (Timer t) {
|
||||||
var position = MyApp.currentPosition;
|
var answer = MyApp.currentPosition;
|
||||||
if (position != null) {
|
if (answer != null) {
|
||||||
var trackMessage = TrackMessage();
|
var trackMessage = TrackMessage();
|
||||||
trackMessage.pos = TrackPosition();
|
trackMessage.pos = TrackPosition();
|
||||||
trackMessage.pos.time = position.timestamp.toIso8601String();
|
trackMessage.pos.time = answer.timestamp.toIso8601String();
|
||||||
trackMessage.pos.lat = position.latitude;
|
trackMessage.pos.lat = answer.latitude;
|
||||||
trackMessage.pos.long = position.longitude;
|
trackMessage.pos.long = answer.longitude;
|
||||||
trackMessage.pos.acc = position.accuracy.toInt();
|
trackMessage.pos.acc = answer.accuracy.toInt();
|
||||||
|
|
||||||
publishPayloadMessage("track", trackMessage.toJson());
|
publishText("/appserver/to_server/100/1/104400/track", jsonEncode(answer.toJson()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ flutter:
|
|||||||
assets:
|
assets:
|
||||||
- assets/
|
- assets/
|
||||||
- assets/sounds/
|
- assets/sounds/
|
||||||
|
- assets/json/
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
|
|||||||
Reference in new issue
Block a user