diff --git a/bridge_gps_data-SAMPLE.cfg b/bridge_gps_data-SAMPLE.cfg index 41959bf..77ce9df 100644 --- a/bridge_gps_data-SAMPLE.cfg +++ b/bridge_gps_data-SAMPLE.cfg @@ -148,6 +148,9 @@ IGATE_BEACON_ICON = /I IGATE_LATITUDE = 0000.00N IGATE_LONGITUDE = 00000.00W +# User settings file, MUST configure using absolute path. +USER_SETTINGS_FILE: /path/to/user_settings.txt + # The APRS filter below is used for the message received script. See http://www.aprs-is.net/javAPRSFilter.aspx for details # about APRS filters. APRS_RECEIVE_LOGIN_CALL: N0CALL-1 diff --git a/bridge_gps_data.py b/bridge_gps_data.py index d2e63a7..27ef5c0 100644 --- a/bridge_gps_data.py +++ b/bridge_gps_data.py @@ -207,7 +207,7 @@ def mailbox_delete(dmr_id): def sos_write(dmr_id, time, message): - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) try: if user_settings[dmr_id][1]['ssid'] == '': sos_call = user_settings[dmr_id][0]['call'] + '-' + user_ssid @@ -245,7 +245,7 @@ def decdeg2dms(dd): def user_setting_write(dmr_id, setting, value): ## try: # Open file and load as dict for modification - with open("./user_settings.txt", 'r') as f: + with open(user_settings_file, 'r') as f: ## if f.read() == '{}': ## user_dict = {} user_dict = ast.literal_eval(f.read()) @@ -264,7 +264,7 @@ def user_setting_write(dmr_id, setting, value): f.close() logger.info('Loaded user settings. Preparing to write...') # Write modified dict to file - with open("./user_settings.txt", 'w') as user_dict_file: + with open(user_settings_file, 'w') as user_dict_file: user_dict_file.write(str(user_dict)) user_dict_file.close() logger.info('User setting saved') @@ -340,7 +340,7 @@ def process_sms(_rf_src, sms): logger.info('Latitude: ' + str(aprs_lat)) logger.info('Longitude: ' + str(aprs_lon)) # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -383,7 +383,7 @@ def process_sms(_rf_src, sms): aprs_dest = re.sub('@| A-.*','',sms) aprs_msg = re.sub('^@|.* A-|','',sms) logger.info('APRS message to ' + aprs_dest.upper() + '. Message: ' + aprs_msg) - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) in user_settings and user_settings[int_id(_rf_src)][1]['ssid'] != '': ssid = user_settings[int_id(_rf_src)][1]['ssid'] else: @@ -1521,7 +1521,7 @@ class routerHBP(HBSYSTEM): #logger.info(aprs_loc_packet) logger.info('Lat: ' + str(aprs_lat) + ' Lon: ' + str(aprs_lon)) # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -1617,7 +1617,7 @@ class routerHBP(HBSYSTEM): # Begin APRS format and upload # Disable opening file for reading to reduce "collision" or reading and writing at same time. # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -1811,11 +1811,11 @@ if __name__ == '__main__': emergency_sos_file = CONFIG['GPS_DATA']['EMERGENCY_SOS_FILE'] # Check if user_settings (for APRS settings of users) exists. Creat it if not. - if Path('./user_settings.txt').is_file(): + if Path(user_settings_file).is_file(): pass else: - Path('./user_settings.txt').touch() - with open("./user_settings.txt", 'w') as user_dict_file: + Path(user_settings_file).touch() + with open(user_settings_file, 'w') as user_dict_file: user_dict_file.write("{1: [{'call': 'N0CALL'}, {'ssid': ''}, {'icon': ''}, {'comment': ''}]}") user_dict_file.close() # Check to see if dashboard files exist diff --git a/config.py b/config.py index eea47cf..bddfd80 100644 --- a/config.py +++ b/config.py @@ -166,6 +166,7 @@ def build_config(_config_file): 'BULLETIN_BOARD_FILE': config.get(section, 'BULLETIN_BOARD_FILE'), 'MAILBOX_FILE': config.get(section, 'MAILBOX_FILE'), 'EMERGENCY_SOS_FILE': config.get(section, 'EMERGENCY_SOS_FILE'), + 'USER_SETTINGS_FILE': config.get(section, 'USER_SETTINGS_FILE'), }) if not CONFIG['LOGGER']['LOG_FILE']: diff --git a/gps_data-SAMPLE.cfg b/gps_data-SAMPLE.cfg index 046248e..bffcd22 100644 --- a/gps_data-SAMPLE.cfg +++ b/gps_data-SAMPLE.cfg @@ -141,12 +141,8 @@ IGATE_BEACON_ICON = /I IGATE_LATITUDE = 0000.00N IGATE_LONGITUDE = 00000.00W -# The options below are required for operation of the dashboard. Leave them as default -# unless you know what you are doing. -LOCATION_FILE: /tmp/gps_data_user_loc.txt -BULLETIN_BOARD_FILE: /tmp/gps_data_user_bb.txt -MAILBOX_FILE: /tmp/gps_data_user_mailbox.txt -EMERGENCY_SOS_FILE: /tmp/gps_data_user_sos.txt +# User settings file, MUST configure using absolute path. +USER_SETTINGS_FILE: /path/to/user_settings.txt # The email gateway settingns below are OPTIONAL. They are NOT REQUIRED if you don't want http://www.aprs-is.net/javAPRSFilter.aspx# to enable the email gateway. Leave as is to disable. diff --git a/gps_data.py b/gps_data.py index 2cb73bf..f968962 100644 --- a/gps_data.py +++ b/gps_data.py @@ -200,7 +200,7 @@ def mailbox_delete(dmr_id): def sos_write(dmr_id, time, message): - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) try: if user_settings[dmr_id][1]['ssid'] == '': sos_call = user_settings[dmr_id][0]['call'] + '-' + user_ssid @@ -238,7 +238,7 @@ def decdeg2dms(dd): def user_setting_write(dmr_id, setting, value): ## try: # Open file and load as dict for modification - with open("./user_settings.txt", 'r') as f: + with open(user_settings_file, 'r') as f: ## if f.read() == '{}': ## user_dict = {} user_dict = ast.literal_eval(f.read()) @@ -257,7 +257,7 @@ def user_setting_write(dmr_id, setting, value): f.close() logger.info('Loaded user settings. Preparing to write...') # Write modified dict to file - with open("./user_settings.txt", 'w') as user_dict_file: + with open(user_settings_file, 'w') as user_dict_file: user_dict_file.write(str(user_dict)) user_dict_file.close() logger.info('User setting saved') @@ -333,7 +333,7 @@ def process_sms(_rf_src, sms): logger.info('Latitude: ' + str(aprs_lat)) logger.info('Longitude: ' + str(aprs_lon)) # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -376,7 +376,7 @@ def process_sms(_rf_src, sms): aprs_dest = re.sub('@| A-.*','',sms) aprs_msg = re.sub('^@|.* A-|','',sms) logger.info('APRS message to ' + aprs_dest.upper() + '. Message: ' + aprs_msg) - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) in user_settings and user_settings[int_id(_rf_src)][1]['ssid'] != '': ssid = user_settings[int_id(_rf_src)][1]['ssid'] else: @@ -469,7 +469,7 @@ class DATA_SYSTEM(HBSYSTEM): #logger.info(aprs_loc_packet) logger.info('Lat: ' + str(aprs_lat) + ' Lon: ' + str(aprs_lon)) # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -565,7 +565,7 @@ class DATA_SYSTEM(HBSYSTEM): # Begin APRS format and upload # Disable opening file for reading to reduce "collision" or reading and writing at same time. # 14FRS2013 simplified and moved settings retrieval - user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if int_id(_rf_src) not in user_settings: ssid = str(user_ssid) icon_table = '/' @@ -713,12 +713,15 @@ if __name__ == '__main__': the_mailbox_file = CONFIG['GPS_DATA']['MAILBOX_FILE'] emergency_sos_file = CONFIG['GPS_DATA']['EMERGENCY_SOS_FILE'] + # User APRS settings + user_settings_file = CONFIG['GPS_DATA']['USER_SETTINGS_FILE'] + # Check if user_settings (for APRS settings of users) exists. Creat it if not. - if Path('./user_settings.txt').is_file(): + if Path(user_settings_file).is_file(): pass else: - Path('./user_settings.txt').touch() - with open("./user_settings.txt", 'w') as user_dict_file: + Path(user_settings_file).touch() + with open(user_settings_file, 'w') as user_dict_file: user_dict_file.write("{1: [{'call': 'N0CALL'}, {'ssid': ''}, {'icon': ''}, {'comment': ''}]}") user_dict_file.close() # Check to see if dashboard files exist diff --git a/scripts/aprs_receive/receive.py b/scripts/aprs_receive/receive.py index 991d0da..76f28ef 100644 --- a/scripts/aprs_receive/receive.py +++ b/scripts/aprs_receive/receive.py @@ -24,30 +24,27 @@ import time import argparse def mailbox_write(call, dmr_id, time, message, recipient): + global mailbox_file mail_file = ast.literal_eval(os.popen('cat ' + mailbox_file).read()) mail_file.insert(0, {'call': call, 'dmr_id': dmr_id, 'time': time, 'message':message, 'recipient': recipient}) - with open("../../gps_data_user_mailbox.txt", 'w') as mailbox_file: + with open(mailbox_file, 'w') as mailbox_file: mailbox_file.write(str(mail_file[:100])) mailbox_file.close() print('User mail saved.') def aprs_filter(packet): - #if aprslib.parse(packet) in aprslib.parse(packet): - # print(aprslib.parse(packet)) - #else: - # pass - user_settings = ast.literal_eval(os.popen('cat ../../user_settings.txt').read()) + + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) if 'addresse' in aprslib.parse(packet): #print(aprslib.parse(packet)) recipient = re.sub('-.*','', aprslib.parse(packet)['addresse']) recipient_ssid = re.sub('.*-','', aprslib.parse(packet)['addresse']) for i in user_settings.items(): -## print('checking user_settings ' + recipient) - if recipient in i[1][0]['call'] and recipient_ssid in i[1][1]['ssid']: -## print(i[1][0]) -## print(i[1][1]) -## print(aprslib.parse(packet)) + ssid = i[1][1]['ssid'] + if i[1][1]['ssid'] == '': + ssid = user_aprs_ssid + if recipient in i[1][0]['call'] and recipient_ssid in ssid: mailbox_write(re.sub('-.*','', aprslib.parse(packet)['addresse']), aprslib.parse(packet)['from'], time.time(), aprslib.parse(packet)['message_text'], recipient) if 'msgNo' in aprslib.parse(packet): time.sleep(1) @@ -71,9 +68,10 @@ if __name__ == '__main__': aprs_login = parser.get('GPS_DATA', 'APRS_RECEIVE_LOGIN_CALL') aprs_passcode = parser.get('GPS_DATA', 'APRS_LOGIN_PASSCODE') mailbox_file = parser.get('GPS_DATA', 'MAILBOX_FILE') + user_settings_file = mailbox_file = parser.get('GPS_DATA', 'USER_SETTINGS_FILE') AIS = aprslib.IS(aprs_login, passwd=int(aprs_passcode), host=aprs_server, port=int(aprs_port)) - user_settings = ast.literal_eval(os.popen('cat ../../user_settings.txt').read()) + user_settings = ast.literal_eval(os.popen('cat ' + user_settings_file).read()) print('APRS message receive script for GPS/Data Application.\nAuthor: Eric, KF7EEL - kf7eel@qsl.net') AIS.set_filter(parser.get('GPS_DATA', 'APRS_FILTER')) AIS.connect()