add emergency feature

This commit is contained in:
KF7EEL 2021-02-28 13:49:22 -08:00
parent 90982b88de
commit a8714c9a7d
4 changed files with 148 additions and 74 deletions

View File

@ -184,6 +184,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
@ -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:

View File

@ -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:

View File

@ -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('<h1 style="text-align: center;">Bulletin Board</h1>' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr)
except:
return str('<h1 style="text-align: center;">No data</h1>')
def check_emergency():
# open emergency txt
try:
sos_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_sos.txt').read())
value = Markup("""
<h1 style="text-align: center;"><span style="background-color: #ff0000; color: #ffffff;">EMERGENCY ACTIVATION</span></h1>
<p>&nbsp;</p>
<table style="width: 441px; margin-left: auto; margin-right: auto;" border="3">
<tbody>
<tr>
<td style="width: 78.3667px;"><span style="text-decoration: underline;"><strong>From:</strong></span></td>
<td style="width: 345.633px; text-align: center;"><strong>""" + sos_file['call'] + """ - """ + str(sos_file['dmr_id']) + """</strong></td>
</tr>
<tr>
<td style="width: 78.3667px;"><span style="text-decoration: underline;"><strong>Message:</strong></span></td>
<td style="width: 345.633px; text-align: center;"><strong>""" + sos_file['message'] + """</strong></td>
</tr>
<tr>
<td style="width: 78.3667px;"><span style="text-decoration: underline;"><strong>Time:</strong></span></td>
<td style="width: 345.633px; text-align: center;"><strong>""" + sos_file['time'] + """</strong></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<button onclick="window.open('view_map?track=""" + sos_file['call'] + """&reload=30','_blank' );" type="button" class="emergency_button"><h1>View Station on Map</h1></button>
<hr />
""")
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('<strong>The HTML String</strong>')
#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('/<string:page_name>/')
##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="<i>" + '<strong>Last Location: \n' + str(user_coord['call']) + '</strong>' + '\n' + user_coord['time'] + "</i>", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map)
folium.Marker([user_lat, user_lon], popup="""<i>
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;">Last Location:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['call']) +"""</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>"""+ user_coord['time'] +"""</em></td>
</tr>
</tbody>
</table>
</i>
""", 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="<i>" + '<strong>' + str(user_coord['call']) + '</strong>' + '\n' + user_coord['time'] + "</i>", tooltip=str(user_coord['call'])).add_to(marker_cluster)
folium.CircleMarker([user_lat, user_lon], popup="""
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;"><strong>""" + user_coord['call'] + """</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>""" + user_coord['time'] + """</em></td>
</tr>
</tbody>
</table>
""", 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('''<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="''' + str(reload_time) + """" >
<title>""" + dashboard_title + """ - Tracking """+ track_call + """</title></head><p style="text-align: center;"><strong>""" + dashboard_title + """ - Tracking """ + track_call + """</strong></p>
<p style="text-align: center;"><em>Page automatically reloads every """ + str(reload_time) + """ seconds.</em></p>
<p style="text-align: center;">
<select name="sample" onchange="location = this.value;">
<option value="view_map?track=""" + track_call + """&reload=120">2 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=">Don't Reload</option>
<option value="view_map?track=""" + track_call + """&reload=30">30 Seconds</option>
<option value="view_map?track=""" + track_call + """&reload=5">5 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=600">10 Minutes</option>
</select>
<p style="text-align: center;"><button onclick="self.close()">Close</button>
</p>""", 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="""<i>
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;">Last Location:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['call']) +"""</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>"""+ user_coord['time'] +"""</em></td>
</tr>
</tbody>
</table>
</i>
""", 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="""
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;"><strong>""" + user_coord['call'] + """</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>""" + user_coord['time'] + """</em></td>
</tr>
</tbody>
</table>
""", 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('''<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="''' + str(reload_time) + """" >
<title>""" + dashboard_title + """ - Tracking """+ track_call + """</title></head><p style="text-align: center;"><strong>""" + dashboard_title + """ - Tracking """ + track_call + """</strong></p>
<p style="text-align: center;"><em>Page automatically reloads every """ + str(reload_time) + """ seconds.</em></p>
<p style="text-align: center;">
<select name="sample" onchange="location = this.value;">
<option value="view_map?track=""" + track_call + """&reload=120">2 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=">Don't Reload</option>
<option value="view_map?track=""" + track_call + """&reload=30">30 Seconds</option>
<option value="view_map?track=""" + track_call + """&reload=5">5 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=600">10 Minutes</option>
</select>
<p style="text-align: center;"><button onclick="self.close()">Close</button>
</p>""", folium_map._repr_html_())
except:
return """<h1 style="text-align: center;">Station not found.</h1>
<p style="text-align: center;"><button onclick="self.close()">Close Window</button></p>"""
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="<i>" + '<strong>Last Location: \n' + str(user_coord['call']) + '</strong>' + '\n' + user_coord['time'] + '\n<A href="view_map?track=' + user_coord['call'] + """" target="_blank">Track Station</A></i>""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map)
folium.Marker([user_lat, user_lon], popup="""<i>
<table style="width: 150px;">
<tbody>
@ -245,8 +276,6 @@ def view_map():
</i>""", 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="<i>" + '<strong>' + str(user_coord['call']) + '</strong>' + '\n' + user_coord['time'] + "</i>", tooltip=str(user_coord['call'])).add_to(marker_cluster)
#folium.CircleMarker([user_lat, user_lon], popup="<i>" + '<strong>' + str(user_coord['call']) + '</strong>' + '\n' + user_coord['time'] + "</i>", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster)
folium.CircleMarker([user_lat, user_lon], popup="""
<table style="width: 150px;">
<tbody>

View File

@ -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;
}
</style>
</head>
<div class="content">
<body>
{% include 'header.html' %}
{{emergency}}
<p style="text-align: center;"><em>Page automatically reloads every 2 minutes.</em></p>
<h4 style="text-align: center;"><a href="bulletin_rss.xml"><em>Bulletin Board RSS Feed</em></a><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5QIcFBAOXAevLAAAAZZJREFUSMftlbtKA0EUhj8jWhi8gaIEC29oxEoRFESLgIXYiWVSKoj6CCrBBwj6CBHNE1hEWy21ETQqiIW1wXhPo81ZOBw2apbdVPvDsDPnP8M/5zKzECJEQKivYO8DFoAYEAGKtTpQEvhW4w3IA+tAVy2F9fgEskA8COHUL8LOKAMZoMmLQF0FewcwImmNAzPANBB18b0BFoGroNLfBiyLgI2+BMwF3XgNwCrwYsQ//BBPSRPdAoeybjE+A8ClS+Sjfnf1E5A2dW4FzoxfwWvD/XWd7oAxI24jz3gVnpS7eiEpt+KvQEL5D5qal/245zFgU+pnXzMd+Zrh9/3q5l7g3CXtTs0bgWvFffn5vDa7iKcVv2K4DS8i3cAOsAuMm8h12ovqqrVL/R3upFrRKPBgHgctvm0iSynuWNnf5bf6byy5dPKe4nukhg6XU9yW2TfsJlDpNCUX27OaP8pD4WBCzQtmX381EUeAI3Xqe6m5xoHpYAezJuJkNb9Fh0tI4+SlXhpTwJBaZ+XbCcwr+6kcPESI2uAHmAijFaMnEmYAAAAASUVORK5CYII=" /></h4>
<table>