Merge pull request #1 from oob-provisioning-for-iot/justin
fixing Bluetooth and refactor many files
18
README.md
|
@ -1,9 +1,25 @@
|
|||
# flutter_provisioning_for_iot
|
||||
|
||||
##Flutter Setup
|
||||
## Flutter Setup
|
||||
|
||||
Windows installation guide: <br>
|
||||
https://docs.flutter.dev/get-started/install/windows
|
||||
<br>
|
||||
Linux installation guide: <br>
|
||||
https://docs.flutter.dev/get-started/install/linux
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
<br>
|
||||
To build this projekt with windows be sure to set in <br>
|
||||
settings -> windows security -> for developers -> developer mode -> on
|
|
@ -58,6 +58,9 @@ android {
|
|||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
// needed to fix bluetooth scan
|
||||
shrinkResources false
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,5 +70,5 @@ flutter {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
}
|
|
@ -3,8 +3,11 @@
|
|||
package="com.example.flutter_provisioning_for_iot">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<!-- Needed to communicate with already-paired Bluetooth devices. (Android 12 upwards)-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<application
|
||||
android:label="flutter_provisioning_for_iot"
|
||||
android:name="${applicationName}"
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 544 B |
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 442 B |
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 721 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"username": "...",
|
||||
"password": "...",
|
||||
"address": "..."
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
# flutter_provisioning_for_iot
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
<br>
|
||||
To build this projekt with windows be sure to set in <br>
|
||||
settings -> windows security -> for developers -> developer mode -> on
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'Sidebar.dart';
|
||||
|
||||
class BluetoothTest extends StatefulWidget {
|
||||
const BluetoothTest({super.key});
|
||||
|
||||
@override
|
||||
State<BluetoothTest> createState() => _BluetoothTest();
|
||||
}
|
||||
|
||||
class _BluetoothTest extends State<BluetoothTest> {
|
||||
FlutterBlue flutterBlue = FlutterBlue.instance;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Bluetooth Test"),
|
||||
),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
var subscription = flutterBlue.scanResults.listen((results) {
|
||||
// do something with scan results
|
||||
for (ScanResult r in results) {
|
||||
String scan = '"${r.device.name} found! rssi: ${r.rssi}"';
|
||||
debugPrint(scan);
|
||||
}
|
||||
});
|
||||
// Stop scanning
|
||||
flutterBlue.stopScan();
|
||||
|
||||
}, child: const Text("Scan Devices"),
|
||||
),
|
||||
),
|
||||
drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter_provisioning_for_iot/MainPage.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MainPage());
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
}
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 564 B After Width: | Height: | Size: 564 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 68 B |
Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 68 B |
Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 68 B |
|
@ -0,0 +1,49 @@
|
|||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'sidebar.dart';
|
||||
|
||||
class BluetoothTest extends StatefulWidget {
|
||||
const BluetoothTest({super.key});
|
||||
|
||||
@override
|
||||
State<BluetoothTest> createState() => _BluetoothTest();
|
||||
}
|
||||
|
||||
class _BluetoothTest extends State<BluetoothTest> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Bluetooth Test"),
|
||||
),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
|
||||
FlutterBlue flutterBlue = FlutterBlue.instance;
|
||||
flutterBlue.startScan(timeout: const Duration(seconds: 4));
|
||||
|
||||
flutterBlue.scanResults.listen((results) async {
|
||||
// do something with scan results
|
||||
for (ScanResult r in results) {
|
||||
String scan = '"scan: ${r.device.name} found! rssi: ${r
|
||||
.rssi}"';
|
||||
debugPrint(scan);
|
||||
if(r.device.name == "Crusher ANC") {
|
||||
await r.device.connect();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Stop scanning
|
||||
flutterBlue.stopScan();
|
||||
|
||||
}, child: const Text("Scan Devices"),
|
||||
),
|
||||
),
|
||||
drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> readJson() async {
|
||||
final data = await rootBundle.loadString('config/credentials.json');
|
||||
var data_ = json.decode(data) as Map<String, dynamic>;
|
||||
debugPrint(data_.toString());
|
||||
return data_;
|
||||
}
|
||||
|
||||
class CloudServiceAPI{
|
||||
late final Map<String, dynamic> credentials;
|
||||
late Future loadJson;
|
||||
late String basicAuth;
|
||||
late String address;
|
||||
late Map<String, String> headers;
|
||||
|
||||
CloudServiceAPI() {
|
||||
loadJson = loadConfig();
|
||||
}
|
||||
|
||||
Future loadConfig() async{
|
||||
credentials = await readJson();
|
||||
String username = credentials['username'];
|
||||
String password = credentials['password'];
|
||||
address = credentials['address'];
|
||||
basicAuth = 'Basic ${base64.encode(utf8.encode('$username:$password'))}';
|
||||
headers = {
|
||||
'authorization': basicAuth,
|
||||
'content-type': 'application/json',
|
||||
'accept': 'application/json'
|
||||
};
|
||||
}
|
||||
Future<List> getDevices() async {
|
||||
var url = Uri.https(address, '/api/devices');
|
||||
Response r = await get(url, headers: headers);
|
||||
return json.decode(r.body) as List<dynamic>;
|
||||
}
|
||||
Future<Map<String, dynamic>> getDeviceInfo(deviceID) async {
|
||||
var url = Uri.https(address, '/api/devices/$deviceID');
|
||||
Response r = await get(url, headers: headers);
|
||||
return json.decode(r.body) as Map<String, dynamic>;
|
||||
}
|
||||
Future<Map<String, dynamic>> getInformation() async {
|
||||
var url = Uri.https(address, '/api/app');
|
||||
Response r = await get(url, headers: headers);
|
||||
return json.decode(r.body) as Map<String, dynamic>;
|
||||
}
|
||||
Future<bool> createDevice(
|
||||
id,
|
||||
primaryThumbprint,
|
||||
secondaryThumbprint) async{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
import 'cloud_service_api.dart';
|
||||
import 'sidebar.dart';
|
||||
|
||||
|
||||
class CloudService extends StatefulWidget {
|
||||
const CloudService({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CloudService> createState() => _CloudService();
|
||||
|
||||
}
|
||||
Future<Map<String, dynamic>> readJson() async {
|
||||
final data = await rootBundle.loadString('config/credentials.json');
|
||||
var data_ = json.decode(data) as Map<String, dynamic>;
|
||||
debugPrint(data_.toString());
|
||||
return data_;
|
||||
}
|
||||
|
||||
class _CloudService extends State<CloudService>{
|
||||
late final Map<String, dynamic> credentials;
|
||||
final CloudServiceAPI cloudServiceAPI = CloudServiceAPI();
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Cloud Service"),
|
||||
),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async{
|
||||
var respond1 = await cloudServiceAPI.getDevices();
|
||||
debugPrint('Devices: ${respond1[0].toString()}');
|
||||
var respond2 = await cloudServiceAPI.getInformation();
|
||||
debugPrint('Information: ${respond2.toString()}');
|
||||
}, child: const Text("Example"),
|
||||
),
|
||||
),
|
||||
drawer: const Sidebar(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_provisioning_for_iot/main_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MainPage());
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_provisioning_for_iot/Sidebar.dart';
|
||||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter_provisioning_for_iot/sidebar.dart';
|
||||
|
||||
class MainPage extends StatelessWidget {
|
||||
const MainPage({super.key});
|
||||
|
@ -59,7 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'Sidebar.dart';
|
||||
import 'sidebar.dart';
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
const Settings({Key? key}) : super(key: key);
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_provisioning_for_iot/BluetoothTest.dart';
|
||||
import 'MainPage.dart';
|
||||
import 'Settings.dart';
|
||||
import 'package:flutter_provisioning_for_iot/bluetooth_test.dart';
|
||||
import 'main_page.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
class Sidebar extends StatelessWidget {
|
||||
const Sidebar({Key? key}) : super(key: key);
|
|
@ -0,0 +1,14 @@
|
|||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import flutter_blue
|
||||
import shared_preferences_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterBluePlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
}
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |