diff --git a/naxalnet/iwd.py b/naxalnet/iwd.py index 1578572..e6a04a8 100644 --- a/naxalnet/iwd.py +++ b/naxalnet/iwd.py @@ -188,7 +188,8 @@ class Device: def start_adhoc_open(self, name: str): """ Create ad-hoc network with name, changing mode to ad-hoc - if it isn't already on ad-hoc + if it isn't already on ad-hoc and power onn the device + if it is off """ if self.get_mode() != "ad-hoc": self.set_mode("ad-hoc") @@ -196,8 +197,8 @@ class Device: if not self.is_powered_on(): self.power_on() - if self.is_adhoc_started(): - self.stop_adhoc() + # Stop adhoc if already started + self.stop_adhoc() self._proxy.StartOpen(name) @@ -207,6 +208,29 @@ class Device: self._proxy.Stop() self.reload() + def start_ap(self, ssid, passwd): + """ + Create ap network, changing mode to ap + if it isn't already on ap and turning + on the device if it is off + """ + if self.get_mode() != "ap": + self.set_mode("ap") + + if not self.is_powered_on(): + self.power_on() + + # Stop ap if already started + self.stop_ap() + + self._proxy.Start(ssid, passwd) + + def stop_ap(self): + """stop ap if an ap is started""" + if self.is_ap_started(): + self._proxy.Stop() + self.reload() + class Adapter: """represents an adapter as a python object""" @@ -243,7 +267,7 @@ class Adapter: def supports_mode(self, mode: str) -> bool: """ - Returns True if the adapter supports the mode + Returns True if the adapter supports the mode. mode can be "ad-hoc", "ap" or "station" """ return mode in self.supported_modes diff --git a/naxalnet/naxalnet.py b/naxalnet/naxalnet.py index 25045f0..fbd2b7f 100755 --- a/naxalnet/naxalnet.py +++ b/naxalnet/naxalnet.py @@ -82,10 +82,11 @@ try: # ie, we have more devices if len(ap_devices) != 0: print("Working on AP") - ap_device = ap_devices.pop() + ap_device = Device(ap_devices.pop()) # _TODO: start ap after implementing in in iwd.py -except DBusError as e: - print(e) + ap_device.start_ap(AP_SSID, AP_PASSWD) +except DBusError as error: + print(error) sys.exit("An error occured while communicating with iwd") print("Bye")