2019-04-23 17:45:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2021-01-26 02:49:01 +00:00
|
|
|
|
2019-04-23 17:45:51 +00:00
|
|
|
import os
|
2021-01-26 02:49:01 +00:00
|
|
|
import re
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2019-11-27 03:58:07 +00:00
|
|
|
import esp_prov
|
2021-01-26 02:49:01 +00:00
|
|
|
import ttfw_idf
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
# Have esp_prov throw exception
|
|
|
|
esp_prov.config_throw_except = True
|
|
|
|
|
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
2019-04-23 17:45:51 +00:00
|
|
|
def test_examples_wifi_prov_mgr(env, extra_data):
|
|
|
|
# Acquire DUT
|
2021-01-26 02:49:01 +00:00
|
|
|
dut1 = env.get_dut('wifi_prov_mgr', 'examples/provisioning/wifi_prov_mgr', dut_class=ttfw_idf.ESP32DUT)
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
# Get binary file
|
2021-01-26 02:49:01 +00:00
|
|
|
binary_file = os.path.join(dut1.app.binary_path, 'wifi_prov_mgr.bin')
|
2019-04-23 17:45:51 +00:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-01-26 02:49:01 +00:00
|
|
|
ttfw_idf.log_performance('wifi_prov_mgr_bin_size', '{}KB'.format(bin_size // 1024))
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
# Upload binary and start testing
|
|
|
|
dut1.start_app()
|
|
|
|
|
|
|
|
# Check if BT memory is released before provisioning starts
|
2021-01-26 02:49:01 +00:00
|
|
|
dut1.expect('wifi_prov_scheme_ble: BT memory released', timeout=60)
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
# Parse BLE devname
|
2021-01-26 02:49:01 +00:00
|
|
|
devname = dut1.expect(re.compile(r'Provisioning started with service name : (PROV_\S\S\S\S\S\S)'), timeout=30)[0]
|
|
|
|
print('BLE Device Alias for DUT :', devname)
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Starting Provisioning')
|
2019-04-23 17:45:51 +00:00
|
|
|
verbose = False
|
2021-01-26 02:49:01 +00:00
|
|
|
protover = 'v1.1'
|
2019-04-23 17:45:51 +00:00
|
|
|
secver = 1
|
2021-01-26 02:49:01 +00:00
|
|
|
pop = 'abcd1234'
|
|
|
|
provmode = 'ble'
|
|
|
|
ap_ssid = 'myssid'
|
|
|
|
ap_password = 'mypassword'
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Getting security')
|
2019-04-23 17:45:51 +00:00
|
|
|
security = esp_prov.get_security(secver, pop, verbose)
|
|
|
|
if security is None:
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Failed to get security')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Getting transport')
|
2019-07-02 14:42:47 +00:00
|
|
|
transport = esp_prov.get_transport(provmode, devname)
|
2019-04-23 17:45:51 +00:00
|
|
|
if transport is None:
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Failed to get transport')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Verifying protocol version')
|
2019-04-23 17:45:51 +00:00
|
|
|
if not esp_prov.version_match(transport, protover):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Mismatch in protocol version')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Verifying scan list capability')
|
2019-04-23 06:48:28 +00:00
|
|
|
if not esp_prov.has_capability(transport, 'wifi_scan'):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Capability not present')
|
2019-04-23 06:48:28 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Starting Session')
|
2019-04-23 17:45:51 +00:00
|
|
|
if not esp_prov.establish_session(transport, security):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Failed to start session')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Sending Custom Data')
|
|
|
|
if not esp_prov.custom_data(transport, security, 'My Custom Data'):
|
|
|
|
raise RuntimeError('Failed to send custom data')
|
2020-01-03 15:36:10 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Sending Wifi credential to DUT')
|
2019-04-23 17:45:51 +00:00
|
|
|
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Failed to send Wi-Fi config')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
print('Applying config')
|
2019-04-23 17:45:51 +00:00
|
|
|
if not esp_prov.apply_wifi_config(transport, security):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Failed to send apply config')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
2020-06-25 05:52:25 +00:00
|
|
|
if not esp_prov.wait_wifi_connected(transport, security):
|
2021-01-26 02:49:01 +00:00
|
|
|
raise RuntimeError('Provisioning failed')
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
# Check if BTDM memory is released after provisioning finishes
|
2021-01-26 02:49:01 +00:00
|
|
|
dut1.expect('wifi_prov_scheme_ble: BTDM memory released', timeout=30)
|
2019-04-23 17:45:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_wifi_prov_mgr()
|