diff --git a/bridge_gps_data.py b/bridge_gps_data.py index bde6475..ab28376 100755 --- a/bridge_gps_data.py +++ b/bridge_gps_data.py @@ -252,7 +252,6 @@ def user_setting_write(dmr_id, setting, value): logger.info('Current settings: ' + str(user_dict)) if dmr_id not in user_dict: user_dict[dmr_id] = [{'call': str(get_alias((dmr_id), subscriber_ids))}, {'ssid': ''}, {'icon': ''}, {'comment': ''}] - if setting.upper() == 'ICON': user_dict[dmr_id][2]['icon'] = value if setting.upper() == 'SSID': @@ -261,6 +260,11 @@ def user_setting_write(dmr_id, setting, value): user_comment = user_dict[dmr_id][3]['comment'] = value[0:35] if setting.upper() == 'APRS': user_dict[dmr_id] = [{'call': str(get_alias((dmr_id), subscriber_ids))}, {'ssid': ''}, {'icon': ''}, {'comment': ''}] + if setting.upper() == 'PIN': + try: + user_dict[dmr_id][4]['pin'] = value + except: + user_dict[dmr_id].append({'pin': value}) f.close() logger.info('Loaded user settings. Preparing to write...') # Write modified dict to file @@ -270,11 +274,7 @@ def user_setting_write(dmr_id, setting, value): logger.info('User setting saved') f.close() packet_assembly = '' -## except: -## logger.info('No data file found, creating one.') -## #Path('./user_settings.txt').mkdir(parents=True, exist_ok=True) -## Path('./user_settings.txt').touch() - + # Process SMS, do something bases on message def process_sms(_rf_src, sms): @@ -288,6 +288,8 @@ def process_sms(_rf_src, sms): user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@SSID| ','',sms)) elif '@COM' in sms: user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms)) + elif '@PIN' in sms: + user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), int(re.sub('@PIN |@PIN','',sms))) # Write blank entry to cause APRS receive to look for packets for this station. elif '@APRS' in sms: user_setting_write(int_id(_rf_src), 'APRS', '') diff --git a/config.py b/config.py index 21164bc..8cf29fd 100755 --- a/config.py +++ b/config.py @@ -279,7 +279,6 @@ def build_config(_config_file): CONFIG['SYSTEMS'].update({section: { 'MODE': config.get(section, 'MODE'), 'ENABLED': config.getboolean(section, 'ENABLED'), - 'APRS': config.getboolean(section, 'APRS'), 'REPEAT': config.getboolean(section, 'REPEAT'), 'MAX_PEERS': config.getint(section, 'MAX_PEERS'), 'IP': gethostbyname(config.get(section, 'IP')), diff --git a/gps_data.py b/gps_data.py index f968962..60acfaa 100644 --- a/gps_data.py +++ b/gps_data.py @@ -152,15 +152,41 @@ def aprs_send(packet): AIS.sendall(packet) AIS.close() logger.info('Packet sent to APRS-IS.') +# For future use +##def position_timer(aprs_call): +## dash_entries = ast.literal_eval(os.popen('cat ' + loc_file).read()) +## for i in dash_entries: +## if aprs_call == i['call']: +## if time.time() + def dashboard_loc_write(call, lat, lon, time, comment): #try: dash_entries = ast.literal_eval(os.popen('cat ' + loc_file).read()) # except: # dash_entries = [] - dash_entries.insert(0, {'call': call, 'lat': lat, 'lon': lon, 'time':time, 'comment': comment}) + list_index = 0 + call_count = 0 + new_dash_entries = [] + for i in dash_entries: + if i['call'] == call: + if call_count >= 25: + print(call_count) + pass + + else: + new_dash_entries.append(i) + call_count = call_count + 1 + + if call != i['call']: + print('Record call: |' + i['call'] + '|') + print('Filter Call: |' + call + '|') + new_dash_entries.append(i) + + pass + list_index = list_index + 1 with open(loc_file, 'w') as user_loc_file: - user_loc_file.write(str(dash_entries[:200])) + user_loc_file.write(str(new_dash_entries[:500])) user_loc_file.close() logger.info('User location saved for dashboard') #logger.info(dash_entries) @@ -245,7 +271,6 @@ def user_setting_write(dmr_id, setting, value): logger.info('Current settings: ' + str(user_dict)) if dmr_id not in user_dict: user_dict[dmr_id] = [{'call': str(get_alias((dmr_id), subscriber_ids))}, {'ssid': ''}, {'icon': ''}, {'comment': ''}] - if setting.upper() == 'ICON': user_dict[dmr_id][2]['icon'] = value if setting.upper() == 'SSID': @@ -254,6 +279,11 @@ def user_setting_write(dmr_id, setting, value): user_comment = user_dict[dmr_id][3]['comment'] = value[0:35] if setting.upper() == 'APRS': user_dict[dmr_id] = [{'call': str(get_alias((dmr_id), subscriber_ids))}, {'ssid': ''}, {'icon': ''}, {'comment': ''}] + if setting.upper() == 'PIN': + try: + user_dict[dmr_id][4]['pin'] = value + except: + user_dict[dmr_id].append({'pin': value}) f.close() logger.info('Loaded user settings. Preparing to write...') # Write modified dict to file @@ -263,11 +293,7 @@ def user_setting_write(dmr_id, setting, value): logger.info('User setting saved') f.close() packet_assembly = '' -## except: -## logger.info('No data file found, creating one.') -## #Path('./user_settings.txt').mkdir(parents=True, exist_ok=True) -## Path('./user_settings.txt').touch() - + # Process SMS, do something bases on message def process_sms(_rf_src, sms): @@ -281,6 +307,8 @@ def process_sms(_rf_src, sms): user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@SSID| ','',sms)) elif '@COM' in sms: user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms)) + elif '@PIN' in sms: + user_setting_write(int_id(_rf_src), re.sub(' .*|@','',sms), int(re.sub('@PIN |@PIN','',sms))) # Write blank entry to cause APRS receive to look for packets for this station. elif '@APRS' in sms: user_setting_write(int_id(_rf_src), 'APRS', '') diff --git a/scripts/dashboard/dashboard.py b/scripts/dashboard/dashboard.py index e3fd1c5..7fbdafd 100644 --- a/scripts/dashboard/dashboard.py +++ b/scripts/dashboard/dashboard.py @@ -60,7 +60,7 @@ def get_loc_data():

 Longitude 

-

 Local Time 

+

 Time 

''' @@ -101,13 +101,13 @@ def get_bb_data():

 Callsign 

-

 DMR ID 

+

 ID 

 Bulletin 

-

 Local Time 

+

 Time 

''' @@ -178,6 +178,22 @@ def aprs_to_latlon(x): minutes = x - 100*degrees return degrees + minutes/60 +def user_setting_write(dmr_id, input_ssid, input_icon, input_comment): + dmr_id = int(dmr_id) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) + new_dict = user_settings + new_dict[dmr_id][1]['ssid'] = input_ssid + new_dict[dmr_id][2]['icon'] = input_icon + new_dict[dmr_id][3]['comment'] = input_comment + print(input_comment) + print(new_dict[dmr_id]) + + # Write modified dict to file + with open(user_settings_file, 'w') as user_dict_file: + user_dict_file.write(str(new_dict)) + user_dict_file.close() + + @app.route('/') def index(): value = Markup('The HTML String') @@ -206,6 +222,7 @@ def view_map(): map_size = request.args.get('map_size') user_loc = ast.literal_eval(os.popen('cat ' + loc_file).read()) last_known_list = [] + coord_list = [] try: if track_call: #folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) @@ -320,6 +337,7 @@ def view_map(): if 'W' in user_coord['lon']: user_lon = -user_lon loc_comment = '' + coord_list.append([user_lat, user_lon]) if 'comment' in user_coord: loc_comment = """ @@ -351,18 +369,21 @@ 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.CircleMarker([user_lat, user_lon], popup=""" - - - - - - - - - -
""" + user_coord['call'] + """
""" + loc_time + """
- """, tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) + if coord_list.count([user_lat, user_lon]) > 15: + pass + else: + folium.CircleMarker([user_lat, user_lon], popup=""" + + + + + + + + + +
""" + user_coord['call'] + """
""" + loc_time + """
+ """, tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) return folium_map._repr_html_() @@ -370,37 +391,136 @@ def view_map(): def map(): return render_template('map.html', title = dashboard_title, logo = logo) -@app.route('/user') +@app.route('/user', methods = ['GET', 'POST']) def user_settings(): + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) user_id = request.args.get('user_id') - if not user_id: - user_result = """ - Use this tool to find and check the stored APRS settings for your DMR ID. When a position is sent, the stored settings will be used to format the APRS packet. -
- + if request.method == 'POST' and request.form.get('dmr_id'): + if int(request.form.get('dmr_id')) in user_settings: + user_id = request.form.get('dmr_id') + ssid = user_settings[int(request.form.get('dmr_id'))][1]['ssid'] + icon = user_settings[int(request.form.get('dmr_id'))][2]['icon'] + comment = user_settings[int(request.form.get('dmr_id'))][3]['comment'] + try: + pin = user_settings[int(request.form.get('dmr_id'))][4]['pin'] + if ssid == '': + ssid = aprs_ssid + if icon == '': + icon = '\[' + if comment == '': + comment = default_comment + ' ' + user_id + user_result = """ + Use this tool to change the stored APRS settings for your DMR ID. When a position is sent, the stored settings will be used to format the APRS packet. Leave field(s) blank for default value. +

 Modify Settings for ID: """ + user_id + """

+ +
- - + + + - - + + + - - + + + + + + + + + + + + + + +
-

-
Callsign:""" + str(user_settings[int(user_id)][0]['call']) + """
SSID:
Icon:
Comment:
DMR ID:
PIN:
+

+

 

+ + + """ + except: + user_result = """

No PIN set for """ + str(user_settings[int(user_id)][0]['call']) + """ - """ + request.form.get('dmr_id') + """

+

+

""" + if int(request.form.get('dmr_id')) not in user_settings: + user_result = """

DMR ID not found.

+

+

""" + #if edit_user: + + if request.method == 'POST' and request.form.get('dmr_id') and request.form.get('pin'): + if int(request.form.get('pin')) == pin: + ssid = request.form.get('ssid') + icon = request.form.get('icon') + comment = request.form.get('comment') + user_setting_write(request.form.get('dmr_id'), request.form.get('ssid'), request.form.get('icon'), request.form.get('comment')) + user_result = """

Changed settings for """ + str(user_settings[int(user_id)][0]['call']) + """ - """ + request.form.get('dmr_id') + """

+

+

""" + if int(request.form.get('pin')) != pin: + user_result = """

Incorrect PIN.

+

+

""" + + if request.method == 'GET' and not request.args.get('user_id'): + user_result = """ + Use this tool to find, check, and change the stored APRS settings for your DMR ID. When a position is sent, the stored settings will be used to format the APRS packet. + + + + + + + +
+ + + + + + + + + + + + +
+

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

+
+

 

""" - else: + #else: + if request.method == 'GET' and request.args.get('user_id'): try: - #return render_template('map.html', title = dashboard_title, logo = logo) - user_settings = ast.literal_eval(os.popen('cat ../../user_settings.txt').read()) call = user_settings[int(user_id)][0]['call'] ssid = user_settings[int(user_id)][1]['ssid'] icon = user_settings[int(user_id)][2]['icon'] @@ -452,7 +572,7 @@ def mailbox(): if not recipient: mail_content = """

The Mailbox is a place where users can leave messages via DMR SMS. A user can leave a message for someone else by sending a specially formatted SMS to """ + data_call_id + """. - The message recipient can then use the mailbox to check for messages. You can also check for APRS mesages addressed to your DMR radio. Enter your call sign below to check for messages. See the help page for more information.

+ The message recipient can then use the mailbox to check for messages. You can also check for APRS mesages addressed to your DMR radio. Enter your call sign (without APRS SSID) below to check for messages. See the help page for more information.

@@ -544,7 +664,8 @@ def bb_rss(): """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """""" + rss_link + """""" + entry['bulletin'] + """ - """ + loc_time + """ - + """ + datetime.fromtimestamp(entry['time']).strftime('%a, %d %b %y') +""" + """ return Response(rss_header + post_data + "\n\n", mimetype='text/xml') except Exception as e: @@ -573,6 +694,7 @@ def mail_rss(): """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """""" + rss_link + """""" + entry['message'] + """ - """ + loc_time + """ + """ + datetime.fromtimestamp(entry['time']).strftime('%a, %d %b %y') +""" """ return Response(rss_header + post_data + "\n\n", mimetype='text/xml') @@ -636,6 +758,7 @@ if __name__ == '__main__': loc_file = parser.get('GPS_DATA', 'LOCATION_FILE') emergency_sos_file = parser.get('GPS_DATA', 'EMERGENCY_SOS_FILE') the_mailbox_file = parser.get('GPS_DATA', 'MAILBOX_FILE') + user_settings_file = parser.get('GPS_DATA', 'USER_SETTINGS_FILE') ######################## app.run(debug = True, port=dash_port, host=dash_host) diff --git a/scripts/dashboard/templates/help.html b/scripts/dashboard/templates/help.html index e6ffbc2..6afeae7 100644 --- a/scripts/dashboard/templates/help.html +++ b/scripts/dashboard/templates/help.html @@ -51,6 +51,11 @@ + + + + +
@SSID 7
@PINSet a PIN. This is used for changing your APRS settings ia the dashboard. You must set this for each DMR ID you wish to change via the dashboard.@PIN 1234
@MH Set you location by maidenhead grid square. Designed for radios with no GPS or that are not compatable yet. @MH DN97uk