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
|
||||
@JsonSerializable()
|
||||
class Status {
|
||||
late Id? id;
|
||||
@JsonKey(name: "id", defaultValue: 0)
|
||||
Id? id;
|
||||
|
||||
late StatusPos pos;
|
||||
|
||||
|
||||
@@ -789,7 +789,7 @@ extension StatusPosQueryObject
|
||||
// **************************************************************************
|
||||
|
||||
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>);
|
||||
|
||||
Map<String, dynamic> _$StatusToJson(Status instance) => <String, dynamic>{
|
||||
|
||||
@@ -6,15 +6,7 @@ part 'start_session_message.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class StartSessionMessage {
|
||||
Id get isarId => Util.fastHash(messageId);
|
||||
|
||||
late String recv;
|
||||
|
||||
late bool store;
|
||||
|
||||
late String messageId;
|
||||
|
||||
late Payload payload;
|
||||
late bool startSession;
|
||||
|
||||
StartSessionMessage();
|
||||
|
||||
@@ -22,15 +14,3 @@ class StartSessionMessage {
|
||||
|
||||
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()
|
||||
..recv = json['recv'] as String
|
||||
..store = json['store'] as bool
|
||||
..messageId = json['messageId'] as String
|
||||
..payload = Payload.fromJson(json['payload'] as Map<String, dynamic>);
|
||||
StartSessionMessage()..startSession = json['startSession'] as bool;
|
||||
|
||||
Map<String, dynamic> _$StartSessionMessageToJson(
|
||||
StartSessionMessage instance) =>
|
||||
<String, dynamic>{
|
||||
'recv': instance.recv,
|
||||
'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,
|
||||
'startSession': instance.startSession,
|
||||
};
|
||||
+50
-68
@@ -2,15 +2,13 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:mqtt_client/mqtt_client.dart';
|
||||
import 'package:mqtt_client/mqtt_server_client.dart';
|
||||
import 'package:stadtbote/model/ranking.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/device_object.dart';
|
||||
import 'package:stadtbote/model/job.dart';
|
||||
import 'package:stadtbote/model/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';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:typed_data/typed_buffers.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../main.dart';
|
||||
@@ -137,7 +134,7 @@ class MqttCore {
|
||||
|
||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||
|
||||
Util.logInfo("message $text send to $topic");
|
||||
Util.logInfo("send message $text to $topic");
|
||||
} catch (e) {
|
||||
Util.logException(e.toString());
|
||||
}
|
||||
@@ -170,58 +167,53 @@ class MqttCore {
|
||||
|
||||
Util.logInfo('message received');
|
||||
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);
|
||||
|
||||
for (var entry in messageData.keys) {
|
||||
if (entry == 'payload') {
|
||||
var payload = messageData[entry];
|
||||
for (var payloadEntry in payload.keys) {
|
||||
var payloadData = payload[payloadEntry];
|
||||
switch(messageType) {
|
||||
case 'session':
|
||||
_sessionMessageReceived(messageData);
|
||||
break;
|
||||
|
||||
switch(payloadEntry) {
|
||||
case 'session':
|
||||
_sessionMessageReceived(payloadData);
|
||||
break;
|
||||
case 'status':
|
||||
_statusMessageReceived(messageData);
|
||||
break;
|
||||
|
||||
case 'status':
|
||||
_statusMessageReceived(payloadData);
|
||||
break;
|
||||
case 'ranks':
|
||||
//_rankingMessageReceived(payloadData);
|
||||
break;
|
||||
|
||||
case 'ranks':
|
||||
_rankingMessageReceived(payloadData);
|
||||
break;
|
||||
case 'jobs':
|
||||
//_jobMessageReceived(payloadData);
|
||||
break;
|
||||
|
||||
case 'jobs':
|
||||
_jobMessageReceived(payloadData);
|
||||
break;
|
||||
case 'job_del':
|
||||
//_jobDeleteReceived(payloadData);
|
||||
break;
|
||||
|
||||
case 'job_del':
|
||||
_jobDeleteReceived(payloadData);
|
||||
break;
|
||||
case 'sync_request':
|
||||
//_syncRequestReceived(payloadData);
|
||||
break;
|
||||
|
||||
case 'sync_request':
|
||||
_syncRequestReceived(payloadData);
|
||||
break;
|
||||
case "mssg":
|
||||
//_messageMessageReceived(payloadData);
|
||||
break;
|
||||
|
||||
case "mssg":
|
||||
_messageMessageReceived(payloadData);
|
||||
break;
|
||||
|
||||
default:
|
||||
Util.logInfo('Unknown topic: $payloadEntry');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
Util.logInfo('Unknown topic: $messageType');
|
||||
break;
|
||||
}
|
||||
} catch(ex) {
|
||||
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');
|
||||
|
||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
|
||||
@@ -355,7 +347,7 @@ class MqttCore {
|
||||
|
||||
void _processBootstrap() async {
|
||||
try {
|
||||
var deviceObject = DeviceObject();
|
||||
/*var deviceObject = DeviceObject();
|
||||
deviceObject.manufacturer = "sven";
|
||||
deviceObject.model = "emulator";
|
||||
deviceObject.os = "hat es";
|
||||
@@ -375,6 +367,10 @@ class MqttCore {
|
||||
var response = await http.get(Uri.parse(uri));
|
||||
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 brokerUriAndPortArray = bootstrapResponsePayload.config.broker.replaceFirst("mqtt://", "").split(":");
|
||||
@@ -390,28 +386,14 @@ class MqttCore {
|
||||
}
|
||||
|
||||
_initSession() {
|
||||
var playload = Payload();
|
||||
playload.startSession = "true";
|
||||
|
||||
var startSessionMessage = StartSessionMessage();
|
||||
startSessionMessage.recv = "server";
|
||||
startSessionMessage.store = true;
|
||||
startSessionMessage.messageId = const Uuid().v4();
|
||||
startSessionMessage.payload = playload;
|
||||
startSessionMessage.startSession = true;
|
||||
|
||||
var topic = "$_toServerTopic/session";
|
||||
|
||||
var jsonMap = startSessionMessage.toJson();
|
||||
var json = jsonEncode(jsonMap);
|
||||
Util.logInfo("send start session json: $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");
|
||||
publishText(topic, json);
|
||||
}
|
||||
|
||||
_sendSyncMessage() async
|
||||
@@ -430,21 +412,21 @@ class MqttCore {
|
||||
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() {
|
||||
_trackTimer ??= Timer.periodic(const Duration(seconds: 60), (Timer t) {
|
||||
var position = MyApp.currentPosition;
|
||||
if (position != null) {
|
||||
var answer = MyApp.currentPosition;
|
||||
if (answer != null) {
|
||||
var trackMessage = TrackMessage();
|
||||
trackMessage.pos = TrackPosition();
|
||||
trackMessage.pos.time = position.timestamp.toIso8601String();
|
||||
trackMessage.pos.lat = position.latitude;
|
||||
trackMessage.pos.long = position.longitude;
|
||||
trackMessage.pos.acc = position.accuracy.toInt();
|
||||
trackMessage.pos.time = answer.timestamp.toIso8601String();
|
||||
trackMessage.pos.lat = answer.latitude;
|
||||
trackMessage.pos.long = answer.longitude;
|
||||
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/sounds/
|
||||
- assets/json/
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
|
||||
Reference in new issue
Block a user