Home | History | Annotate | Download | only in net
      1 #!/usr/bin/env python3.4
      2 #
      3 # Copyright 2018 Google, Inc.
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 # http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 
     17 import logging
     18 import time
     19 import pprint
     20 
     21 from enum import IntEnum
     22 from queue import Empty
     23 
     24 from acts import asserts
     25 from acts import signals
     26 from acts import utils
     27 from acts.controllers import attenuator
     28 from acts.test_utils.wifi import wifi_constants
     29 from acts.test_utils.tel import tel_defines
     30 from acts.test_utils.wifi import wifi_test_utils as wutils
     31 
     32 ARDUINO = "/root/arduino/arduino-1.8.5/arduino "
     33 CONNECT_WIFI = "/arduino/connect_wifi/connect_wifi.ino"
     34 DISCONNECT_WIFI = "/arduino/disconnect_wifi/disconnect_wifi.ino"
     35 SSID = wutils.WifiEnums.SSID_KEY
     36 PWD = wutils.WifiEnums.PWD_KEY
     37 
     38 def connect_wifi(wd, network=None):
     39     """Connect wifi on arduino wifi dongle
     40 
     41     Args:
     42         wd - wifi dongle object
     43         network - wifi network to connect to
     44     """
     45     wd.log.info("Flashing connect_wifi.ino onto dongle")
     46     cmd = "locate %s" % CONNECT_WIFI
     47     file_path = utils.exe_cmd(cmd).decode("utf-8", "ignore").rstrip()
     48     write_status = wd.write(ARDUINO, file_path, network)
     49     asserts.assert_true(write_status, "Failed to flash connect wifi")
     50     wd.log.info("Flashing complete")
     51     wifi_status = wd.wifi_status()
     52     asserts.assert_true(wifi_status, "Failed to connect to %s" % network)
     53     ping_status = wd.ping_status()
     54     asserts.assert_true(ping_status, "Failed to connect to internet")
     55 
     56 def disconnect_wifi(wd):
     57     """Disconnect wifi on arduino wifi dongle
     58 
     59     Args:
     60         wd - wifi dongle object
     61 
     62     Returns:
     63         True - if wifi is disconnected
     64         False - if not
     65     """
     66     wd.log.info("Flashing disconnect_wifi.ino onto dongle")
     67     cmd = "locate %s" % DISCONNECT_WIFI
     68     file_path = utils.exe_cmd(cmd).decode("utf-8", "ignore").rstrip()
     69     write_status = wd.write(ARDUINO, file_path)
     70     asserts.assert_true(write_status, "Failed to flash disconnect wifi")
     71     wd.log.info("Flashing complete")
     72     wifi_status = wd.wifi_status(False)
     73     asserts.assert_true(not wifi_status, "Failed to disconnect wifi")
     74