Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt #91

Closed
wants to merge 2 commits into from
Closed

Mqtt #91

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified android/app/src/main/res/drawable-hdpi/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/drawable-mdpi/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/drawable-v21/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<item>
<bitmap android:gravity="center" android:src="@drawable/splash"/>
</item>
</layer-list>
</layer-list>
Binary file modified android/app/src/main/res/drawable-xhdpi/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/drawable-xxhdpi/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/drawable-xxxhdpi/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/drawable/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion android/app/src/main/res/drawable/launch_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<item>
<bitmap android:gravity="center" android:src="@drawable/splash"/>
</item>
</layer-list>
</layer-list>
19 changes: 19 additions & 0 deletions android/app/src/main/res/values-night-v31/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:forceDarkAllowed">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
4 changes: 4 additions & 0 deletions android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:forceDarkAllowed">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Expand Down
19 changes: 19 additions & 0 deletions android/app/src/main/res/values-v31/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:forceDarkAllowed">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
5 changes: 4 additions & 1 deletion android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:forceDarkAllowed">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Expand All @@ -16,4 +19,4 @@
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
</resources>
23 changes: 0 additions & 23 deletions ios/Runner/Assets.xcassets/BrandingImage.imageset/Contents.json

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Runner/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
<image name="LaunchImage" width="1024" height="1024"/>
<image name="LaunchBackground" width="1" height="1"/>
</resources>
</document>
</document>
2 changes: 1 addition & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
<key>UIStatusBarHidden</key>
<false/>
</dict>
</plist>
</plist>
12 changes: 6 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ class MyApp extends StatelessWidget {
brightness: Brightness.light,
),
textTheme: const TextTheme(
headline1: TextStyle(
displayLarge: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
fontSize: 32,
color: Color(0xFF464646),
),
headline2: TextStyle(
displayMedium: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w700,
fontSize: 18,
color: Color(0xFF464646),
),
headline3: TextStyle(
displaySmall: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: 18,
color: Color(0xFF464646),
),
headline4: TextStyle(
headlineMedium: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: 18,
color: Color(0xFFBDBDBD),
),
headline5: TextStyle(
headlineSmall: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: 12,
color: Color(0xFFBDBDBD),
),
headline6: TextStyle(
titleLarge: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w400,
fontSize: 14,
Expand Down
118 changes: 118 additions & 0 deletions lib/mqtt/mqtt.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import 'dart:convert';
import 'dart:ffi';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:mqtt_client/mqtt_server_client.dart';

class MqttHandler with ChangeNotifier {
final ValueNotifier<String> data = ValueNotifier<String>("");
late MqttServerClient client;

Future<Object> connect() async {
client = MqttServerClient.withPort(
'broker.hivemq.com', 'smartpump239834893453920938', 1883);
client.logging(on: true);
client.onConnected = onConnected;
client.onDisconnected = onDisconnected;
client.onUnsubscribed = onUnsubscribed;
client.onSubscribed = onSubscribed;
client.onSubscribeFail = onSubscribeFail;
client.pongCallback = pong;
client.keepAlivePeriod = 60;
client.logging(on: true);

/// Set the correct MQTT protocol for mosquito
client.setProtocolV311();

final connMessage = MqttConnectMessage()
.withWillTopic('willtopic')
.withWillMessage('Will message')
.startClean()
.withWillQos(MqttQos.atLeastOnce);

print('MQTT_LOGS::Mosquitto client connecting....');

client.connectionMessage = connMessage;
try {
await client.connect();
} catch (e) {
print('Exception: $e');
client.disconnect();
}

if (client.connectionStatus!.state == MqttConnectionState.connected) {
print('MQTT_LOGS::Mosquitto client connected');
} else {
print(
'MQTT_LOGS::ERROR Mosquitto client connection failed - disconnecting, status is ${client.connectionStatus}');
client.disconnect();
return -1;
}

//wil be used to determine water tank status
print('MQTT_LOGS::Subscribing to the pump/current topic');
const topic = 'pump/current';
client.subscribe(topic, MqttQos.atMostOnce);

client.updates!.listen((List<MqttReceivedMessage<MqttMessage?>>? c) {
final recMess = c![0].payload as MqttPublishMessage;
final pt =
MqttPublishPayload.bytesToStringAsString(recMess.payload.message);

data.value = pt;
notifyListeners();
print(
'MQTT_LOGS:: New data arrived: topic is <${c[0].topic}>, payload is $pt');
print('');
});

return client;
}

void onConnected() {
print('MQTT_LOGS:: Connected');
}

void onDisconnected() {
print('MQTT_LOGS:: Disconnected');
}

void onSubscribed(String topic) {
print('MQTT_LOGS:: Subscribed topic: $topic');
}

void onSubscribeFail(String topic) {
print('MQTT_LOGS:: Failed to subscribe $topic');
}

void onUnsubscribed(String? topic) {
print('MQTT_LOGS:: Unsubscribed topic: $topic');
}

void pong() {
print('MQTT_LOGS:: Ping response client callback invoked');
}

void pumpTrigger(bool state) {
const pubTopic = 'trigger/pump';
final builder = MqttClientPayloadBuilder();
builder.addBool(val: state);
if (client.connectionStatus?.state == MqttConnectionState.connected) {
client.publishMessage(pubTopic, MqttQos.atMostOnce, builder.payload!);
}
}

void updateConfig(String nextRun, UnsignedInt duration, bool auto) {
const pubTopic = 'update/config';
final builder = MqttClientPayloadBuilder();
builder.addString(jsonEncode({
"next_run": nextRun,
"interval": duration,
"auto": auto,
}));
if (client.connectionStatus?.state == MqttConnectionState.connected) {
client.publishMessage(pubTopic, MqttQos.atMostOnce, builder.payload!);
}
}
}
6 changes: 3 additions & 3 deletions lib/popups/popup_widgets/popup_filled_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class PopupFilledButton extends StatelessWidget {
Widget build(BuildContext context) {
return TextButton(
onPressed: onPressed,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(const Color(0xFF464646)),
),
child: Text(
text,
style: const TextStyle(color: Colors.white),
),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(const Color(0xFF464646)),
),
);
}
}
8 changes: 4 additions & 4 deletions lib/popups/popup_widgets/popup_outlined_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class PopupOutlinedButton extends StatelessWidget {
Widget build(BuildContext context) {
return OutlinedButton(
onPressed: onPressed,
child: Text(
text,
style: const TextStyle(color: Color(0xFF464646)),
),
style: ButtonStyle(
side: MaterialStateProperty.all(
const BorderSide(
Expand All @@ -26,6 +22,10 @@ class PopupOutlinedButton extends StatelessWidget {
),
),
),
child: Text(
text,
style: const TextStyle(color: Color(0xFF464646)),
),
);
}
}
6 changes: 3 additions & 3 deletions lib/src/screens/about_screen/about_us_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class AboutUs extends StatelessWidget {
trailing: SvgPicture.asset('assets/icons/svg/info.svg')
// Icon(Icons.info, color: Colors.black, size: 32,),
),
Padding(
padding: const EdgeInsets.only(top: 12),
const Padding(
padding: EdgeInsets.only(top: 12),
child: Center(child: Column(
children: const [
children: [
Text('Domus',style: TextStyle(fontFamily: 'Lexend',
fontSize: 48,
fontWeight: FontWeight.w700
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/edit_profile/components/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class _UploadImageState extends State<UploadImage> {
getImageFromGallery();
},
child: ClipRRect(
borderRadius: BorderRadius.circular(35),
child: Image.file(
_image!,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(35),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FavouriteTile extends StatelessWidget {
Text(
device,
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.headline2!.copyWith(
style: Theme.of(context).textTheme.displayMedium!.copyWith(
color: Colors.black,
// color: itsOn ? Colors.white : Colors.black,
),
Expand All @@ -84,6 +84,7 @@ class FavouriteTile extends StatelessWidget {
width: getProportionateScreenWidth(100),
),
GestureDetector(
onTap: switchButton,
child: Container(
width: 48,
height: 25.6,
Expand Down Expand Up @@ -113,7 +114,6 @@ class FavouriteTile extends StatelessWidget {
],
),
),
onTap: switchButton,
),
const SizedBox(width: 15,)
],
Expand Down Expand Up @@ -141,7 +141,7 @@ class FavouriteTile extends StatelessWidget {
Text(
itsOn ? 'On' : 'Off',
textAlign: TextAlign.left,
style: Theme.of(context).textTheme.headline2!.copyWith(
style: Theme.of(context).textTheme.displayMedium!.copyWith(
color: Colors.black,
// color: itsOn ? Colors.white : Colors.black,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/favourites_screen/favourites_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _FavouritesState extends State<Favourites> {
children: [
Text(
'Favourites',
style: Theme.of(context).textTheme.headline1,
style: Theme.of(context).textTheme.displayLarge,
),
Container(
width: 50,
Expand Down
Loading
Loading