|
1 |
| -# ESP-IDF Provisioning - Android |
2 | 1 |
|
3 |
| -ESP-IDF consists of a provisioning mechanism, which is used to provide network credentials and/or custom data to an ESP32 device. |
| 2 | +# Provisioning Library |
| 3 | + |
| 4 | +Provisioning library provides mechanism to send network credentials and/or custom data to an ESP32 or ESP32-S2 devices. |
4 | 5 | This repository contains the source code for the companion Android app for this provisioning mechanism.
|
| 6 | + |
| 7 | +- [Features](#features) |
| 8 | +- [Requirements](#requirements) |
| 9 | +- [How to include](#how-to-include) |
| 10 | +- [Usage](#using-ESPProvision) |
| 11 | + - [****Introduction****](#introduction) |
| 12 | + - [****Getting ESPDevice****](#getting-ESPDevice) |
| 13 | + - [****Provisioning****](#provisioning) |
| 14 | +- [License](#license) |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +- [x] Search for available BLE devices. |
| 19 | +- [x] Scan device QR code to provide reference to ESP device. |
| 20 | +- [x] Create reference of ESPDevice manually. |
| 21 | +- [x] Data Encryption |
| 22 | +- [x] Data transmission through BLE and SoftAP. |
| 23 | +- [x] Scan for available Wi-Fi networks. |
| 24 | +- [x] Provision device. |
| 25 | +- [x] Scan for available Wi-Fi networks. |
| 26 | +- [x] Support for exchanging custom data. |
| 27 | + |
| 28 | +## Requirements |
| 29 | + |
| 30 | +- Supports Android 7.0 (API level 24) and above. |
5 | 31 |
|
6 |
| -This is licensed under Apache 2.0. The complete license for the same can be found in the LICENSE file. |
| 32 | +## How to include |
| 33 | + |
| 34 | + Add it in your root build.gradle at the end of repositories: |
| 35 | + |
7 | 36 |
|
8 |
| -## Configuring Build |
| 37 | + allprojects { |
| 38 | + repositories { |
| 39 | + ... |
| 40 | + maven { url 'https://jitpack.io' } |
| 41 | + } |
| 42 | + } |
9 | 43 |
|
10 |
| -There are multiple build options. It is a combination of 3 options - transport, security and release type. |
| 44 | +And add a dependency code to your app module's `build.gradle` file. |
11 | 45 |
|
12 |
| -- Transports |
13 |
| - - WiFi |
14 |
| - - BLE |
15 |
| -- Security |
16 |
| - - 0 (no security) |
17 |
| - - 1 (security as per IDF docs for provisioning) |
18 |
| -- Release type |
19 |
| - - Debug |
20 |
| - - Release |
| 46 | + implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.0' |
| 47 | + |
| 48 | +## Using Provisioning Library |
| 49 | + |
| 50 | +## Introduction |
| 51 | + |
| 52 | +Provisioning library provides a simpler mechanism to communicate with an ESP-32 and ESP32-S2 devices. It gives an efficient search and scan model to listen and return devices which are in provisioning mode. It embeds security protocol and allow for safe transmission of data by doing end to end encryption. It supports BLE and SoftAP as mode of transmission which are configurable at runtime. Its primarily use is to provide home network credentials to a device and ensure device connectivity status is returned to the application. |
| 53 | + |
| 54 | + |
| 55 | +## Getting ESPDevice |
| 56 | + |
| 57 | +`ESPDevice` object is virtual representation of ESP-32/ESP32-S2 devices. It provides interface to interact with devices directly in a simpler manner. `ESPProvisionManager` is a singleton class that encompasses APIs for searching ESP devices using BLE or SoftAP transport. |
| 58 | + `ESPDevice` instances can be obtained from two ways as described following : |
21 | 59 |
|
22 |
| -So you can pick a build type as `bleSec1Debug`. Note that except for Release type, if you change any of the above options, you will have to change the corresponding firmware on ESP32. |
| 60 | + ### Scan |
| 61 | + |
| 62 | +Device information can be extracted from scanning valid QR code. User of this API decides the camera preview layer frame by providing `SurfaceView` as parameter. It return single `ESPDevice` instance on success. Supports both SoftAP and BLE. |
| 63 | + |
| 64 | +```java |
| 65 | + |
| 66 | +ESPProvisionManager.getInstance(context).scanQRCode(Activity activityContext, SurfaceView surfaceView, QRCodeScanListener qrCodeScanListener) |
| 67 | + |
| 68 | +``` |
| 69 | +### Create |
| 70 | + |
| 71 | +`ESPDevice` can be also created by passing necessary parameters as argument of below function. |
| 72 | + |
| 73 | +```java |
| 74 | + |
| 75 | +ESPProvisionManager.getInstance(context).createESPDevice(TransportType transportType, SecurityType securityType); |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | + > This will return ESPDevice with given transport and security type. |
23 | 80 |
|
24 |
| -# Resources |
| 81 | + 1. For BLE Transport |
| 82 | + > For BLE transport type, library will need BluetoothDevice to connect with actual device. To get BluetoothDevice app can call search API or also app can use own BLE scanning. Library supports searching of BLE devices which are currently in provisioning mode. It returns list of devices that are discoverable and matches the parameter criteria. This API will return BluetoothDevice objects for the devices found in BLE scan with given prefix. |
| 83 | + > After user select BLE device, app can call connect API. |
| 84 | + |
| 85 | +```java |
| 86 | + |
| 87 | +ESPProvisionManager.getInstance(context).searchBleEspDevices(String prefix, BleScanListener bleScannerListener) |
| 88 | + |
| 89 | +``` |
| 90 | + |
| 91 | +> After user select BLE device, app can call connect API. |
25 | 92 |
|
26 |
| -* Documentation for the latest version of IDF: https://docs.espressif.com/projects/esp-idf/. |
| 93 | +```java |
| 94 | + |
| 95 | +espDevice.connectBLEDevice(BluetoothDevice bluetoothDevice, String primaryServiceUuid) |
| 96 | + |
| 97 | +``` |
27 | 98 |
|
28 |
| -* The [esp32.com forum](https://esp32.com/) is a place to ask questions and find community resources. |
| 99 | + |
| 100 | + 2. For SoftAP Transport |
29 | 101 |
|
30 |
| -* [Check the Issues section on github](https://github.com/espressif/esp-idf-provisioning-android/issues) if you find a bug or have a feature request. Please check existing Issues before opening a new one. |
| 102 | + > For SoftAP transport type, app can call connect API to connect with the device. |
31 | 103 |
|
32 |
| -* If you're interested in contributing to ESP-IDF, please check the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/contribute/index.html). |
| 104 | +```java |
| 105 | + |
| 106 | +espDevice.connectWiFiDevice() |
| 107 | + |
| 108 | +``` |
| 109 | + |
| 110 | +> For both transport app can listen device connected / disconnected events by resigtering for events. |
| 111 | + |
| 112 | +## Provisioning |
| 113 | + |
| 114 | +The main feature of Provisioning library is to provision ESP devices. Once we get instance of `ESPDevice` from above APIs we need to establish session with the device before we can transmit/receive data from it. After receiving device connected event, app can get device capabilities and also set Proof of possesion if device has pop capability. |
| 115 | + |
| 116 | +After that application can proceed to scan list of available networks visible to device. This list can be used to give option to the user to choose network of their own choice. |
| 117 | + |
| 118 | +```java |
| 119 | + |
| 120 | +espDevice.scanNetworks(final WiFiScanListener wifiScanListener); |
| 121 | + |
| 122 | +``` |
| 123 | + |
| 124 | +User can choose to apply Wi-Fi settings from the above list or choose other Wi-Fi network to provision the device. |
| 125 | + |
| 126 | +```java |
| 127 | + |
| 128 | +espDevice.provision(final String ssid, final String passphrase, final ProvisionListener provisionListener); |
| 129 | + |
| 130 | +``` |
| 131 | + |
| 132 | +## License |
| 133 | + |
| 134 | + |
| 135 | + Copyright 2020 Espressif Systems (Shanghai) PTE LTD |
| 136 | + |
| 137 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 138 | + you may not use this file except in compliance with the License. |
| 139 | + You may obtain a copy of the License at |
| 140 | + |
| 141 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 142 | + |
| 143 | + Unless required by applicable law or agreed to in writing, software |
| 144 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 145 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 146 | + See the License for the specific language governing permissions and |
| 147 | + limitations under the License. |
0 commit comments