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

Bugfix for Example app and Ble Service #10

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b076ee6
minSdkVersion is updated to 19 for compatibility reasons
omert08 Mar 15, 2021
2f5a914
If BT is already on at Android devices, it hangs at start() function,…
omert08 Mar 15, 2021
dd530a3
peripheral parameter is passed to WiFiScreen
omert08 Mar 15, 2021
5650674
peripheral select code is added before provisioning
omert08 Mar 15, 2021
dda3cec
WifiEventLoad is edited for peripheral parameter pass
omert08 Mar 15, 2021
91e3562
peripheral is passed to WiFiBloc
omert08 Mar 15, 2021
6e1ccd0
TransPortHTTP class constructor is done
omert08 Mar 20, 2021
8e30a64
overrides are added
omert08 Mar 20, 2021
1af03c1
Transporthttp constuctor is edited
omert08 Mar 26, 2021
9f2db57
transport http is exported
omert08 Mar 26, 2021
7ef305e
softap events are added
omert08 Mar 26, 2021
7bc00c2
wifibloc is isolated for ble prov.
omert08 Mar 26, 2021
5daf74c
WiFiBlocSoftAP is added
omert08 Mar 26, 2021
217f6f3
load event is edited
omert08 Mar 26, 2021
1b27056
dart:html is removed
omert08 Mar 26, 2021
70d45cc
softapbloc is created
omert08 Mar 26, 2021
b2c5689
softap initial events are added
omert08 Mar 26, 2021
951abf9
soft ap screen code is created
omert08 Mar 26, 2021
62587ed
Softap state initial states are created
omert08 Mar 26, 2021
7452170
softap screen is created
omert08 Mar 26, 2021
795e648
Android manifest is edited for http requests and internet usage
omert08 Mar 27, 2021
3ee3f32
no important updates
omert08 Mar 27, 2021
081eb81
It works with softap provisioning on Android untill EstablishSession …
omert08 Mar 27, 2021
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
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.tuanpm.esp_provisioning_example"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
3 changes: 3 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="esp_provisioning_example"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down Expand Up @@ -44,4 +46,5 @@
android:name="flutterEmbedding"
android:value="2" />
</application>

</manifest>
87 changes: 0 additions & 87 deletions example/ios/Podfile

This file was deleted.

41 changes: 0 additions & 41 deletions example/ios/Podfile.lock

This file was deleted.

2 changes: 1 addition & 1 deletion example/lib/ble_screen/ble_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _BleScreenState extends State<BleScreen> {
return Container(
padding: EdgeInsets.only(top: 5.0),
height: MediaQuery.of(context).size.height - 50,
child: WiFiScreen(),
child: WiFiScreenBLE(peripheral: item),
);
});
bottomSheetController.whenComplete(() {
Expand Down
9 changes: 5 additions & 4 deletions example/lib/ble_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class BleService {
});
});

var state = await _waitForBluetoothPoweredOn();
if (Platform.isAndroid) {
log.v('enableRadio');
await _bleManager.enableRadio();
if (state.index != 3) { // check if bluetooth is already open
log.v('enableRadio');
await _bleManager.enableRadio();
}
}

var state = await _waitForBluetoothPoweredOn();
_isPowerOn = true;
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:esp_provisioning_example/softap_screen/softap_screen.dart';
import 'package:flutter/material.dart';
import 'ble_screen/ble_screen.dart';

Expand Down Expand Up @@ -26,7 +27,7 @@ class HomeScreen extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => BleScreen()));
builder: (BuildContext context) => SoftApScreen()));
},
child: Text(
'Start Provisioning',
Expand Down
25 changes: 25 additions & 0 deletions example/lib/softap_screen/softap_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:esp_provisioning_example/softap_screen/softap_event.dart';
import 'package:esp_provisioning_example/softap_screen/softap_state.dart';
import 'package:esp_provisioning_example/softap_service.dart';



class SoftApBloc extends Bloc<SoftApEvent,SoftApState> {

@override
// TODO: implement initialState
get initialState => SoftApStateLoaded();

@override
Stream<SoftApState> mapEventToState(event) async* {
if (event is SoftApEventStart){
yield* _mapStartToState();
}
}
Stream<SoftApState> _mapStartToState() async* {

}
}

10 changes: 10 additions & 0 deletions example/lib/softap_screen/softap_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:equatable/equatable.dart';

abstract class SoftApEvent extends Equatable {
const SoftApEvent();

@override
List<Object> get props => [];
}

class SoftApEventStart extends SoftApEvent {}
99 changes: 99 additions & 0 deletions example/lib/softap_screen/softap_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'package:esp_provisioning_example/softap_screen/softap_bloc.dart';
import 'package:esp_provisioning_example/softap_screen/softap_event.dart';
import 'package:esp_provisioning_example/softap_screen/softap_state.dart';
import 'package:esp_provisioning_example/wifi_screen/wifi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class SoftApScreen extends StatefulWidget {
@override
_SoftApScreenState createState() => _SoftApScreenState();
}

class _SoftApScreenState extends State<SoftApScreen> {

void _showBottomSheet(BuildContext _context) {
// BlocProvider.of<SoftApBloc>(_context).add(SoftApEventStart());

var bottomSheetController = showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
isScrollControlled: true,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0),
),
),
builder: (BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 5.0),
height: MediaQuery.of(context).size.height - 50,
child: WiFiScreenSoftAP(),
);
});
bottomSheetController.whenComplete(() {
// after prov.
BlocProvider.of<SoftApBloc>(_context).add(SoftApEventStart());
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.redAccent,
title: const Text('Scanning BLE devices'),
),
body: BlocProvider(
create: (BuildContext context) => SoftApBloc(),
child: BlocBuilder<SoftApBloc, SoftApState>(
builder: (BuildContext context, SoftApState state) {
if (state is SoftApStateLoaded) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(4.0),
width: MediaQuery.of(context).size.width * 0.85,
child:Text('Please connect WiFi to Subol_Gas_Sensor_ in "Wi-Fi Settings". Once you complete it please tap on "Ready" button.',
style: TextStyle(fontSize: 18),),
),

SizedBox(height: MediaQuery.of(context).size.width * 0.1,),
MaterialButton(
color: Colors.redAccent,
elevation: 5,
padding: EdgeInsets.all(15.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5))),
child: Text(
'Ready',
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.white),
),

onPressed: () {
_showBottomSheet(this.context);
},
),
],
)

);
}

return Center(
child: SpinKitRipple(color: Theme.of(context).textSelectionColor),
);
},
),
),
);
}
}
10 changes: 10 additions & 0 deletions example/lib/softap_screen/softap_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:equatable/equatable.dart';

abstract class SoftApState extends Equatable {
const SoftApState();

@override
List<Object> get props => [];
}

class SoftApStateLoaded extends SoftApState {}
20 changes: 20 additions & 0 deletions example/lib/softap_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter_ble_lib/flutter_ble_lib.dart';
import 'package:esp_provisioning/esp_provisioning.dart';

class SoftAPService {
final String hostname;
final int port;
SoftAPService(this.hostname, this.port);

Future<EspProv> startProvisioning() async {
EspProv prov = EspProv(
transport: TransportHTTP(this.hostname, this.port), security: Security1(pop: 'abcd1234'));
var success = await prov.establishSession();
if (!success) {
throw Exception('Error establishSession');
}
return prov;
}
}
Loading