mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2025-01-10 08:47:47 +05:30
checks if device supports ad-hoc before starting ad-hoc
Partly added AP support
This commit is contained in:
parent
0fb8b6a8ab
commit
006cb1095c
48
naxalnet
48
naxalnet
@ -57,17 +57,36 @@ try:
|
|||||||
# Get list of all devices
|
# Get list of all devices
|
||||||
print("Finding connected devices")
|
print("Finding connected devices")
|
||||||
objects = iwd.GetManagedObjects()
|
objects = iwd.GetManagedObjects()
|
||||||
devices = []
|
# devices that support ad-hoc
|
||||||
for name, obj in objects.items():
|
adhoc_devices = []
|
||||||
|
# devices that support ap
|
||||||
|
ap_devices = []
|
||||||
|
for path, obj in objects.items():
|
||||||
if "net.connman.iwd.Device" in obj:
|
if "net.connman.iwd.Device" in obj:
|
||||||
# add all devices to the list
|
# add all devices to the list
|
||||||
print("Found device:", obj["net.connman.iwd.Device"]["Name"])
|
name = obj["net.connman.iwd.Device"]["Name"]
|
||||||
devices.append(name)
|
print("Found device:", name)
|
||||||
|
adapter_path = obj["net.connman.iwd.Device"]["Adapter"].get_string()
|
||||||
|
adapter = objects[adapter_path]["net.connman.iwd.Adapter"]
|
||||||
|
if "ad-hoc" in adapter["SupportedModes"]:
|
||||||
|
print(name, "supports ad-hoc")
|
||||||
|
adhoc_devices.append(path)
|
||||||
|
if "ap" in adapter["SupportedModes"]:
|
||||||
|
print(name, "supports ap")
|
||||||
|
ap_devices.append(path)
|
||||||
|
print(objects)
|
||||||
|
print(adhoc_devices)
|
||||||
|
print(ap_devices)
|
||||||
|
|
||||||
|
if len(adhoc_devices) != 0:
|
||||||
# Start ad-hoc on first device
|
# Start ad-hoc on first device
|
||||||
devpath = devices.pop()
|
dev1path = adhoc_devices.pop()
|
||||||
print("Working on first device", devpath)
|
# Remove device from ap_devices if it exists there
|
||||||
dev1 = bus.get_proxy("net.connman.iwd", devpath)
|
if dev1path in ap_devices:
|
||||||
|
ap_devices.remove(dev1path)
|
||||||
|
print("Working on AP")
|
||||||
|
dev1 = bus.get_proxy("net.connman.iwd", dev1path)
|
||||||
|
print("Starting ad-hoc on", dev1.Name)
|
||||||
if not dev1.Powered:
|
if not dev1.Powered:
|
||||||
print("Device is off. Turning on")
|
print("Device is off. Turning on")
|
||||||
dev1.Powered = True
|
dev1.Powered = True
|
||||||
@ -76,11 +95,20 @@ try:
|
|||||||
print("Switching to ad-hoc")
|
print("Switching to ad-hoc")
|
||||||
dev1.Mode = "ad-hoc"
|
dev1.Mode = "ad-hoc"
|
||||||
# Changing Mode needs connecting to the proxy again
|
# Changing Mode needs connecting to the proxy again
|
||||||
dev1 = bus.get_proxy("net.connman.iwd", devpath)
|
dev1 = bus.get_proxy("net.connman.iwd", dev1path)
|
||||||
print("Starting ad-hoc network")
|
print("Starting ad-hoc network")
|
||||||
dev1.StartOpen(ADHOC_SSID)
|
dev1.StartOpen(ADHOC_SSID)
|
||||||
# TODO: If there is a second device, start AP
|
|
||||||
# in it
|
# Start Access point
|
||||||
|
if len(ap_devices) != 0:
|
||||||
|
print("Working on AP")
|
||||||
|
dev2path = ap_devices.pop()
|
||||||
|
dev2 = bus.get_proxy("net.connman.iwd", dev2path)
|
||||||
|
print("Starting AP on", dev2.Name)
|
||||||
|
if not dev1.Powered:
|
||||||
|
print("Device is off. Turning on")
|
||||||
|
dev1.Powered = True
|
||||||
|
# TODO: Start AP on dev2
|
||||||
except DBusError:
|
except DBusError:
|
||||||
sys.exit("An error occured while communicating with iwd")
|
sys.exit("An error occured while communicating with iwd")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user