diff --git a/bridge_gps_data.py b/bridge_gps_data.py index 92e5a4d..7327941 100755 --- a/bridge_gps_data.py +++ b/bridge_gps_data.py @@ -289,7 +289,7 @@ def process_sms(_rf_src, sms): elif '@COM' in sms: user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms)) elif '@BB' in sms: - dashboard_bb_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), strftime('%H:%M:%S - %m/%d/%y'), re.sub('@BB|@BB ','',sms)) + dashboard_bb_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.time(), re.sub('@BB|@BB ','',sms)) elif '@' and ' E-' in sms: email_message = str(re.sub('.*@|.* E-', '', sms)) to_email = str(re.sub(' E-.*', '', sms)) @@ -304,14 +304,14 @@ def process_sms(_rf_src, sms): logger.info(error_exception) logger.info(str(traceback.extract_tb(error_exception.__traceback__))) elif '@SOS' in sms or '@NOTICE' in sms: - sos_write(int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), sms) + sos_write(int_id(_rf_src), time.time(), sms) elif '@REM SOS' == sms: os.remove('/tmp/gps_data_user_sos.txt') logger.info('Removing SOS') elif '@' and 'M-' in sms: message = re.sub('^@|.* M-|','',sms) recipient = re.sub('@| M-.*','',sms) - mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), message, str(recipient).upper()) + mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.time(), message, str(recipient).upper()) elif '@REM MAIL' == sms: mailbox_delete(_rf_src) elif '@MH' in sms: @@ -366,7 +366,7 @@ def process_sms(_rf_src, sms): try: aprslib.parse(aprs_loc_packet) aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) #logger.info('Sent manual position to APRS') except Exception as error_exception: logger.info('Exception. Not uploaded') @@ -1550,7 +1550,7 @@ class routerHBP(HBSYSTEM): float(lat_deg) < 91 float(lon_deg) < 121 aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) #logger.info('Sent APRS packet') except Exception as error_exception: logger.info('Error. Failed to send packet. Packet may be malformed.') @@ -1652,7 +1652,7 @@ class routerHBP(HBSYSTEM): float(loc.lat) float(loc.lon) aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time.time()) except Exception as error_exception: logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.') logger.info(error_exception) diff --git a/gps_data.py b/gps_data.py index 81e0883..cdac809 100644 --- a/gps_data.py +++ b/gps_data.py @@ -280,7 +280,7 @@ def process_sms(_rf_src, sms): elif '@COM' in sms: user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms)) elif '@BB' in sms: - dashboard_bb_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), re.sub('@BB|@BB ','',sms)) + dashboard_bb_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.time(), re.sub('@BB|@BB ','',sms)) elif '@' and ' E-' in sms: email_message = str(re.sub('.*@|.* E-', '', sms)) to_email = str(re.sub(' E-.*', '', sms)) @@ -295,14 +295,14 @@ def process_sms(_rf_src, sms): logger.info(error_exception) logger.info(str(traceback.extract_tb(error_exception.__traceback__))) elif '@SOS' in sms or '@NOTICE' in sms: - sos_write(int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), sms) + sos_write(int_id(_rf_src), time.time(), sms) elif '@REM SOS' == sms: os.remove('/tmp/gps_data_user_sos.txt') logger.info('Removing SOS or Notice') elif '@' and 'M-' in sms: message = re.sub('^@|.* M-|','',sms) recipient = re.sub('@| M-.*','',sms) - mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), message, str(recipient).upper()) + mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.time(), message, str(recipient).upper()) elif '@REM MAIL' == sms: mailbox_delete(_rf_src) elif '@MH' in sms: @@ -357,7 +357,7 @@ def process_sms(_rf_src, sms): try: aprslib.parse(aprs_loc_packet) aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) #logger.info('Sent manual position to APRS') except Exception as error_exception: logger.info('Exception. Not uploaded') @@ -496,7 +496,7 @@ class DATA_SYSTEM(HBSYSTEM): float(lat_deg) < 91 float(lon_deg) < 121 aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) #logger.info('Sent APRS packet') except Exception as error_exception: logger.info('Error. Failed to send packet. Packet may be malformed.') @@ -598,7 +598,7 @@ class DATA_SYSTEM(HBSYSTEM): float(loc.lat) float(loc.lon) aprs_send(aprs_loc_packet) - dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time.strftime('%H:%M:%S - %m/%d/%y')) + dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time.time()) except Exception as error_exception: logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.') logger.info(error_exception) diff --git a/scripts/dashboard/dashboard.py b/scripts/dashboard/dashboard.py index 285cc14..384f654 100644 --- a/scripts/dashboard/dashboard.py +++ b/scripts/dashboard/dashboard.py @@ -27,6 +27,7 @@ from dashboard_settings import * import folium from folium.plugins import MarkerCluster import re +from datetime import datetime app = Flask(__name__) @@ -68,17 +69,21 @@ def get_loc_data(): if e['call'] in last_known_loc_list: pass if e['call'] not in last_known_loc_list: + if type(e['time']) == str: + loc_time = str(e['time']) + if type(e['time']) == int or type(e['time']) == float: + loc_time = datetime.fromtimestamp(e['time']).strftime(time_format) last_known_loc_list.append(e['call']) display_number = display_number - 1 tmp_loc = tmp_loc + ''' ''' + e['call'] + '''  ''' + str(e['lat']) + '''   ''' + str(e['lon']) + '''  -  ''' + e['time'] + '''  +  ''' + loc_time + '''  ''' return str(str('

Last Known Location

') + tbl_hdr + loc_hdr + tmp_loc + tbl_ftr) except: - return str('

No data

') + return str('

No data

') def get_bb_data(): @@ -108,12 +113,16 @@ def get_bb_data(): if display_number == 0: break else: + if type(e['time']) == str: + loc_time = str(e['time']) + if type(e['time']) == int or type(e['time']) == float: + loc_time = datetime.fromtimestamp(e['time']).strftime(time_format) display_number = display_number - 1 tmp_bb = tmp_bb + '''  ''' + e['call'] + '''  ''' + str(e['dmr_id']) + '''  ''' + e['bulletin'] + '''  -  ''' + e['time'] + '''  +  ''' + loc_time + '''  ''' return str('

Bulletin Board

' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr) @@ -127,6 +136,10 @@ def check_emergency(): if '@NOTICE' in sos_file['message'] and '@SOS' not in sos_file['message']: notice_header = 'NOTICE:' else: + if type(sos_file['time']) == str: + loc_time = str(sos_file['time']) + if type(sos_file['time']) == int or type(sos_file['time']) == float: + loc_time = datetime.fromtimestamp(sos_file['time']).strftime(time_format) notice_header = 'EMERGENCY ACTIVATION' value = Markup("""

""" + notice_header + """

@@ -142,7 +155,7 @@ def check_emergency(): Time: - """ + sos_file['time'] + """ + """ + loc_time + """ @@ -196,6 +209,10 @@ def view_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 type(user_coord['time']) == str: + loc_time = str(user_coord['time']) + if type(user_coord['time']) == int or type(user_coord['time']) == float: + loc_time = datetime.fromtimestamp(user_coord['time']).strftime(time_format) if 'S' in user_coord['lat']: user_lat = -user_lat if 'W' in user_coord['lon']: @@ -213,7 +230,7 @@ def view_map(): """+ str(user_coord['call']) +""" - """+ user_coord['time'] +""" + """+ loc_time +""" @@ -228,7 +245,7 @@ def view_map(): """ + user_coord['call'] + """ - """ + user_coord['time'] + """ + """ + loc_time + """ @@ -264,7 +281,7 @@ def view_map(): -

+

""" + map_view return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(content)) @@ -280,6 +297,10 @@ def view_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 type(user_coord['time']) == str: + loc_time = str(user_coord['time']) + if type(user_coord['time']) == int or type(user_coord['time']) == float: + loc_time = datetime.fromtimestamp(user_coord['time']).strftime(time_format) if 'S' in user_coord['lat']: user_lat = -user_lat if 'W' in user_coord['lon']: @@ -295,7 +316,7 @@ def view_map(): """ + user_coord['call'] + """ - """ + user_coord['time'] + """ + """ + loc_time + """ Track Station @@ -313,7 +334,7 @@ def view_map(): """ + user_coord['call'] + """ - """ + user_coord['time'] + """ + """ + loc_time + """ @@ -348,6 +369,8 @@ def user_settings(): +

 

+ """ else: @@ -435,11 +458,15 @@ def mailbox(): ''' for messages in mailbox_file: if messages['recipient'] == recipient.upper(): + if type(messages['time']) == str: + loc_time = str(messages['time']) + if type(messages['time']) == int or type(messages['time']) == float: + loc_time = datetime.fromtimestamp(messages['time']).strftime(time_format) mail_content = mail_content + """ - + @@ -448,7 +475,7 @@ def mailbox(): - + @@ -473,11 +500,15 @@ def bb_rss(): """ + rss_link + """This is the Bulletin Board feed from """ + dashboard_title + """""" for entry in dash_bb: + if type(entry['time']) == str: + loc_time = str(entry['time']) + if type(entry['time']) == int or type(entry['time']) == float: + loc_time = datetime.fromtimestamp(entry['time']).strftime(time_format) post_data = post_data + """ """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """ """ + rss_link + """ - """ + entry['bulletin'] + """ - """ + entry['time'] + """ + """ + entry['bulletin'] + """ - """ + loc_time + """ """ return Response(rss_header + post_data + "\n\n", mimetype='text/xml') @@ -496,12 +527,16 @@ def mail_rss(): """ + rss_link + """This is a Mailbox feed from """ + dashboard_title + """ for """ + recipient + """.""" for entry in mailbox_file: + if type(entry['time']) == str: + loc_time = str(entry['time']) + if type(entry['time']) == int or type(entry['time']) == float: + loc_time = datetime.fromtimestamp(entry['time']).strftime(time_format) if entry['recipient'] == recipient: post_data = post_data + """ """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """ """ + rss_link + """ - """ + entry['message'] + """ - """ + entry['time'] + """ + """ + entry['message'] + """ - """ + loc_time + """ """ return Response(rss_header + post_data + "\n\n", mimetype='text/xml') diff --git a/scripts/dashboard/dashboard_settings-SAMPLE.py b/scripts/dashboard/dashboard_settings-SAMPLE.py index 9b8811e..4560859 100644 --- a/scripts/dashboard/dashboard_settings-SAMPLE.py +++ b/scripts/dashboard/dashboard_settings-SAMPLE.py @@ -48,6 +48,9 @@ contact_call = 'N0CALL' contact_email = 'email@example.org' contact_website = 'https://hbl.ink' +# Time format for display +time_format = '%H:%M:%S - %m/%d/%y' + # Center dashboard map over these coordinates map_center = (47.00, -120.00) zoom_level = 7 diff --git a/scripts/dashboard/templates/footer.html b/scripts/dashboard/templates/footer.html index bbcbee1..722c511 100644 --- a/scripts/dashboard/templates/footer.html +++ b/scripts/dashboard/templates/footer.html @@ -1,5 +1,5 @@

-
Dashboard created by KF7EEL - https://github.com/kf7eel/hblink3
HBLink created by N0MJS.
HBLink GitHub page
This is branch: gps
+
Dashboard created by KF7EEL - https://github.com/kf7eel/hblink3
HBLink created by N0MJS.
HBLink GitHub page
This is branch: gps
Callsign:From: """ + messages['call'] + """
Time:""" + messages['time'] + """""" + loc_time + """
Message: