From 588a1fd09972bfc4e2c78503badd7a2d30d77db1 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:10:25 +0000 Subject: [PATCH 01/28] Gitignore set --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..29d7f1e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea +*.pyc \ No newline at end of file From b99c416f2f4b7cf6076318ec2a2cb22ecb2f3d32 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:10:37 +0000 Subject: [PATCH 02/28] Turn on debug mode - revert this before production --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 01784b55..b60b2354 100644 --- a/glass_server.py +++ b/glass_server.py @@ -111,7 +111,7 @@ def trigger_event_endpoint(event_name): - app.run(host='0.0.0.0', port=4000, debug=False) + app.run(host='0.0.0.0', port=4000, debug=True) # SimConnect App def simconnect_thread_func(threadname): From 861bbc08366eadde8d9c2a6e3ce613b670e9c00b Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:11:44 +0000 Subject: [PATCH 03/28] Add the plugin and import it --- findmyplane_plugin.py | 105 ++++++++++++++++++++++++++++++++++++++++++ glass_server.py | 1 + 2 files changed, 106 insertions(+) create mode 100644 findmyplane_plugin.py diff --git a/findmyplane_plugin.py b/findmyplane_plugin.py new file mode 100644 index 00000000..c648054d --- /dev/null +++ b/findmyplane_plugin.py @@ -0,0 +1,105 @@ +# +# This plugin can be used in your projects to add functionality related to Find My Plane +# It is a simple wrapper for the Find My Plane API, the full docs of which are available at http://findmyplane.live/api +# +# Example workflow is available in example.py +# + + +import requests + +server_url = "https://findmyplane.live/" +api_url = server_url + "api" + +connected_to_instance = False +ident_public_key = None +ident_private_key = None + +first_datapoint = True + + +def set_keys(ident_public_key_to_set, ident_private_key_to_set): + global ident_public_key + global ident_private_key + global connected_to_instance + global first_datapoint + + ident_public_key = ident_public_key_to_set + ident_private_key = ident_private_key_to_set + first_datapoint = True + connected_to_instance = True + + +def request_new_plane_instance(plane_title=None, atc_id=None, client=None): + + endpoint_url = "/create_new_plane" + url = api_url + endpoint_url + + values = {'title': plane_title, + 'atc_id': atc_id, + 'client': client} + + try: + r = requests.post(url, json=values) + plane_object = r.json() + set_keys(plane_object['ident_public_key'], plane_object['ident_private_key']) + except: + plane_object = {'status': 'error'} + + return plane_object + + +def disconnect_from_plane_instance(): + global ident_public_key + global ident_private_key + global connected_to_instance + global first_datapoint + + ident_public_key = None + ident_private_key = None + connected_to_instance = False + first_datapoint = True + + +def set_plane_location(current_latitude, current_longitude, current_compass, current_altitude, current_speed = None): + + if connection_status() != "connected": + return "error: not connected" + + global first_datapoint + + endpoint_url = "/update_plane_location" + url = api_url + endpoint_url + + values = {'ident_public_key': ident_public_key, + 'ident_private_key': ident_private_key, + 'current_latitude': current_latitude, + 'current_longitude': current_longitude, + 'current_compass': current_compass, + 'current_altitude': current_altitude} + + if current_speed is not None: values['current_speed'] = current_speed + + try: + r = requests.post(url, json=values) + if first_datapoint: + r = requests.post(url, json=values) + first_datapoint = False + except: + return "error: request failed" + + return "success" + + +def connection_status(): + if connected_to_instance: + return "connected" + else: + return "disconnected" + + +def url_to_view(): + if connection_status() == "connected": + return server_url + "view/" + ident_public_key + else: + return "no url set as not connected to instance" diff --git a/glass_server.py b/glass_server.py index b60b2354..c35c6062 100644 --- a/glass_server.py +++ b/glass_server.py @@ -8,6 +8,7 @@ import asyncio from threading import Thread import datetime +import findmyplane_plugin print (socket.gethostbyname(socket.gethostname())) From 59fcf9b904496a9cb50c8b3332de77e6cbd5302d Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:27:20 +0000 Subject: [PATCH 04/28] Add functionality to connect/disconnect from plane instances --- findmyplane_plugin.py | 2 +- glass_server.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/findmyplane_plugin.py b/findmyplane_plugin.py index c648054d..8ed818ea 100644 --- a/findmyplane_plugin.py +++ b/findmyplane_plugin.py @@ -46,7 +46,7 @@ def request_new_plane_instance(plane_title=None, atc_id=None, client=None): except: plane_object = {'status': 'error'} - return plane_object + return {'status': 'success'} def disconnect_from_plane_instance(): diff --git a/glass_server.py b/glass_server.py index c35c6062..35f7e7a8 100644 --- a/glass_server.py +++ b/glass_server.py @@ -110,8 +110,30 @@ def trigger_event_endpoint(event_name): return jsonify(status) - - + # Find my plane routes + @app.route('/findmyplane/status/', methods=["GET"]) + @app.route('/findmyplane/status/', methods=["POST"]) + def findmyplane_set_status(status_to_set): + + if request.method == "GET": + return jsonify({'status': findmyplane_plugin.connection_status(), + 'ident_public_key': findmyplane_plugin.ident_public_key, + 'url_to_view': findmyplane_plugin.url_to_view() + }) + + if request.method == "POST": + if status_to_set == "disconnected": + findmyplane_plugin.disconnect_from_plane_instance() + return jsonify({'status': 'disconnected'}) + + if status_to_set == "connected": + findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") + if findmyplane_connection_attempt['status'] == "success": + return jsonify({'status': 'connected'}) + else: + return jsonify({'status': 'error'}) + + app.run(host='0.0.0.0', port=4000, debug=True) # SimConnect App From 9706485749473c220899714d2ccfb11d600b81ff Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:33:44 +0000 Subject: [PATCH 05/28] Minor tidy ups --- glass_server.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/glass_server.py b/glass_server.py index 35f7e7a8..02f4a98e 100644 --- a/glass_server.py +++ b/glass_server.py @@ -109,30 +109,38 @@ def trigger_event_endpoint(event_name): status = trigger_event(event_name, value_to_use) return jsonify(status) - - # Find my plane routes + + + # START: Find my plane routes + @app.route('/findmyplane/status/', methods=["GET"]) @app.route('/findmyplane/status/', methods=["POST"]) + # This route allows the front end to query and set the connection status def findmyplane_set_status(status_to_set): + # Returns the current status, the public ident and the URL link through a GET request if request.method == "GET": return jsonify({'status': findmyplane_plugin.connection_status(), 'ident_public_key': findmyplane_plugin.ident_public_key, 'url_to_view': findmyplane_plugin.url_to_view() }) + # Allows the front end to set the connection status Passing "connected" will create a new plane instance + # Passing "disconnected" will disconnect from the instance, which will prompt the server to delete it in due + # course if it doesn't receive more data if request.method == "POST": if status_to_set == "disconnected": findmyplane_plugin.disconnect_from_plane_instance() return jsonify({'status': 'disconnected'}) if status_to_set == "connected": - findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") + findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description if findmyplane_connection_attempt['status'] == "success": return jsonify({'status': 'connected'}) else: return jsonify({'status': 'error'}) + #END: Find my plane routes app.run(host='0.0.0.0', port=4000, debug=True) From adaf9980cad2a2b7ecef897d5d2f6fd17d1fc0ce Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 11:34:16 +0000 Subject: [PATCH 06/28] Another tidy --- glass_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 02f4a98e..59b43d09 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,6 +113,7 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes + @app.route('/findmyplane/status/', methods=["GET"]) @app.route('/findmyplane/status/', methods=["POST"]) # This route allows the front end to query and set the connection status @@ -140,7 +141,7 @@ def findmyplane_set_status(status_to_set): else: return jsonify({'status': 'error'}) - #END: Find my plane routes + # END: Find my plane routes app.run(host='0.0.0.0', port=4000, debug=True) From 790238948ddd8353c85b83436df4a4b50a4f50f8 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:03:31 +0000 Subject: [PATCH 07/28] Debug doesn't work so removing it --- glass_server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/glass_server.py b/glass_server.py index 59b43d09..2d6d2103 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,7 +113,6 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes - @app.route('/findmyplane/status/', methods=["GET"]) @app.route('/findmyplane/status/', methods=["POST"]) # This route allows the front end to query and set the connection status @@ -126,9 +125,9 @@ def findmyplane_set_status(status_to_set): 'url_to_view': findmyplane_plugin.url_to_view() }) - # Allows the front end to set the connection status Passing "connected" will create a new plane instance + # Allows the front end to set the connection status. Passing "connected" will create a new plane instance. # Passing "disconnected" will disconnect from the instance, which will prompt the server to delete it in due - # course if it doesn't receive more data + # course if it doesn't receive more data. if request.method == "POST": if status_to_set == "disconnected": findmyplane_plugin.disconnect_from_plane_instance() @@ -143,7 +142,7 @@ def findmyplane_set_status(status_to_set): # END: Find my plane routes - app.run(host='0.0.0.0', port=4000, debug=True) + app.run(host='0.0.0.0', port=4000, debug=False) # SimConnect App def simconnect_thread_func(threadname): From d0ae38a7a684992c12d0b1de1bdb55c1451c53af Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:05:35 +0000 Subject: [PATCH 08/28] Update glass_server.py --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 2d6d2103..6de5a999 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,7 +113,7 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes - @app.route('/findmyplane/status/', methods=["GET"]) + @app.route('/findmyplane/status', methods=["GET"]) @app.route('/findmyplane/status/', methods=["POST"]) # This route allows the front end to query and set the connection status def findmyplane_set_status(status_to_set): From cb61b55975093e89527a9ce4b4cc6cf0f6ec9871 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:09:20 +0000 Subject: [PATCH 09/28] Update glass_server.py --- glass_server.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/glass_server.py b/glass_server.py index 6de5a999..1d6ea28e 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,13 +113,12 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes - @app.route('/findmyplane/status', methods=["GET"]) - @app.route('/findmyplane/status/', methods=["POST"]) + @app.route('/findmyplane/status/', methods=["GET", "POST"]) # This route allows the front end to query and set the connection status - def findmyplane_set_status(status_to_set): + def findmyplane_set_status(status_to_set = "CHECK"): # Returns the current status, the public ident and the URL link through a GET request - if request.method == "GET": + if status_to_set.upper() = "CHECK" return jsonify({'status': findmyplane_plugin.connection_status(), 'ident_public_key': findmyplane_plugin.ident_public_key, 'url_to_view': findmyplane_plugin.url_to_view() @@ -128,17 +127,16 @@ def findmyplane_set_status(status_to_set): # Allows the front end to set the connection status. Passing "connected" will create a new plane instance. # Passing "disconnected" will disconnect from the instance, which will prompt the server to delete it in due # course if it doesn't receive more data. - if request.method == "POST": - if status_to_set == "disconnected": - findmyplane_plugin.disconnect_from_plane_instance() - return jsonify({'status': 'disconnected'}) - - if status_to_set == "connected": - findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description - if findmyplane_connection_attempt['status'] == "success": - return jsonify({'status': 'connected'}) - else: - return jsonify({'status': 'error'}) + if status_to_set.upper() == "disconnected": + findmyplane_plugin.disconnect_from_plane_instance() + return jsonify({'status': 'disconnected'}) + + if status_to_set.upper() == "connected": + findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description + if findmyplane_connection_attempt['status'] == "success": + return jsonify({'status': 'connected'}) + else: + return jsonify({'status': 'error'}) # END: Find my plane routes From 086118fe70a98579138d68f81f7eb187d4cd22cd Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:10:02 +0000 Subject: [PATCH 10/28] Update glass_server.py --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 1d6ea28e..f8741c02 100644 --- a/glass_server.py +++ b/glass_server.py @@ -118,7 +118,7 @@ def trigger_event_endpoint(event_name): def findmyplane_set_status(status_to_set = "CHECK"): # Returns the current status, the public ident and the URL link through a GET request - if status_to_set.upper() = "CHECK" + if status_to_set.upper() == "CHECK" return jsonify({'status': findmyplane_plugin.connection_status(), 'ident_public_key': findmyplane_plugin.ident_public_key, 'url_to_view': findmyplane_plugin.url_to_view() From e162ce23416aa4a2519896e5c4ee404e26c34193 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:10:22 +0000 Subject: [PATCH 11/28] Update glass_server.py --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index f8741c02..8ac33998 100644 --- a/glass_server.py +++ b/glass_server.py @@ -118,7 +118,7 @@ def trigger_event_endpoint(event_name): def findmyplane_set_status(status_to_set = "CHECK"): # Returns the current status, the public ident and the URL link through a GET request - if status_to_set.upper() == "CHECK" + if status_to_set.upper() == "CHECK": return jsonify({'status': findmyplane_plugin.connection_status(), 'ident_public_key': findmyplane_plugin.ident_public_key, 'url_to_view': findmyplane_plugin.url_to_view() From b706025ae1ac14d5096b93b01a27836e13eff40c Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:12:58 +0000 Subject: [PATCH 12/28] Trying with debug --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 8ac33998..674c100c 100644 --- a/glass_server.py +++ b/glass_server.py @@ -140,7 +140,7 @@ def findmyplane_set_status(status_to_set = "CHECK"): # END: Find my plane routes - app.run(host='0.0.0.0', port=4000, debug=False) + app.run(host='0.0.0.0', port=4000, debug=True, use_reloader=False) # SimConnect App def simconnect_thread_func(threadname): From 21afadea8518350366833a5adc72c19f18d1bc30 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:14:58 +0000 Subject: [PATCH 13/28] Update glass_server.py --- glass_server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/glass_server.py b/glass_server.py index 674c100c..ad3ff46a 100644 --- a/glass_server.py +++ b/glass_server.py @@ -127,17 +127,19 @@ def findmyplane_set_status(status_to_set = "CHECK"): # Allows the front end to set the connection status. Passing "connected" will create a new plane instance. # Passing "disconnected" will disconnect from the instance, which will prompt the server to delete it in due # course if it doesn't receive more data. - if status_to_set.upper() == "disconnected": + if status_to_set.upper() == "DISCONNECTED": findmyplane_plugin.disconnect_from_plane_instance() return jsonify({'status': 'disconnected'}) - if status_to_set.upper() == "connected": + if status_to_set.upper() == "CONNECTED": findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description if findmyplane_connection_attempt['status'] == "success": return jsonify({'status': 'connected'}) else: return jsonify({'status': 'error'}) + return jsonify({'status': 'error', 'reason': 'no valid command passed'}) + # END: Find my plane routes app.run(host='0.0.0.0', port=4000, debug=True, use_reloader=False) From a4bc6f942f0b1f8b86b561d3f5eb92fa9491035e Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:16:40 +0000 Subject: [PATCH 14/28] Update glass_server.py --- glass_server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/glass_server.py b/glass_server.py index ad3ff46a..1c03aff0 100644 --- a/glass_server.py +++ b/glass_server.py @@ -134,8 +134,10 @@ def findmyplane_set_status(status_to_set = "CHECK"): if status_to_set.upper() == "CONNECTED": findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description if findmyplane_connection_attempt['status'] == "success": + print ("success") return jsonify({'status': 'connected'}) else: + print ("failed") return jsonify({'status': 'error'}) return jsonify({'status': 'error', 'reason': 'no valid command passed'}) From 0517f054d1314585fe1b1223c6e03fc78cb2e19f Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:20:17 +0000 Subject: [PATCH 15/28] Update glass_server.py --- glass_server.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/glass_server.py b/glass_server.py index 1c03aff0..3bae88dd 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,29 +113,35 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes - @app.route('/findmyplane/status/', methods=["GET", "POST"]) + @app.route('/findmyplane/status', endpoint="check") + @app.route('/findmyplane/status/set/', endpoint="set") # This route allows the front end to query and set the connection status - def findmyplane_set_status(status_to_set = "CHECK"): + def findmyplane_set_status(status_to_set = "check"): - # Returns the current status, the public ident and the URL link through a GET request - if status_to_set.upper() == "CHECK": + if request.endpoint == "check": return jsonify({'status': findmyplane_plugin.connection_status(), 'ident_public_key': findmyplane_plugin.ident_public_key, + 'ident_private_key': findmyplane_plugin.ident_private_key, 'url_to_view': findmyplane_plugin.url_to_view() }) # Allows the front end to set the connection status. Passing "connected" will create a new plane instance. # Passing "disconnected" will disconnect from the instance, which will prompt the server to delete it in due # course if it doesn't receive more data. - if status_to_set.upper() == "DISCONNECTED": + if status_to_set.lower() == "disconnected": findmyplane_plugin.disconnect_from_plane_instance() return jsonify({'status': 'disconnected'}) - if status_to_set.upper() == "CONNECTED": + if status_to_set.lower() == "connected": findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description if findmyplane_connection_attempt['status'] == "success": print ("success") - return jsonify({'status': 'connected'}) + return jsonify({ + 'status': 'connected', + 'ident_public_key': findmyplane_plugin.ident_public_key, + 'ident_private_key': findmyplane_plugin.ident_private_key, + 'url_to_view': findmyplane_plugin.url_to_view() + }) else: print ("failed") return jsonify({'status': 'error'}) From 34fe154f93c836af70d130500c5ea6dcdfbde137 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:21:36 +0000 Subject: [PATCH 16/28] Update glass_server.py --- glass_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 3bae88dd..24cc48a8 100644 --- a/glass_server.py +++ b/glass_server.py @@ -113,7 +113,7 @@ def trigger_event_endpoint(event_name): # START: Find my plane routes - @app.route('/findmyplane/status', endpoint="check") + @app.route('/findmyplane/status/check', endpoint="check") @app.route('/findmyplane/status/set/', endpoint="set") # This route allows the front end to query and set the connection status def findmyplane_set_status(status_to_set = "check"): From 68fe8f90614ed64a2b173251e0e6679cd166d7e0 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:29:41 +0000 Subject: [PATCH 17/28] Update glass_server.py --- glass_server.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/glass_server.py b/glass_server.py index 24cc48a8..9f064d28 100644 --- a/glass_server.py +++ b/glass_server.py @@ -35,6 +35,18 @@ def flask_thread_func(threadname): def output_ui_variables(): # Initialise dictionaru ui_friendly_dictionary["STATUS"] = "success" + + # Find my plane addition - send if activated + if findmyplane_plugin.connection_status() == "connected": + findmyplane_plugin.set_plane_location( + current_latitude = ui_friendly_dictionary["LATITUDE"], + current_longitude = ui_friendly_dictionary["LONGITUDE"], + current_compass = ui_friendly_dictionary["MAGNETIC_COMPASS"], + current_altitude = ui_friendly_dictionary["INDICATED_ALTITUDE"], + current_speed = ui_friendly_dictionary["AIRSPEED_INDICATED"] + ) + print ("Data sent to findmyplane") + return jsonify(ui_friendly_dictionary) @app.route('/') @@ -369,7 +381,7 @@ async def ui_dictionary(ui_friendly_dictionary, previous_alt, landing_t1, landin ui_friendly_dictionary["LANDING_T2"] = landing_t2 ui_friendly_dictionary["LANDING_VS3"] = landing_vs3 ui_friendly_dictionary["LANDING_T3"] = landing_t3 - + while True: asyncio.run(ui_dictionary(ui_friendly_dictionary, previous_alt, ui_friendly_dictionary["LANDING_T1"], ui_friendly_dictionary["LANDING_VS1"], ui_friendly_dictionary["LANDING_T2"], ui_friendly_dictionary["LANDING_VS2"], ui_friendly_dictionary["LANDING_T3"], ui_friendly_dictionary["LANDING_VS3"])) #sleep(0.3) From 4fd2dee2d0794965e1a6c318d37db702a2d7a976 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:35:45 +0000 Subject: [PATCH 18/28] Add option to send title and atc_id --- findmyplane_plugin.py | 6 ++++-- glass_server.py | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/findmyplane_plugin.py b/findmyplane_plugin.py index 8ed818ea..e04136da 100644 --- a/findmyplane_plugin.py +++ b/findmyplane_plugin.py @@ -61,7 +61,7 @@ def disconnect_from_plane_instance(): first_datapoint = True -def set_plane_location(current_latitude, current_longitude, current_compass, current_altitude, current_speed = None): +def set_plane_location(current_latitude, current_longitude, current_compass, current_altitude, current_speed = None, title = None, atc_id = None): if connection_status() != "connected": return "error: not connected" @@ -76,7 +76,9 @@ def set_plane_location(current_latitude, current_longitude, current_compass, cur 'current_latitude': current_latitude, 'current_longitude': current_longitude, 'current_compass': current_compass, - 'current_altitude': current_altitude} + 'current_altitude': current_altitude, + 'title': title, + 'atc_id': atc_id} if current_speed is not None: values['current_speed'] = current_speed diff --git a/glass_server.py b/glass_server.py index 9f064d28..c38b0cdf 100644 --- a/glass_server.py +++ b/glass_server.py @@ -43,7 +43,9 @@ def output_ui_variables(): current_longitude = ui_friendly_dictionary["LONGITUDE"], current_compass = ui_friendly_dictionary["MAGNETIC_COMPASS"], current_altitude = ui_friendly_dictionary["INDICATED_ALTITUDE"], - current_speed = ui_friendly_dictionary["AIRSPEED_INDICATED"] + current_speed = ui_friendly_dictionary["AIRSPEED_INDICATED"], + title = ui_friendly_dictionary["TITLE"], + atc_id = ui_friendly_dictionary["ATC_ID"] ) print ("Data sent to findmyplane") @@ -333,6 +335,10 @@ async def ui_dictionary(ui_friendly_dictionary, previous_alt, landing_t1, landin #ui_friendly_dictionary["PANEL_ANTI_ICE_SWITCH"] = await aq.get("PANEL_ANTI_ICE_SWITCH") # Sim Rate ui_friendly_dictionary["SIMULATION_RATE"] = await aq.get("SIMULATION_RATE") + # Aircraft details + ui_friendly_dictionary["TITLE"] = await aq.get("TITLE") + ui_friendly_dictionary["ATC_ID"] = await aq.get("ATC_ID") + # Current altitude From b32dff2e4d89d1a74d7072684459cfa81ffbfc12 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:38:51 +0000 Subject: [PATCH 19/28] Fix title and atc_id to be sent in plain text --- findmyplane_plugin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/findmyplane_plugin.py b/findmyplane_plugin.py index e04136da..cd4cfca4 100644 --- a/findmyplane_plugin.py +++ b/findmyplane_plugin.py @@ -61,7 +61,7 @@ def disconnect_from_plane_instance(): first_datapoint = True -def set_plane_location(current_latitude, current_longitude, current_compass, current_altitude, current_speed = None, title = None, atc_id = None): +def set_plane_location(current_latitude, current_longitude, current_compass, current_altitude, current_speed=None, title=None, atc_id=None): if connection_status() != "connected": return "error: not connected" @@ -71,6 +71,12 @@ def set_plane_location(current_latitude, current_longitude, current_compass, cur endpoint_url = "/update_plane_location" url = api_url + endpoint_url + if title is not None: + title = title.decode("utf-8") + + if atc_id is not None: + atc_id = atc_id.decode("utf-8") + values = {'ident_public_key': ident_public_key, 'ident_private_key': ident_private_key, 'current_latitude': current_latitude, From 25870ba9108baff7ef476732b8e2bf7f2758959a Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:40:40 +0000 Subject: [PATCH 20/28] Quick fix --- findmyplane_plugin.py | 6 ------ glass_server.py | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/findmyplane_plugin.py b/findmyplane_plugin.py index cd4cfca4..ca0301fc 100644 --- a/findmyplane_plugin.py +++ b/findmyplane_plugin.py @@ -71,12 +71,6 @@ def set_plane_location(current_latitude, current_longitude, current_compass, cur endpoint_url = "/update_plane_location" url = api_url + endpoint_url - if title is not None: - title = title.decode("utf-8") - - if atc_id is not None: - atc_id = atc_id.decode("utf-8") - values = {'ident_public_key': ident_public_key, 'ident_private_key': ident_private_key, 'current_latitude': current_latitude, diff --git a/glass_server.py b/glass_server.py index c38b0cdf..d83c5604 100644 --- a/glass_server.py +++ b/glass_server.py @@ -335,10 +335,17 @@ async def ui_dictionary(ui_friendly_dictionary, previous_alt, landing_t1, landin #ui_friendly_dictionary["PANEL_ANTI_ICE_SWITCH"] = await aq.get("PANEL_ANTI_ICE_SWITCH") # Sim Rate ui_friendly_dictionary["SIMULATION_RATE"] = await aq.get("SIMULATION_RATE") + # Aircraft details ui_friendly_dictionary["TITLE"] = await aq.get("TITLE") ui_friendly_dictionary["ATC_ID"] = await aq.get("ATC_ID") + if ui_friendly_dictionary["TITLE"] is not None: + ui_friendly_dictionary["TITLE"] = ui_friendly_dictionary["TITLE"].decode("utf-8") + + if ui_friendly_dictionary["ATC_ID"] is not None: + ui_friendly_dictionary["ATC_ID"] = ui_friendly_dictionary["ATC_ID"].decode("utf-8") + # Current altitude From 1758330709bf218dd96654d0f9dee97f33e017b0 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 14:44:13 +0000 Subject: [PATCH 21/28] First attempt at GUI integration --- templates/glass.html | 6 +++++- templates/menu_findmyplane.html | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 templates/menu_findmyplane.html diff --git a/templates/glass.html b/templates/glass.html index 52ae2392..90b46f36 100644 --- a/templates/glass.html +++ b/templates/glass.html @@ -90,7 +90,8 @@ - + +    @@ -111,6 +112,9 @@ {% include 'menu_panel.html' %} + + {% include 'menu_findmyplane.html' %} + {% include 'menu_other.html' %} diff --git a/templates/menu_findmyplane.html b/templates/menu_findmyplane.html new file mode 100644 index 00000000..119d9b16 --- /dev/null +++ b/templates/menu_findmyplane.html @@ -0,0 +1,18 @@ +
+
+
+ + +
+ +
+
Find My Plane
+
+
+ +
+ + +
+
+
\ No newline at end of file From e8a2b2c5029d1b5e339e8e72b86ef7ea40577c90 Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 15:01:16 +0000 Subject: [PATCH 22/28] GUI attempt --- static/js/custom/findMyPlane.js | 9 +++++++++ templates/menu_findmyplane.html | 24 ++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 static/js/custom/findMyPlane.js diff --git a/static/js/custom/findMyPlane.js b/static/js/custom/findMyPlane.js new file mode 100644 index 00000000..b716aafd --- /dev/null +++ b/static/js/custom/findMyPlane.js @@ -0,0 +1,9 @@ + + +function startFindmyplaneTracking() { + +} + +function stopFindmyplaneTracking() { + +} \ No newline at end of file diff --git a/templates/menu_findmyplane.html b/templates/menu_findmyplane.html index 119d9b16..f650db5f 100644 --- a/templates/menu_findmyplane.html +++ b/templates/menu_findmyplane.html @@ -1,17 +1,29 @@
- + +
- + +
-
Find My Plane
-
+ +
AP Master
+ +
+ + +
Online tracking status
+ +

Connection status: Disconnected

+

IDENT: N/A

+

Following Link: N/A

+ +

MSFS Mobile Companion App integrates with Find My Planeto allow you to view your flight location online with other players.

+
-
-
From 1977f687b6a96c8d811cb971b8ad345659629cee Mon Sep 17 00:00:00 2001 From: hankhank10 Date: Fri, 29 Jan 2021 15:14:22 +0000 Subject: [PATCH 23/28] GUI update --- static/js/custom/findMyPlane.js | 39 +++++++++++++++++++++++++++++++++ templates/glass.html | 2 ++ templates/menu_findmyplane.html | 5 +++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/static/js/custom/findMyPlane.js b/static/js/custom/findMyPlane.js index b716aafd..8590e2b1 100644 --- a/static/js/custom/findMyPlane.js +++ b/static/js/custom/findMyPlane.js @@ -1,9 +1,48 @@ +let findmyplaneConnectionStatus; +let findmyplaneIdentPublicKey; +let findmyplaneLinkURL; +findmyplaneConnectionStatus = "disconnected"; + +function toggleFindmyplaneTracking() { + + if (findmyplaneConnectionStatus === "disconnected") { + startFindmyplaneTracking() + } + + if (findmyplaneConnectionStatus === "connected") { + stopFindmyplaneTracking() + } + +} function startFindmyplaneTracking() { + $.getJSON($SCRIPT_ROOT + '/findmyplane/status/set/connected', {}, function(data) { + if (data.status === 'connected') { + findmyplaneConnectionStatus = 'connected'; + findmyplaneIdentPublicKey = data.ident_public_key; + findmyplaneLinkURL = data.url_to_view; + + checkAndUpdateButton("#findmyplaneMaster", 1, "Connected", "Disconnected") + //$("findmyplaneConnectionStatus").html = "Connected" + + window.alert("Connected") + } + + if (data.status === 'error') { + findmyplaneConnectionStatus = 'disconnected' + + checkAndUpdateButton("#findmyplaneMaster", 0) + window.alert("Errored") + } + }); } + + function stopFindmyplaneTracking() { + window.alert("Pass") + } \ No newline at end of file diff --git a/templates/glass.html b/templates/glass.html index 90b46f36..5633e5ef 100644 --- a/templates/glass.html +++ b/templates/glass.html @@ -251,6 +251,8 @@ + + - + diff --git a/templates/menu_findmyplane.html b/templates/menu_findmyplane.html index 0e574a41..608685d4 100644 --- a/templates/menu_findmyplane.html +++ b/templates/menu_findmyplane.html @@ -9,16 +9,16 @@
-
Online tracking with Find My Plane
- +
Online tracking with Find My Plane

+
Online tracking status
-

Connection status: Disconnected

-

IDENT: N/A

-

Following Link: N/A

+

Connection status: ?

+

IDENT: ?

+

Following Link: ?

MSFS Mobile Companion App integrates with Find My Planeto allow you to view your flight location online with other players.

From cfbb7ac8928a37e439153888ff34d02b6af19466 Mon Sep 17 00:00:00 2001 From: Mark Hankinson Date: Fri, 29 Jan 2021 22:02:24 +0100 Subject: [PATCH 27/28] Fixes --- glass_server.py | 2 +- static/js/custom/findMyPlane.js | 7 ++++--- templates/menu_findmyplane.html | 29 ++++++++++++++++++++++------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/glass_server.py b/glass_server.py index c9ee0ecd..2615e834 100644 --- a/glass_server.py +++ b/glass_server.py @@ -164,7 +164,7 @@ def findmyplane_status(status_to_set = "check"): # END: Find my plane routes - app.run(host='0.0.0.0', port=4000, debug=True, use_reloader=False) + app.run(host='0.0.0.0', port=4000, debug=False, use_reloader=False) # SimConnect App def simconnect_thread_func(threadname): diff --git a/static/js/custom/findMyPlane.js b/static/js/custom/findMyPlane.js index 7dabe45d..e34ed475 100644 --- a/static/js/custom/findMyPlane.js +++ b/static/js/custom/findMyPlane.js @@ -3,6 +3,7 @@ let findmyplaneIdentPublicKey; let findmyplaneUrlToView; findmyplaneConnectionStatus = 0; +startFindmyplaneTracking(); function findmyplaneUpdateDisplay() { @@ -10,15 +11,15 @@ function findmyplaneUpdateDisplay() { console.log (findmyplaneConnectionStatus) if (findmyplaneConnectionStatus === 1) { $("#findmyplaneMaster").removeClass("btn-danger").addClass("btn-success").html("Connected to Find My Plane"); - $("#findmyplaneMenuButton").removeClass("btn-danger").addClass("btn-success") + $("#findmyplaneMenuButton").removeClass("btn-danger").addClass("btn-success"); $("#findmyplaneConnectionStatusLabel").text("Connected to Find My Plane"); - $("#findmyplaneIdentLabel").text(findmyplaneIdentPublicKey); + $("#findmyplaneIdentLabel").text(findmyplaneIdentPublicKey).attr('style', 'color: green'); $("#findmyplaneFollowingUrlLabel").html(''+findmyplaneUrlToView+''); } else { $("#findmyplaneMaster").addClass("btn-danger").removeClass("btn-success").html("Disconnected - click to connect"); $("#findmyplaneMenuButton").addClass("btn-danger").removeClass("btn-success") $("#findmyplaneConnectionStatusLabel").text("Disconnected from Find My Plane"); - $("#findmyplaneIdentLabel").text("N/A"); + $("#findmyplaneIdentLabel").text("N/A").attr('style', 'color: red'); $("#findmyplaneFollowingUrlLabel").html("N/A"); } diff --git a/templates/menu_findmyplane.html b/templates/menu_findmyplane.html index 608685d4..9abde499 100644 --- a/templates/menu_findmyplane.html +++ b/templates/menu_findmyplane.html @@ -11,17 +11,32 @@
Online tracking with Find My Plane

-
+ +
+

MSFS Mobile Companion App integrates with Find My Plane to allow you to view your flight location online with other players.

+
-
Online tracking status
-

Connection status: ?

-

IDENT: ?

-

Following Link: ?

-

+
Online tracking status
-

MSFS Mobile Companion App integrates with Find My Planeto allow you to view your flight location online with other players.

+
+
+ +
+ + +
+
+ + +
+ +

Live link: ?

+

+ +
+
From 5308fbc7b78388247190e2a8e9fee37dd7798858 Mon Sep 17 00:00:00 2001 From: Mark Hankinson Date: Fri, 29 Jan 2021 22:18:51 +0100 Subject: [PATCH 28/28] Final update --- glass_server.py | 3 --- static/js/custom/findMyPlane.js | 11 ++++++++++- templates/menu_findmyplane.html | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/glass_server.py b/glass_server.py index 2615e834..48053bb6 100644 --- a/glass_server.py +++ b/glass_server.py @@ -47,7 +47,6 @@ def output_ui_variables(): title = ui_friendly_dictionary["TITLE"], atc_id = ui_friendly_dictionary["ATC_ID"] ) - print ("Data sent to findmyplane") return jsonify(ui_friendly_dictionary) @@ -149,7 +148,6 @@ def findmyplane_status(status_to_set = "check"): if status_to_set.lower() == "connected": findmyplane_connection_attempt = findmyplane_plugin.request_new_plane_instance(client="Mobile Companion App") #Let me know if you are happy with this client description if findmyplane_connection_attempt['status'] == "success": - print ("success") return jsonify({ 'status': 'connected', 'ident_public_key': findmyplane_plugin.ident_public_key, @@ -157,7 +155,6 @@ def findmyplane_status(status_to_set = "check"): 'url_to_view': findmyplane_plugin.url_to_view() }) else: - print ("failed") return jsonify({'status': 'error'}) return jsonify({'status': 'error', 'reason': 'no valid command passed'}) diff --git a/static/js/custom/findMyPlane.js b/static/js/custom/findMyPlane.js index e34ed475..efc9acb0 100644 --- a/static/js/custom/findMyPlane.js +++ b/static/js/custom/findMyPlane.js @@ -14,13 +14,16 @@ function findmyplaneUpdateDisplay() { $("#findmyplaneMenuButton").removeClass("btn-danger").addClass("btn-success"); $("#findmyplaneConnectionStatusLabel").text("Connected to Find My Plane"); $("#findmyplaneIdentLabel").text(findmyplaneIdentPublicKey).attr('style', 'color: green'); - $("#findmyplaneFollowingUrlLabel").html(''+findmyplaneUrlToView+''); + $("#findmyplaneFollowingUrlButton").show(); + $("#findmyplaneFollowingUrlLabel").html(findmyplaneUrlToView); } else { $("#findmyplaneMaster").addClass("btn-danger").removeClass("btn-success").html("Disconnected - click to connect"); $("#findmyplaneMenuButton").addClass("btn-danger").removeClass("btn-success") $("#findmyplaneConnectionStatusLabel").text("Disconnected from Find My Plane"); $("#findmyplaneIdentLabel").text("N/A").attr('style', 'color: red'); $("#findmyplaneFollowingUrlLabel").html("N/A"); + $("#findmyplaneFollowingUrlButton").hide(); + } } @@ -44,4 +47,10 @@ function startFindmyplaneTracking() { function stopFindmyplaneTracking() { $.getJSON($SCRIPT_ROOT + '/findmyplane/status/set/disconnected', {}, function(data) {}); +} + +function goToTrackingUrl() { + + window.open(findmyplaneUrlToView,"blank") + } \ No newline at end of file diff --git a/templates/menu_findmyplane.html b/templates/menu_findmyplane.html index 9abde499..b02cfef8 100644 --- a/templates/menu_findmyplane.html +++ b/templates/menu_findmyplane.html @@ -13,7 +13,7 @@
-

MSFS Mobile Companion App integrates with Find My Plane to allow you to view your flight location online with other players.

+

MSFS Mobile Companion App integrates with Find My Plane to allow you to view your flight location online with other pilots. Just use the ident code below on the website or click the link.


@@ -32,7 +32,8 @@
-

Live link: ?

+
+