diff --git a/platform/arduino/wtfconfig.py b/platform/arduino/wtfconfig.py index 9892f44..bc66ce1 100644 --- a/platform/arduino/wtfconfig.py +++ b/platform/arduino/wtfconfig.py @@ -6,6 +6,7 @@ # path to arduino directory... must be changed IDE = "/home/jacob/dev/arduino_project/MeshableMCU/arduino-1.5.6-r2" +BOARD = "gmc200_dbg" arduino_comm = wtf.comm.Serial(port="/dev/ttyUSB2", prompt="") arduino_comm.name = "arduino" @@ -20,4 +21,4 @@ sta = wtf.node.ap.Hostapd(sta_ssh, [iface], ops=ops) wtf.conf = wtf.config("arduino", comm=arduino_comm, nodes=[sta], - name="arduino mc200 tests", data={'IDE': IDE}) + name="arduino mc200 tests", data={'IDE': IDE, 'BOARD': BOARD}) diff --git a/tests/arduino.py b/tests/arduino.py index d1e2e6c..8cb26a1 100644 --- a/tests/arduino.py +++ b/tests/arduino.py @@ -38,6 +38,10 @@ def setUpClass(cls): cls.IDE = wtfconfig.data['IDE'] else: cls.IDE = '' + if 'BOARD' in wtfconfig.data: + cls.BOARD = wtfconfig.data['BOARD'] + else: + cls.BOARD = 'mc200_dbg' # set up a fake X server for a computer without one... if not 'DISPLAY' in cls.env or cls.env['DISPLAY'] == '': @@ -81,7 +85,7 @@ def build_and_upload(self, build_path): self.fail("You do not have the correct arduino ide directory path set") ret = Popen(["./arduino", "--upload", "--board", - "cozybit:mc200:mc200_dbg", "-v", "--pref", + "cozybit:mc200:%s" % self.BOARD, "-v", "--pref", "build.path=" + self.build_dir, "--port", self.cereal.port, build_path], env=self.env) ret.wait() @@ -97,14 +101,12 @@ def setup_run(self, path, write=None): def start_hostapd(self, apconf): """ Set hostap.conf and init/start node """ + self.AP.stop() self.AP.config = apconf self.AP.init() self.AP.start() time.sleep(5) - def stop_hostapd(self): - self.AP.stop() - def test_01_string_addition_operators(self): self.setup_run('./examples/08.Strings/StringAdditionOperator/' 'StringAdditionOperator.ino') @@ -250,12 +252,9 @@ def test_14_string_to_int(self): def test_15_connect_wifi_no_password(self): self.start_hostapd(ap.APConfig(ssid="wtf-arduino-ap")) self.setup_run(os.getcwd() + '/platform/arduino/SimpleWiFi/SimpleWiFi.ino') - # set to 20 incase connection takes longer than 10 seconds - time.sleep(20) self.ffd.expect(re.escape("You're connected to the network")); # [1-9] first so we don't match 0.0.0.0 with d+.d+.d+.d+ self.ffd.expect(re.escape("the ip is ") + r'[1-9]\d+\.\d+\.\d+\.\d+') - self.stop_hostapd() def test_16_connect_wifi_with_password(self): self.start_hostapd(ap.APConfig(ssid="wtf-arduino-pass-ap", @@ -264,9 +263,6 @@ def test_16_connect_wifi_with_password(self): password="thisisasecret", encrypt=ap.ENCRYPT_CCMP)) self.setup_run(os.getcwd() + '/platform/arduino/SimpleWiFiPass/SimpleWiFiPass.ino') - # set to 20 incase connection takes longer than 10 seconds - time.sleep(20) self.ffd.expect(re.escape("You're connected to the password protected network")); # [1-9] first so we don't match 0.0.0.0 with d+.d+.d+.d+ self.ffd.expect(re.escape("the ip is ") + r'[1-9]\d+\.\d+\.\d+\.\d+') - self.stop_hostapd() diff --git a/wtf/node/__init__.py b/wtf/node/__init__.py index e1afab3..36b2c48 100644 --- a/wtf/node/__init__.py +++ b/wtf/node/__init__.py @@ -4,8 +4,9 @@ """WTF network node definitions.""" import os -import time from collections import namedtuple +from textwrap import dedent +import time from wtf.util import CapData from wtf.util import PerfConf @@ -622,3 +623,18 @@ def bond(self, ifaces, ip): for iface in ifaces: self._cmd_or_die("ip addr flush " + iface.name) self._cmd_or_die("ifenslave bond0 " + iface.name) + + def start_udhcpd(self): + """Start udhcpd, assumes it is on the system""" + n = 10 + for iface in self.iface: + self.set_ip(iface.name, "192.168.%d.1" % n) + dhcp_conf = dedent(""" + start 192.168.%d.10 + end 192.168.%d.100 + interface %s + """ % (n, n, iface.name)) + self.comm.send_cmd("killall udhcpd") + self._cmd_or_die("echo -e \"" + dhcp_conf + "\">/tmp/udhcp.conf") + self._cmd_or_die("udhcpd /tmp/udhcp.conf") + n += 1 diff --git a/wtf/node/ap.py b/wtf/node/ap.py index 0c27d20..0d38834 100644 --- a/wtf/node/ap.py +++ b/wtf/node/ap.py @@ -81,6 +81,7 @@ def start(self): raise node.InsufficientConfigurationError() self._configure() self._cmd_or_die("hostapd -B /tmp/hostapd.conf") + self.start_udhcpd() def stop(self): node.LinuxNode.stop(self)