esp_provisioning_wifi 0.2.0
esp_provisioning_wifi: ^0.2.0 copied to clipboard
Provision WiFi on Espressif ESP32 devices over Bluetooth LE from Flutter, with a Bloc API and native Android and iOS provisioning implementations.

esp_provisioning_wifi #
Library to provision WiFi on ESP32 devices over Bluetooth, using Bloc.
API Notes #
- Import the package via the public barrel:
import 'package:esp_provisioning_wifi/esp_provisioning_wifi.dart';
scanWifiNetworks(...)returnsFuture<List<EspWifiNetwork>>.- Each network exposes
ssid, plusrssi(dBm) andsecuritywhere the platform reports them (currently Android only; null on iOS).
- Each network exposes
provisionWifi(...)returnsFuture<bool>.- It resolves
trueon success and throws aPlatformExceptionwith a typedE_PROV_*code on failure.
- It resolves
cancelOperations()returnsFuture<bool>and cancels active native work.- In-flight scan/provision calls fail with
E_CANCELLED(EspProvisioningFailure.cancelled) on both platforms.
- In-flight scan/provision calls fail with
EspProvisioningState.failureexposes typed failures usingEspProvisioningFailure.none,permissionDenied,timeout,cancelled,deviceNotFound,invalidResponse,sessionFailed,authenticationFailed,networkNotFound,provisioningFailed,platform,unknown.
EspProvisioningState.errorCodeanderrorDetailsexpose raw platform diagnostics.scanWifiNetworks(...)andprovisionWifi(...)accept optionalconnectTimeout.- This timeout is propagated through Dart and native layers for BLE connection timing.
EspProvisioningBlocacceptsconnectTimeout(BLE connect phase, default 15s) andrequestTimeout(overall operation budget, defaultconnectTimeout+ 20s).- Dart-side request timeouts cancel the in-flight native operation and emit
status: EspProvisioningStatus.errorwithfailure == EspProvisioningFailure.timeout. fetchCustomData(...)reads provisioning custom endpoint payloads (defaults to endpointcustom-data).- Useful for firmware-driven provisioning metadata such as lock state or SoftAP password hints.
Error Code Contract #
Native layers report stable error codes that the bloc maps into EspProvisioningFailure:
E0(EspProvisioningErrorCodes.missingArgument)E1(EspProvisioningErrorCodes.wifiScanFailed)E_PERMISSIONE_BLE_SCAN_STARTE_BLE_SCANE_DEVICE_NOT_FOUNDE_INVALID_RESPONSEE_CONNECT_TIMEOUTE_CONNECTE_CUSTOM_DATAE_DEVICEE_PROV_SESSIONE_PROV_CONFIGE_PROV_AUTHE_PROV_NETWORK_NOT_FOUNDE_PROV_FAILEDDEVICE_DISCONNECTEDE_CANCELLEDE_TIMEOUTE_UNKNOWN
Import: package:esp_provisioning_wifi/esp_provisioning_error_codes.dart.
Migration (0.1.x -> 0.2.0) #
- The method channel and native plugin package/classes were renamed, so this
plugin no longer conflicts with apps that also depend on
flutter_esp_ble_prov. No Dart-side changes are needed for this. scanWifiNetworks(...)andEspProvisioningState.wifiNetworksnow useEspWifiNetworkinstead ofString. Usenetwork.ssidwhere you previously used the string;rssiandsecurityare available on Android.- Provisioning failures now throw typed
PlatformExceptions (E_PROV_SESSION,E_PROV_CONFIG,E_PROV_AUTH,E_PROV_NETWORK_NOT_FOUND,E_PROV_FAILED) instead of resolvingfalse. The bloc maps them to newEspProvisioningFailurevalues (sessionFailed,authenticationFailed,networkNotFound,provisioningFailed); exhaustive switches overEspProvisioningFailuremust handle them. - Timeouts now emit
status: EspProvisioningStatus.error(previously the step status was kept withfailure: timeout). - The
TIMEOUTconstant was replaced bykEspDefaultConnectTimeoutandkEspDefaultOperationBudget;EspProvisioningBlocnow takesconnectTimeoutandrequestTimeoutparameters. - Minimums raised: Dart
^3.5.0, Flutter3.24+, flutter_bloc 9, permission_handler 12 (13.x is deferred until its AGP 9 / compileSdk 37 toolchain requirements are mainstream; pinningpermission_handler: ^13.0.0in your app will conflict with this plugin's^12.0.3constraint).
Migration (0.0.x -> 0.1.0) #
- Replace
state.timedOutchecks withstate.failure == EspProvisioningFailure.timeout. - For error UX and telemetry, use both:
state.failurefor typed handlingstate.errorCodeandstate.errorDetailsfor diagnostics
- If you call service methods directly, invoke
cancelOperations()before starting a new scan/provision flow to cancel stale native operations. - Replace direct
srcimports with:import 'package:esp_provisioning_wifi/esp_provisioning_wifi.dart';
Usage #
BlocProvider(
create: (_) => EspProvisioningBloc(),
child: BlocConsumer<EspProvisioningBloc, EspProvisioningState>(
listener: (_, state) {
if (state.failure != EspProvisioningFailure.none) {
// Use typed failure for user-facing behavior.
debugPrint('Failure: ${state.failure} | ${state.errorMsg}');
}
},
builder: (_, state) {
return Text('Status: ${state.status}');
},
),
)
Requirements #
Android 6 (API level 23)+ #
Make sure your android/build.gradle has 23+ here:
defaultConfig {
minSdkVersion 23
}
If your app enforces repositories via settings.gradle (dependencyResolutionManagement),
ensure jitpack.io is present:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Bluetooth permissions are automatically requested by the library.
iOS 13.0+ #
Add this in your ios/Runner/Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Our app uses bluetooth to find, connect and transfer data between different devices</string>
Notes #
Origins #
This library started as a Bloc wrapper over flutter_esp_ble_prov. The native Android and iOS provisioning implementations are now maintained inside this package.
Espressif provisioning libraries #
- Android uses esp-idf-provisioning-android, resolved via JitPack.
- iOS uses the ESPProvision CocoaPod.