Skip to content

Commit

Permalink
get ip with the rest of creds
Browse files Browse the repository at this point in the history
  • Loading branch information
dazemc committed May 6, 2024
1 parent 2c40a9b commit e5501b6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 42 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cSpell.words": [
"creds",
"getx",
"Getx",
"Hotspot",
"keymgmt",
"localip",
"mgmt",
"wipi"
]
}
25 changes: 18 additions & 7 deletions lib/controllers/wipi_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wipi/models/saved_connections.dart';

const String baseUrl = 'http://192.168.0.174/';
const String baseUrl = 'http://192.168.6.9/';
const String showConnections = '${baseUrl}rec_creds?show_connections';
const String showCredentials = '${baseUrl}rec_creds?show_credentials=';
const String deleteCredentials = '${baseUrl}rec_creds?delete_credentials=';
Expand All @@ -22,6 +23,7 @@ class WiPiController extends GetxController {
final displaySsid = "".obs;
final displayPass = "".obs;
final displayKeymgmt = "".obs;
final displayIpAddr = "".obs;
bool connected = false;

void fetchSavedConnections() async {
Expand All @@ -38,31 +40,40 @@ class WiPiController extends GetxController {
getDeleteColor();
final response = await getx.get("$showCredentials${wifiInfo.value}");
creds = response.body;
if (kDebugMode) {
print(creds);
}
for (String key in creds.keys) {
displayConnections = {
key: Connection(
ssid: creds[key]["ssid"],
keymgmt: creds[key]["key-mgmt"],
psk: creds[key]["psk"])
ssid: creds[key]["ssid"],
keymgmt: creds[key]["key-mgmt"],
psk: creds[key]["psk"],
localip: creds[key]["local-ip"],
),
};
}
displayCredentials();
}

void postCredentials() async {
// print('Sending Credentials');
await Future.delayed(const Duration(seconds: 10));
final response =
await getx.post(sendCredentials, {"SSID": ssid, "PASS": pass});
if (response.body == "Connected") {
connected = true;
fetchSavedConnections();
if (kDebugMode) {
print(response.body);
}
// displayIpAddr.value = response.body["local_ip"];
// connected = true;
fetchSavedConnections();
}

void displayCredentials() {
displaySsid.value = displayConnections[wifiInfo.value]!.ssid;
displayKeymgmt.value = displayConnections[wifiInfo.value]!.keymgmt;
displayPass.value = displayConnections[wifiInfo.value]!.psk;
displayIpAddr.value = displayConnections[wifiInfo.value]!.localip;
}

void removeCredentials(connection) async {
Expand Down
10 changes: 6 additions & 4 deletions lib/models/saved_connections.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class Connection {
final String ssid;
final String keymgmt;
final String psk;
late final String ssid;
late final String keymgmt;
late final String psk;
late final String localip;

const Connection({
Connection({
required this.ssid,
required this.keymgmt,
required this.psk,
required this.localip,
});
}
20 changes: 19 additions & 1 deletion lib/views/wipi_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class WiPiHome extends StatelessWidget {
),
child: DropdownButton(
hint: const Text(
'Choose SSID',
style: TextStyle(
color: Colors.white,
),
'Cannot find device',
),
onChanged: (newValue) {
wipiController.wifiInfo(newValue);
Expand Down Expand Up @@ -120,6 +123,21 @@ class WiPiHome extends StatelessWidget {
),
),
),
Card(
color: Colors.black,
child: Container(
margin: const EdgeInsets.all(0),
child: ListTile(
shape: const RoundedRectangleBorder(),
tileColor: Colors.grey[800],
title: Text(
style: const TextStyle(color: Colors.white),
wipiController.displayIpAddr.value),
leading: const Text(
style: TextStyle(color: Colors.white), "local_ip: "),
),
),
),
],
),
),
Expand Down
30 changes: 0 additions & 30 deletions test/widget_test.dart

This file was deleted.

0 comments on commit e5501b6

Please sign in to comment.