flutter_provisioning_sdk 1.0.0+6
flutter_provisioning_sdk: ^1.0.0+6 copied to clipboard
flutter_provisioning_sdk
Provision Manager #
Provision Manager is a Dart library designed for managing device provisioning workflows, including network configuration, Wi-Fi signal strength monitoring, and device orientation tracking. It provides an intuitive API for handling device states and simplifies the installation process.
Installing #
Add Provision Manager to your pubspec.yaml file:
dependencies:
flutter_provisioning_sdk: ^1.0.0+5
Import Provision Manager in files that it will be used:
import 'package:flutter_provisioning_sdk/core/provision_manager.dart';
Scan Devices
The scan can be customized with options like a device name prefix, scan duration, and matching criteria.
ProvisionManager().scanPSDevices(
prefix: deviceSn,
duration: 5000,
exactMatch: true,
scanState: (bool) {
},
onResult: (result) {
},
onFailure: (exception) {
});
Connect Device
The method establishes a connection to a Bluetooth device based on the scanResult object (which contains information about a discovered device) and provides a callback to handle the connection state.
ProvisionManager().connectDevice(scanResult, callback: (state) {
if (state == BleConnectionState.onConnectStart) {
}else if (state == BleConnectionState.onConnectSuccess) {
}else if (state == BleConnectionState.onConnectFail) {
}else if (state == BleConnectionState.onDisconnected) {
}else {
}
});
Get Device Init State
This method retrieves the initialization status of a sensor, indicating whether the sensor has been properly set up or is ready for use.
ProvisionManager().getSensorStateFromDevice().listen((data) {
switch(data.params?.status){
}
})
Scan Wi-Fi
The method scans for available Wi-Fi networks and provides a callback with the list of detected networks (wifiList). The wifiList contains information about the available Wi-Fi networks, which can be accessed and processed within the callback.
ProvisionManager().getWifiListFromDevice((wifiList) {
if (wifiList.params?.softapList != null) {
}
});
Send configuration files such as certificates
The sendConfigure method sends device configuration data, such as organization ID, certificate, keys, and Wi-Fi credentials, to a target device. It handles failures and listens for state updates during the configuration process.
ProvisionManager().sendWiFiConfigToDevice(
orgId,
certPem,
publicKey,
privateKey,
url,
ssid,
password,
onWriteFailure: (e) {
}
).distinct((previous, next) {
return previous.params?.status == next.params?.status;
}).listen((data) {
});
Device Install Info
The getSensorInstallInfo method retrieves information about the installation status of a sensor, including relevant data like orientation, setup status, or other sensor-specific details. The method returns a stream of updates, allowing the application to listen for changes in the sensor's installation information.
ProvisionManager().getSensorInfoFromDevice().listen((data) {
});
Sensor Config Complete
After completing all configurations, call sendCompleteInfoToDevice, which will then enter its work mode.
ProvisionManager().sendCompleteInfoToDevice((data) {
});