Skip to content

Commit 0831a69

Browse files
committed
addedwifibuttons
1 parent 5d4a3bc commit 0831a69

3 files changed

Lines changed: 65 additions & 11 deletions

File tree

app/lib/app_states/main_app_state.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ class MainAppState extends ChangeNotifier { // contains most of the app state in
4040
String distanceValue = "N/A";
4141
double distance =0;
4242
List<int> distancehist = [];
43+
44+
bool isWifiConnected = false;
45+
46+
void handleRobotStatus(String message) {
47+
if (message.contains("N#101#") || message.contains("N#301#")) {
48+
isWifiConnected = true;
49+
notifyListeners(); // This tells VideoLogPage to rebuild and show the camera!
50+
} else if (message.contains("N#102#") || message.contains("N#302#")) {
51+
isWifiConnected = false;
52+
notifyListeners();
53+
}
54+
}
4355

4456
void updateJoystick(double newX, double newY) {
4557
x = newX;

app/lib/pages/layout_pages/main_pages/video_log_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _VideoLogPageState extends State<VideoLogPage> {
6161
child: Center(
6262
child: MJPEGStreamScreen(
6363
//Robot video feed
64-
streamUrl: "http://yasmines-iphone.local:8081/video",
64+
streamUrl: "http://192.168.1.154.x:8000", //IP address of the robot
6565
showLiveIcon: true,
6666
width: 900.0,
6767
height: 600.0,

app/lib/pages/setup_pages/wifi_page.dart

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,66 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
33
import '../../app_states/ble_app_state.dart';
4+
import 'dart:convert';
5+
6+
import 'package:robot_app/ble_files/services/ble_connection/ble_interface.dart';
7+
import '../../ble_files/widgets/ble_connect_button.dart';
8+
import '../../ble_files/services/robot_profiles.dart';
9+
410

5-
// Wifi has not been implemented, this page just contains a button that toggles wifi state and has no real backend
611

12+
// Wifi has not been implemented, this page just contains a button that toggles wifi state and has no real backend
713
class WifiPage extends StatelessWidget {
814
const WifiPage({super.key});
915

1016
@override
1117
Widget build(BuildContext context) {
18+
// You need to grab the bleDriver from the provider to use it inside the button
19+
final bleDriver = context.read<BleInterface>();
20+
final TextEditingController _ssidController = TextEditingController();
21+
final TextEditingController _passController = TextEditingController();
22+
1223
return Center(
13-
child: SizedBox(
14-
width: 180,
15-
height: 60,
16-
child: ElevatedButton(
17-
onPressed: () {
18-
context.read<AppState>().toggleWifi();
19-
},
20-
child: const Text('Toggle WiFi', style: TextStyle(fontSize: 18)),
21-
),
24+
child: Column( // Use a Column so buttons don't overlap in the SizedBox
25+
mainAxisAlignment: MainAxisAlignment.center,
26+
children: [
27+
TextField(//Text field where you input the ssid of the wifi
28+
controller: _ssidController,
29+
decoration: InputDecoration(labelText: 'Wi-Fi Name (SSID)'),
30+
),
31+
TextField(//Text where you input the wifi password
32+
controller: _passController,
33+
obscureText: true,
34+
decoration: InputDecoration(labelText: 'Password'),
35+
),
36+
SizedBox(
37+
width: 250,
38+
height: 60,
39+
child: ElevatedButton(
40+
onPressed: () {
41+
context.read<AppState>().toggleWifi();
42+
},
43+
child: const Text('Toggle App State WiFi', style: TextStyle(fontSize: 18)),
44+
),
45+
),
46+
const SizedBox(height: 20),
47+
SizedBox(
48+
width: 250,
49+
height: 60,
50+
child: ElevatedButton(
51+
onPressed: () async { // Fixed the syntax: onPressed: () async { ... }
52+
try {
53+
// This command tells the robot to start a Wi-Fi Scan
54+
await bleDriver.writeToCharacteristic(utf8.encode('N#1#${_ssidController.text}#${_passController.text}#'));
55+
debugPrint("Wi-Fi Scan Command Sent!");
56+
} catch (e) {
57+
debugPrint("BLE Write Error: $e");
58+
}
59+
},
60+
child: const Text('Send Wifi info to Robot'),
61+
),
62+
),
63+
],
2264
),
2365
);
2466
}

0 commit comments

Comments
 (0)