2018-07-30 12:10:10 -04: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-06-01 03:12:28 -04:00
|
|
|
|
2018-07-30 12:10:10 -04:00
|
|
|
import os
|
2021-06-01 03:12:28 -04:00
|
|
|
import re
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
import esp_prov
|
2021-06-01 03:12:28 -04:00
|
|
|
import tiny_test_fw
|
|
|
|
import ttfw_idf
|
2019-11-26 22:58:07 -05:00
|
|
|
import wifi_tools
|
2021-06-01 03:12:28 -04:00
|
|
|
from tiny_test_fw import Utility
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2018-11-28 07:31:57 -05:00
|
|
|
# Have esp_prov throw exception
|
|
|
|
esp_prov.config_throw_except = True
|
|
|
|
|
2018-12-01 08:23:34 -05:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
2018-07-30 12:10:10 -04:00
|
|
|
def test_examples_provisioning_softap(env, extra_data):
|
|
|
|
# Acquire DUT
|
2021-06-01 03:12:28 -04:00
|
|
|
dut1 = env.get_dut('softap_prov', 'examples/provisioning/legacy/softap_prov', dut_class=ttfw_idf.ESP32DUT)
|
2018-07-30 12:10:10 -04:00
|
|
|
|
|
|
|
# Get binary file
|
2021-06-01 03:12:28 -04:00
|
|
|
binary_file = os.path.join(dut1.app.binary_path, 'softap_prov.bin')
|
2018-07-30 12:10:10 -04:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-06-01 03:12:28 -04:00
|
|
|
ttfw_idf.log_performance('softap_prov_bin_size', '{}KB'.format(bin_size // 1024))
|
2018-07-30 12:10:10 -04:00
|
|
|
|
|
|
|
# Upload binary and start testing
|
|
|
|
dut1.start_app()
|
|
|
|
|
|
|
|
# Parse IP address of STA
|
2021-06-01 03:12:28 -04:00
|
|
|
dut1.expect('Starting WiFi SoftAP provisioning', timeout=60)
|
2018-11-08 02:44:54 -05:00
|
|
|
[ssid, password] = dut1.expect(re.compile(r"SoftAP Provisioning started with SSID '(\S+)', Password '(\S+)'"), timeout=30)
|
2018-07-30 12:10:10 -04:00
|
|
|
|
|
|
|
iface = wifi_tools.get_wiface_name()
|
2018-12-01 08:23:34 -05:00
|
|
|
if iface is None:
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to get Wi-Fi interface on host')
|
|
|
|
print('Interface name : ' + iface)
|
|
|
|
print('SoftAP SSID : ' + ssid)
|
|
|
|
print('SoftAP Password : ' + password)
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2020-06-26 04:16:20 -04:00
|
|
|
try:
|
|
|
|
ctrl = wifi_tools.wpa_cli(iface, reset_on_exit=True)
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Connecting to DUT SoftAP...')
|
|
|
|
try:
|
|
|
|
ip = ctrl.connect(ssid, password)
|
|
|
|
except RuntimeError as err:
|
|
|
|
Utility.console_log('error: {}'.format(err))
|
|
|
|
try:
|
|
|
|
got_ip = dut1.expect(re.compile(r'DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)'), timeout=60)
|
|
|
|
Utility.console_log('got_ip: {}'.format(got_ip))
|
|
|
|
got_ip = got_ip[0]
|
|
|
|
if ip != got_ip:
|
|
|
|
raise RuntimeError('SoftAP connected to another host! {} != {}'.format(ip, got_ip))
|
|
|
|
except tiny_test_fw.DUT.ExpectTimeout:
|
|
|
|
# print what is happening on dut side
|
|
|
|
Utility.console_log('in exception tiny_test_fw.DUT.ExpectTimeout')
|
|
|
|
Utility.console_log(dut1.read())
|
|
|
|
raise
|
|
|
|
print('Connected to DUT SoftAP')
|
|
|
|
|
|
|
|
print('Starting Provisioning')
|
2020-06-26 04:16:20 -04:00
|
|
|
verbose = False
|
2021-06-01 03:12:28 -04:00
|
|
|
protover = 'V0.1'
|
2020-06-26 04:16:20 -04:00
|
|
|
secver = 1
|
2021-06-01 03:12:28 -04:00
|
|
|
pop = 'abcd1234'
|
|
|
|
provmode = 'softap'
|
|
|
|
ap_ssid = 'myssid'
|
|
|
|
ap_password = 'mypassword'
|
|
|
|
softap_endpoint = '{}.{}.{}.1:80'.format(ip.split('.')[0], ip.split('.')[1], ip.split('.')[2])
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Getting security')
|
2020-06-26 04:16:20 -04:00
|
|
|
security = esp_prov.get_security(secver, pop, verbose)
|
|
|
|
if security is None:
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to get security')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Getting transport')
|
2020-06-26 04:16:20 -04:00
|
|
|
transport = esp_prov.get_transport(provmode, softap_endpoint)
|
|
|
|
if transport is None:
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to get transport')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Verifying protocol version')
|
2020-06-26 04:16:20 -04:00
|
|
|
if not esp_prov.version_match(transport, protover):
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Mismatch in protocol version')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Starting Session')
|
2020-06-26 04:16:20 -04:00
|
|
|
if not esp_prov.establish_session(transport, security):
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to start session')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Sending Wifi credential to DUT')
|
2020-06-26 04:16:20 -04:00
|
|
|
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to send Wi-Fi config')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
2021-06-01 03:12:28 -04:00
|
|
|
print('Applying config')
|
2020-06-26 04:16:20 -04:00
|
|
|
if not esp_prov.apply_wifi_config(transport, security):
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Failed to send apply config')
|
2020-06-26 04:16:20 -04:00
|
|
|
|
|
|
|
if not esp_prov.wait_wifi_connected(transport, security):
|
2021-06-01 03:12:28 -04:00
|
|
|
raise RuntimeError('Provisioning failed')
|
2020-06-26 04:16:20 -04:00
|
|
|
finally:
|
|
|
|
ctrl.reset()
|
2018-07-30 12:10:10 -04:00
|
|
|
|
2018-12-01 08:23:34 -05:00
|
|
|
|
2018-07-30 12:10:10 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_provisioning_softap()
|