autocommit

This commit is contained in:
ALIHAN DIKEL
2024-10-29 21:13:53 +03:00
parent af9b78f28a
commit 104da61427
2 changed files with 28 additions and 47 deletions

View File

@@ -1,3 +1,5 @@
import os
import subprocess
import time import time
from loguru import logger from loguru import logger
@@ -5,62 +7,40 @@ import re
import nmcli import nmcli
from pythonping import ping from pythonping import ping
# nmcli connection show djituad2_plus # nmcli connection show djituad2_plus
import os
tello_ssid = os.environ["TELLO_SSID_NAME"] tello_ssid = os.environ["TELLO_SSID_NAME"]
conns = nmcli.connection() conns = nmcli.connection()
def renew_ip_wlan1(timeout=15):
try:
# Release the IP address on wlan1
release_cmd = ["sudo", "dhclient", "-r", "wlan1"]
release_process = subprocess.run(release_cmd, capture_output=True, text=True, timeout=timeout)
# Renew the IP address on wlan1
renew_cmd = ["sudo", "timeout", str(timeout), "dhclient", "-v", "wlan1"]
renew_process = subprocess.run(renew_cmd, capture_output=True, text=True, timeout=timeout)
result_info = {
"release_stdout": release_process.stdout,
"release_stderr": release_process.stderr,
"renew_stdout": renew_process.stdout,
"renew_stderr": renew_process.stderr,
"renew_status": renew_process.returncode
}
return result_info
except subprocess.TimeoutExpired:
return {"error": "timeout"}
except Exception as e:
return {"error": str(e)}
if __name__ == "__main__": if __name__ == "__main__":
info = renew_ip_wlan1()
print(info)
""" SANDBOX
while True:
ping_resp = ping('192.168.10.1', count=1, timeout=5, size=1, verbose=True)
if ping_resp.packet_loss == 0:
logger.success("found tello")
else:
logger.warning("no tello exist")
while True:
start_time = time.time()
print("###### start")
nmcli.device.wifi_rescan()
wifi_list = nmcli.device.wifi()
end_time = time.time()
duration = end_time - start_time
print(f"WiFi scan duration: {duration:.2f} seconds")
for wifi in wifi_list:
if re.search(r"djituad2", wifi.ssid):
print(wifi)
import pywifi
from pywifi import const
import time
nmcli.connection.up(name=tello_ssid, wait=10)
wifi = pywifi.PyWiFi()
ifaces = wifi.interfaces()
for iface in ifaces:
if iface == "wlan1":
break
while True:
iface.scan()
time.sleep(2)
results = iface.scan_results()
for network in results:
if re.search(r"djituad2", network.ssid):
logger.success("tello network found")
#print(f"SSID: {network.ssid}, Signal: {network.signal}")
"""

View File

@@ -64,6 +64,7 @@ async def collect_flight_stats(state):
logger.debug(f"Battery: {bat} - Temperature: {temp} - Barometer: {baro}") logger.debug(f"Battery: {bat} - Temperature: {temp} - Barometer: {baro}")
except TelloException as te: except TelloException as te:
logger.error(te) logger.error(te)
# search for any response if disconnected
else: else:
if counter % 10 == 0: if counter % 10 == 0:
logger.warning("missing connection, pinging tello") logger.warning("missing connection, pinging tello")