|
|
@@ -1,8 +1,10 @@
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
+import logging
|
|
|
import configparser
|
|
|
import lib.config
|
|
|
import lib.app_control
|
|
|
+import lib.bluetooth
|
|
|
|
|
|
# we need to initially load the configuration file.
|
|
|
# This is loaded via a local symlink
|
|
|
@@ -17,6 +19,22 @@ import atexit
|
|
|
atexit.register(lib.app_control.myCar_exit, myCar_config)
|
|
|
|
|
|
|
|
|
+# lets start with log handling here
|
|
|
+import logging, os
|
|
|
+from pathlib import Path
|
|
|
+# first check, if the logentry is a directory
|
|
|
+if Path(myCar_config['paths'].get('log')).is_dir():
|
|
|
+ # now check if we can write ther:
|
|
|
+ myCar_logfile=myCar_config['paths'].get('log') + '/' + 'myCar_Application.log'
|
|
|
+ try:
|
|
|
+ fp = open(myCar_logfile , 'w')
|
|
|
+ except PermissionError:
|
|
|
+ logging.warning('directory ' + myCar_logfile + ' not writeable')
|
|
|
+ else:
|
|
|
+ fp.close()
|
|
|
+ logging.basicConfig(filename=myCar_logfile,level=logging.INFO)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
from flask import Flask
|
|
|
from flask import url_for
|
|
|
@@ -28,30 +46,18 @@ app = Flask(__name__)
|
|
|
|
|
|
@app.route('/')
|
|
|
def myCar_root():
|
|
|
- return render_template('index.html')
|
|
|
+ return render_template('index.html', bt_ctrl_ispowered=lib.bluetooth.bt_ctrl_ispowered())
|
|
|
|
|
|
@app.route('/bluetooth/controller')
|
|
|
def myCar_bluetooth_controller():
|
|
|
- # this method will return available bluetooth devices as a list for the web template output
|
|
|
- import bluew
|
|
|
- #return len(bluew.controllers())
|
|
|
- return render_template('bluetooth/controller.html', bt_ctrl=bluew.controllers())
|
|
|
+ return render_template('bluetooth/controller.html', bt_ctrl=lib.bluetooth.bt_getControllers())
|
|
|
|
|
|
@app.route('/bluetooth/devices')
|
|
|
def myCar_bluetooth_devices():
|
|
|
- # this method will return available bluetooth devices as a list for the web template output
|
|
|
- import bluew
|
|
|
- #return len(bluew.controllers())
|
|
|
- bt_ctrl_powered = False
|
|
|
-
|
|
|
- for dev in bluew.controllers():
|
|
|
- if dev.Powered == True:
|
|
|
- bt_ctrl_powered = True
|
|
|
-
|
|
|
- if bt_ctrl_powered == False:
|
|
|
- return render_template('bluetooth/controller.html', bt_ctrl=bluew.controllers(), bt_error="All Bluetooth Adapters are powered off")
|
|
|
+ if lib.bluetooth.bt_ctrl_ispowered == False:
|
|
|
+ return render_template('bluetooth/controller.html', bt_ctrl=lib.bluetooth.bt_getControllers(), bt_error="All Bluetooth Adapters are powered off")
|
|
|
else:
|
|
|
- return render_template('bluetooth/devices.html', bt_dev=bluew.devices())
|
|
|
+ return render_template('bluetooth/devices.html', bt_dev=lib.bluetooth.bt_getDevices())
|
|
|
|
|
|
@app.route('/bluetooth/connect', methods=['POST'])
|
|
|
def myCar_bluetooth_connect():
|
|
|
@@ -71,6 +77,8 @@ def myCar_bluetooth_connect():
|
|
|
|
|
|
#try:
|
|
|
bt_dst_mac = request.form['bt_dst_mac']
|
|
|
+
|
|
|
+ logging.info('Bluetooth trying to connect to ' + bt_dst_mac)
|
|
|
# pair
|
|
|
bluew.pair(bt_dst_mac)
|
|
|
|
|
|
@@ -117,3 +125,30 @@ def myCar_conf_save():
|
|
|
return redirect(url_for('myCar_conf'), code=302)
|
|
|
|
|
|
|
|
|
+@app.route('/gps')
|
|
|
+def myCar_gps():
|
|
|
+ # dummy implementation before code is ready
|
|
|
+ return render_template('empty.html')
|
|
|
+
|
|
|
+@app.route('/wifi')
|
|
|
+def myCar_wifi():
|
|
|
+ # dummy implementation before code is ready
|
|
|
+ return render_template('empty.html')
|
|
|
+
|
|
|
+@app.route('/system')
|
|
|
+def myCar_system():
|
|
|
+ # dummy implementation before code is ready
|
|
|
+ return render_template('empty.html')
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/live')
|
|
|
+def myCar_live():
|
|
|
+ # dummy implementation before code is ready
|
|
|
+ return render_template('empty.html')
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/record')
|
|
|
+def myCar_record():
|
|
|
+ # dummy implementation before code is ready
|
|
|
+ return render_template('empty.html')
|
|
|
+
|