- first prototype of API enabled agent_gsm
This commit is contained in:
@@ -533,9 +533,11 @@ if __name__ == '__main__':
|
||||
utils.log_error(f'Failed to obtain information about {BACKEND.instance}. Exiting.')
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
if not BACKEND.online:
|
||||
# Start own hotspot and API server
|
||||
agent_point.start()
|
||||
# if not BACKEND.online:
|
||||
|
||||
# Start own hotspot and API server
|
||||
agent_point.CACHE = CACHE
|
||||
agent_point.start()
|
||||
|
||||
# Cache phone information
|
||||
CACHE.put_phone(BACKEND.phone)
|
||||
|
||||
60
src/agent_point.py
Normal file → Executable file
60
src/agent_point.py
Normal file → Executable file
@@ -1,54 +1,80 @@
|
||||
#!/usr/bin/python3
|
||||
import PyAccessPoint
|
||||
import bottle
|
||||
import multiprocessing
|
||||
from PyAccessPoint import pyaccesspoint
|
||||
import time
|
||||
import os
|
||||
import utils_cache
|
||||
|
||||
class AccessPoint:
|
||||
active: bool = False
|
||||
ap: pyaccesspoint.AccessPoint = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def start(self):
|
||||
if self.ap is not None:
|
||||
return
|
||||
|
||||
self.ap = pyaccesspoint.AccessPoint(ssid='agent_gsm', password='qwerty')
|
||||
if not self.ap.start():
|
||||
raise RuntimeError(f'Failed to start WiFi access point.')
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
if self.ap is None:
|
||||
return
|
||||
|
||||
if not self.ap.stop():
|
||||
raise RuntimeError(f'Failed to stop Wifi access point')
|
||||
self.ap = None
|
||||
pass
|
||||
|
||||
ACCESS_POINT = AccessPoint()
|
||||
SERVER_PROCESS = None
|
||||
RESPONSE_OK = {'status': 'ok'}
|
||||
CACHE : utils_cache.InfoCache = None
|
||||
|
||||
@bottle.route('/status')
|
||||
def web_status():
|
||||
return "OK"
|
||||
print(f'Serving /status request...')
|
||||
return RESPONSE_OK
|
||||
|
||||
@bottle.route('/reboot')
|
||||
def web_reboot():
|
||||
os.system('sudo reboot')
|
||||
return RESPONSE_OK
|
||||
|
||||
@bottle.route('/stop')
|
||||
def web_reboot():
|
||||
os.system('sudo halt')
|
||||
return RESPONSE_OK
|
||||
|
||||
@bottle.route('/cache')
|
||||
def web_list_cache():
|
||||
result = []
|
||||
if CACHE is None:
|
||||
return result
|
||||
|
||||
# Iterate cache and return available files list
|
||||
for f in os.listdir(CACHE.dir):
|
||||
result.append(f)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def web_process():
|
||||
print(f'Run web process...')
|
||||
bottle.run(host='0.0.0.0', port=8080)
|
||||
|
||||
def start():
|
||||
global SERVER_PROCESS
|
||||
global ACCESS_POINT, SERVER_PROCESS
|
||||
|
||||
ACCESS_POINT.start()
|
||||
SERVER_PROCESS = multiprocessing.Process(target=web_process)
|
||||
SERVER_PROCESS.start()
|
||||
|
||||
def stop():
|
||||
global ACCESS_POINT, SERVER_PROCESS
|
||||
|
||||
ACCESS_POINT.stop()
|
||||
SERVER_PROCESS.kill()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Start test stuff
|
||||
start()
|
||||
|
||||
# Wait 120 seconds for tests
|
||||
time.sleep(120.0)
|
||||
|
||||
# Stop test
|
||||
stop()
|
||||
|
||||
@@ -19,8 +19,6 @@ class InfoCache:
|
||||
utils.log_error(str(e))
|
||||
self.dir = None
|
||||
|
||||
|
||||
|
||||
def is_active(self) -> bool:
|
||||
return self.dir is not None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user