Skip to content

Commit

Permalink
Added some style on MQTT screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kekko7072 committed Feb 21, 2023
1 parent f69bf6e commit d65b862
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
34 changes: 31 additions & 3 deletions app/lib/interfaces/screens/track_mqtt_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,40 @@ class _TrackMQTTScreenState extends State<TrackMQTTScreen> {
'CONNECTED: ${widget.client.connectionStatus!.state == MqttConnectionState.connected}'),
Text(
'MESSAGES: ${widget.client.connectionStatus!.state == MqttConnectionState.connected}'),
StreamBuilder<MqttPublishMessage>(
StreamBuilder<MqttPublishMessage?>(
stream: widget.client.published,
builder: (context, snapshot) {
MqttPublishMessage? message = snapshot.data;

String messageTopic = message?.variableHeader?.topicName ?? '';

print(message?.variableHeader?.topicName);

///PARSING INFO
if (messageTopic == widget.mqttService.topicsDevice[0]) {
debugPrint(widget.mqttService.topicsDevice[0]);
print(String.fromCharCodes(snapshot.data!.payload.message));
} else if (messageTopic == widget.mqttService.topicsDevice[1]) {
debugPrint(widget.mqttService.topicsDevice[1]);
print(String.fromCharCodes(snapshot.data!.payload.message));
} else if (messageTopic == widget.mqttService.topicsDevice[2]) {
debugPrint(widget.mqttService.topicsDevice[2]);
print(String.fromCharCodes(snapshot.data!.payload.message));
} else if (messageTopic == widget.mqttService.topicsDevice[3]) {
debugPrint(widget.mqttService.topicsDevice[3]);
print(String.fromCharCodes(snapshot.data!.payload.message));
} else if (messageTopic == widget.mqttService.topicsDevice[4]) {
debugPrint(widget.mqttService.topicsDevice[4]);
print(String.fromCharCodes(snapshot.data!.payload.message));
} else {
debugPrint("NOT FOUND MATCHING!");
}

return Column(
children: [
Text(
'Topic: ${snapshot.data?.variableHeader?.topicName}\nMessage: ${snapshot.data?.payload.message != null ? String.fromCharCodes(snapshot.data!.payload.message) : 'ND'}\n'),
Row(
/* Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
Expand Down Expand Up @@ -101,7 +127,7 @@ class _TrackMQTTScreenState extends State<TrackMQTTScreen> {
),
),
],
),
),*/
],
);
}),
Expand All @@ -111,6 +137,8 @@ class _TrackMQTTScreenState extends State<TrackMQTTScreen> {
widget.mqttService.unsubscribeToAllTopic();

widget.mqttService.disconnect();

Navigator.of(context).pop();
}),
],
);
Expand Down
4 changes: 4 additions & 0 deletions app/lib/interfaces/screens/track_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ class _TrackScreenState extends State<TrackScreen> {
child: CupertinoButton.filled(
child: const Text('CONNECT TO MQTT'),
onPressed: () async {
EasyLoading.show();

client = MqttServerClient(serverController.text, '');
mqttService =
MQTTService(client, deviceIdController.text);
Expand All @@ -354,6 +356,8 @@ class _TrackScreenState extends State<TrackScreen> {
mqttService.subscribeToAllTopic();
}

EasyLoading.dismiss();

await UnitsSystem.loadFromSettings().then(
(unitsSystem) => Navigator.of(context).push(
MaterialPageRoute(builder: (context) {
Expand Down
22 changes: 7 additions & 15 deletions app/lib/services/mqtt_service.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import 'imports.dart';

enum TopicDevice {
SYSTEM,
GPS_POSITION,
GPS_NAVIGATION,
MPU_ACCELERATION,
MPU_GYROSCOPE
}

class MQTTService {
final MqttServerClient client;
final String deviceId;
MQTTService(this.client, this.deviceId);

///TOPICS
late List<String> topicsDevice = [
'$deviceId/SYSTEM',
'$deviceId/GPS_POSITION',
'$deviceId/GPS_NAVIGATION',
'$deviceId/MPU_ACCELERATION',
'$deviceId/MPU_GYROSCOPE'
];
List<String> get topicsDevice => [
'$deviceId/SYSTEM',
'$deviceId/GPS_POSITION',
'$deviceId/GPS_NAVIGATION',
'$deviceId/MPU_ACCELERATION',
'$deviceId/MPU_GYROSCOPE'
];

String topicsPath(String topic) => '$deviceId/$topic';

Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
provider: ^6.0.5
path_provider: ^2.0.12
uuid: ^3.0.7
syncfusion_flutter_maps: ^20.4.50
syncfusion_flutter_maps: ^20.4.51
file_picker: ^5.2.5
http: ^0.13.5
flutter_libserialport: ^0.3.0
Expand Down

0 comments on commit d65b862

Please sign in to comment.