diff --git a/bridge_gps_data.py b/bridge_gps_data.py index 4604cc9..2219852 100755 --- a/bridge_gps_data.py +++ b/bridge_gps_data.py @@ -183,6 +183,18 @@ def dashboard_bb_write(call, dmr_id, time, bulletin): user_bb_file.close() logger.info('User bulletin entry saved.') #logger.info(dash_bb) + +def sos_write(dmr_id, time, message): + user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + try: + sos_call = user_settings[dmr_id][0]['call'] + '-' + user_settings[dmr_id][1]['ssid'] + except: + sos_call = str(get_alias((dmr_id), subscriber_ids)) + sos_info = {'call': sos_call, 'dmr_id': dmr_id, 'time': time, 'message':message} + with open("/tmp/gps_data_user_sos.txt", 'w') as sos_file: + sos_file.write(str(sos_info)) + sos_file.close() + logger.info('Saved SOS.') # Send email via SMTP function def send_email(to_email, email_subject, email_message): @@ -264,6 +276,11 @@ def process_sms(_rf_src, sms): logger.info('Failed to send email.') logger.info(error_exception) logger.info(str(traceback.extract_tb(error_exception.__traceback__))) + elif '@SOS' in sms: + sos_write(int_id(_rf_src), 'time', sms) + elif '@REM SOS' == sms: + os.remove('/tmp/gps_data_user_sos.txt') + logger.info('Removing SOS') elif '@MH' in sms: grid_square = re.sub('@MH ', '', sms) if len(grid_square) < 6: diff --git a/gps_data.py b/gps_data.py index ed0eef8..0dbef2c 100644 --- a/gps_data.py +++ b/gps_data.py @@ -177,6 +177,18 @@ def dashboard_bb_write(call, dmr_id, time, bulletin): logger.info('User bulletin entry saved.') #logger.info(dash_bb) +def sos_write(dmr_id, time, message): + user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + try: + sos_call = user_settings[dmr_id][0]['call'] + '-' + user_settings[dmr_id][1]['ssid'] + except: + sos_call = str(get_alias((dmr_id), subscriber_ids)) + sos_info = {'call': sos_call, 'dmr_id': dmr_id, 'time': time, 'message':message} + with open("/tmp/gps_data_user_sos.txt", 'w') as sos_file: + sos_file.write(str(sos_info)) + sos_file.close() + logger.info('Saved SOS.') + # Send email via SMTP function def send_email(to_email, email_subject, email_message): global smtp_server @@ -233,7 +245,7 @@ def user_setting_write(dmr_id, setting, value): def process_sms(_rf_src, sms): if sms == 'ID': - logger.info(str(get_alias(int_id(from_id), subscriber_ids)) + ' - ' + str(int_id(from_id))) + logger.info(str(get_alias(int_id(_rf_src), subscriber_ids)) + ' - ' + str(int_id(_rf_src))) elif sms == 'TEST': logger.info('It works!') elif '@ICON' in sms: @@ -257,6 +269,11 @@ def process_sms(_rf_src, sms): logger.info('Failed to send email.') logger.info(error_exception) logger.info(str(traceback.extract_tb(error_exception.__traceback__))) + elif '@SOS' in sms: + sos_write(int_id(_rf_src), 'time', sms) + elif '@REM SOS' == sms: + os.remove('/tmp/gps_data_user_sos.txt') + logger.info('Removing SOS') elif '@MH' in sms: grid_square = re.sub('@MH ', '', sms) if len(grid_square) < 6: diff --git a/scripts/dashboard/dashboard.py b/scripts/dashboard/dashboard.py index 517140b..949b44f 100644 --- a/scripts/dashboard/dashboard.py +++ b/scripts/dashboard/dashboard.py @@ -21,7 +21,7 @@ This is a web dashboard for the GPS/Data application. ''' -from flask import Flask, render_template, request, Response +from flask import Flask, render_template, request, Response, Markup import ast, os from dashboard_settings import * import folium @@ -114,6 +114,39 @@ def get_bb_data(): return str('

Bulletin Board

' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr) except: return str('

No data

') + +def check_emergency(): + # open emergency txt + try: + sos_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_sos.txt').read()) + value = Markup(""" +

EMERGENCY ACTIVATION

+

 

+ + + + + + + + + + + + + + + +
From:""" + sos_file['call'] + """ - """ + str(sos_file['dmr_id']) + """
Message:""" + sos_file['message'] + """
Time:""" + sos_file['time'] + """
+

 

+ +
+ + """) + return value + except: + return '' + def aprs_to_latlon(x): degrees = int(x) // 100 minutes = x - 100*degrees @@ -121,8 +154,9 @@ def aprs_to_latlon(x): @app.route('/') def index(): + value = Markup('The HTML String') #return get_data() - return render_template('index.html', title = dashboard_title, logo = logo) + return render_template('index.html', title = dashboard_title, logo = logo, emergency = check_emergency()) @app.route('/bulletin_board') def dash_bb(): return get_bb_data() @@ -130,10 +164,7 @@ def dash_bb(): @app.route('/positions') def dash_loc(): return get_loc_data() - #return render_template('index.html', data = str(get_data())) -##@app.route('//') -##def render_static(page_name): -## return render_template('%s.html' % page_name, title = dashboard_title, logo = logo, description = description) + @app.route('/help/') def help(): #return get_data() @@ -148,70 +179,71 @@ def view_map(): track_call = request.args.get('track') user_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) last_known_list = [] - if track_call: - #folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) - #marker_cluster = MarkerCluster().add_to(folium_map) - for user_coord in user_loc: - user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) - user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) - if 'S' in user_coord['lat']: - user_lat = -user_lat - if 'W' in user_coord['lon']: - user_lon = -user_lon - if user_coord['call'] not in last_known_list and user_coord['call'] == track_call: - folium_map = folium.Map(location=[user_lat, user_lon], tiles="Stamen Toner", zoom_start=15) - marker_cluster = MarkerCluster().add_to(folium_map) - # folium.Marker([user_lat, user_lon], popup="" + 'Last Location: \n' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + "", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) - folium.Marker([user_lat, user_lon], popup=""" - - - - - - - - - - - - -
Last Location:
"""+ str(user_coord['call']) +"""
"""+ user_coord['time'] +"""
-
- """, icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) - last_known_list.append(user_coord['call']) - if user_coord['call'] in last_known_list and user_coord['call'] == track_call: - #folium.Marker([user_lat, user_lon], popup="" + '' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + "", tooltip=str(user_coord['call'])).add_to(marker_cluster) - folium.CircleMarker([user_lat, user_lon], popup=""" - - - - - - - - - -
""" + user_coord['call'] + """
""" + user_coord['time'] + """
- """, tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) - #return folium_map._repr_html_() - if not reload_time: - reload_time = 120 - return '{} {}'.format(''' - - - """ + dashboard_title + """ - Tracking """+ track_call + """

""" + dashboard_title + """ - Tracking """ + track_call + """

-

Page automatically reloads every """ + str(reload_time) + """ seconds.

-

- -

-

""", folium_map._repr_html_()) - + try: + if track_call: + #folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) + #marker_cluster = MarkerCluster().add_to(folium_map) + for user_coord in user_loc: + user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) + user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) + if 'S' in user_coord['lat']: + user_lat = -user_lat + if 'W' in user_coord['lon']: + user_lon = -user_lon + if user_coord['call'] not in last_known_list and user_coord['call'] == track_call: + folium_map = folium.Map(location=[user_lat, user_lon], tiles="Stamen Toner", zoom_start=15) + marker_cluster = MarkerCluster().add_to(folium_map) + folium.Marker([user_lat, user_lon], popup=""" + + + + + + + + + + + + +
Last Location:
"""+ str(user_coord['call']) +"""
"""+ user_coord['time'] +"""
+
+ """, icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) + last_known_list.append(user_coord['call']) + if user_coord['call'] in last_known_list and user_coord['call'] == track_call: + folium.CircleMarker([user_lat, user_lon], popup=""" + + + + + + + + + +
""" + user_coord['call'] + """
""" + user_coord['time'] + """
+ """, tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) + #return folium_map._repr_html_() + if not reload_time: + reload_time = 120 + return '{} {}'.format(''' + + + """ + dashboard_title + """ - Tracking """+ track_call + """

""" + dashboard_title + """ - Tracking """ + track_call + """

+

Page automatically reloads every """ + str(reload_time) + """ seconds.

+

+ +

+

""", folium_map._repr_html_()) + except: + return """

Station not found.

+

""" if not track_call: folium_map = folium.Map(location=map_center, tiles="Stamen Toner", zoom_start=int(zoom_level)) marker_cluster = MarkerCluster().add_to(folium_map) @@ -223,7 +255,6 @@ def view_map(): if 'W' in user_coord['lon']: user_lon = -user_lon if user_coord['call'] not in last_known_list: - #folium.Marker([user_lat, user_lon], popup="" + 'Last Location: \n' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + '\nTrack Station""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) folium.Marker([user_lat, user_lon], popup=""" @@ -245,8 +276,6 @@ def view_map(): """, icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) last_known_list.append(user_coord['call']) if user_coord['call'] in last_known_list: - #folium.Marker([user_lat, user_lon], popup="" + '' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + "", tooltip=str(user_coord['call'])).add_to(marker_cluster) - #folium.CircleMarker([user_lat, user_lon], popup="" + '' + str(user_coord['call']) + '' + '\n' + user_coord['time'] + "", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) folium.CircleMarker([user_lat, user_lon], popup="""
diff --git a/scripts/dashboard/templates/index.html b/scripts/dashboard/templates/index.html index df45a38..bbd02d1 100644 --- a/scripts/dashboard/templates/index.html +++ b/scripts/dashboard/templates/index.html @@ -16,12 +16,23 @@ p { max-width: 1200px; min-width: 1200px; margin: auto; +} + .emergency_button { + display: block; + width: 100%; + border: none; + background-color: ##ff0000; + padding: 14px 28px; + font-size: 16px; + cursor: pointer; + text-align: center; }
{% include 'header.html' %} +{{emergency}}

Page automatically reloads every 2 minutes.

Bulletin Board RSS Feed