Skip to content

Commit

Permalink
Merge pull request #270 from projecthorus/testing
Browse files Browse the repository at this point in the history
Remove Habitat payload document creation, other fixes.
  • Loading branch information
darksidelemm authored Mar 25, 2020
2 parents adf7fd1 + 7faa4ef commit 97f165d
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 51 deletions.
2 changes: 1 addition & 1 deletion auto_rx/autorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus.
# PATCH - Small changes, or minor feature additions.

__version__ = "1.3.0"
__version__ = "1.3.1"


# Global Variables
Expand Down
9 changes: 8 additions & 1 deletion auto_rx/autorx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import copy
import logging
import os
import traceback
import json
from .utils import rtlsdr_test
Expand Down Expand Up @@ -147,6 +148,12 @@ def read_auto_rx_config(filename, no_sdr_test=False):


try:

# Check the file exists.
if not os.path.isfile(filename):
logging.critical("Config file %s does not exist!" % filename)
return None

config = RawConfigParser(auto_rx_config)
config.read(filename)

Expand All @@ -168,7 +175,7 @@ def read_auto_rx_config(filename, no_sdr_test=False):

if auto_rx_config['email_smtp_authentication'] not in ['None', 'TLS', 'SSL']:
logging.error("Config - Invalid email authentication setting. Must be None, TLS or SSL.")
raise Exception()
return None

except:
logging.error("Config - Invalid or missing email settings. Disabling.")
Expand Down
44 changes: 24 additions & 20 deletions auto_rx/autorx/habitat.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,27 +629,31 @@ def handle_telem_dict(self, telem, immediate=False):
# race conditions resulting in multiple payload docs being created.
self.upload_lock.acquire()

# Create a habitat document if one does not already exist:
if not self.observed_payloads[telem['id']]['habitat_document']:
# Check if there has already been telemetry from this ID observed on Habhub
_document_exists = check_callsign(_callsign)
# If so, we don't need to create a new document
if _document_exists:
self.observed_payloads[telem['id']]['habitat_document'] = True
else:
# Otherwise, we attempt to create a new document.
if self.inhibit:
# If we have an upload inhibit, don't create a payload doc.
_created = True
else:
_created = initPayloadDoc(_callsign, description="Meteorology Radiosonde", frequency=telem['freq_float'])

# Habitat Payload document creation has been disabled as of 2020-03-20.
# We now use a common payload document for all radiosonde telemetry.
#
# # Create a habitat document if one does not already exist:
# if not self.observed_payloads[telem['id']]['habitat_document']:
# # Check if there has already been telemetry from this ID observed on Habhub
# _document_exists = check_callsign(_callsign)
# # If so, we don't need to create a new document
# if _document_exists:
# self.observed_payloads[telem['id']]['habitat_document'] = True
# else:
# # Otherwise, we attempt to create a new document.
# if self.inhibit:
# # If we have an upload inhibit, don't create a payload doc.
# _created = True
# else:
# _created = initPayloadDoc(_callsign, description="Meteorology Radiosonde", frequency=telem['freq_float'])

if _created:
self.observed_payloads[telem['id']]['habitat_document'] = True
else:
self.log_error("Error creating payload document!")
self.upload_lock.release()
return
# if _created:
# self.observed_payloads[telem['id']]['habitat_document'] = True
# else:
# self.log_error("Error creating payload document!")
# self.upload_lock.release()
# return

if immediate:
self.log_info("Performing immediate upload for first telemetry sentence of %s." % telem['id'])
Expand Down
17 changes: 13 additions & 4 deletions auto_rx/autorx/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class TelemetryLogger(object):
# Close any open file handles after X seconds of no activity.
# This will help avoid having lots of file handles open for a long period of time if we are handling telemetry
# from multiple sondes.
FILE_ACTIVITY_TIMEOUT = 30
FILE_ACTIVITY_TIMEOUT = 300

# We require the following fields to be present in the input telemetry dict.
REQUIRED_FIELDS = ['frame', 'id', 'datetime', 'lat', 'lon', 'alt', 'temp', 'humidity', 'type', 'freq', 'datetime_dt']
REQUIRED_FIELDS = ['frame', 'id', 'datetime', 'lat', 'lon', 'alt', 'temp', 'humidity', 'type', 'freq', 'datetime_dt', 'vel_v', 'vel_h', 'heading']

LOG_HEADER = "timestamp,serial,frame,lat,lon,alt,vel_v,vel_h,heading,temp,humidity,type,freq,other\n"

def __init__(self,
log_directory = "./log"):
Expand Down Expand Up @@ -116,13 +118,17 @@ def telemetry_to_string(self, telemetry):
Args:
telemetry (dict): Telemetry dictionary to process.
"""
_log_line = "%s,%s,%d,%.5f,%.5f,%.1f,%.1f,%.1f,%s,%.3f" % (
# timestamp,serial,frame,lat,lon,alt,vel_v,vel_h,heading,temp,humidity,type,freq,other
_log_line = "%s,%s,%d,%.5f,%.5f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%s,%.3f" % (
telemetry['datetime'],
telemetry['id'],
telemetry['frame'],
telemetry['lat'],
telemetry['lon'],
telemetry['alt'],
telemetry['vel_v'],
telemetry['vel_h'],
telemetry['heading'],
telemetry['temp'],
telemetry['humidity'],
telemetry['type'],
Expand Down Expand Up @@ -188,7 +194,10 @@ def write_telemetry(self, telemetry):
_log_file_name = os.path.join(self.log_directory, _log_suffix)
self.log_info("Opening new log file: %s" % _log_file_name)
# Create entry in open logs dictionary
self.open_logs[_id] = {'log':open(_log_file_name,'a'), 'last_time':time.time()}
self.open_logs[_id] = {'log':open(_log_file_name,'a'), 'last_time':time.time()}

# Write in a header line.
self.open_logs[_id]['log'].write(self.LOG_HEADER)


# Produce log file sentence.
Expand Down
9 changes: 7 additions & 2 deletions auto_rx/autorx/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
{title:"Latitude", field:"lat", headerSort:false},
{title:"Longitude", field:"lon", headerSort:false},
{title:"Alt (m)", field:"alt", headerSort:false},
{title:"Vel (kph)", field:"vel_h", headerSort:false},
{title:"Asc (m/s)", field:"vel_v", headerSort:false},
{title:"Temp (°C)", field:"temp", headerSort:false},
{title:"RH (%)", field:"humidity", headerSort:false},
Expand Down Expand Up @@ -219,8 +220,8 @@

var _look_angles = calculate_lookangles(_station, _bal);

sonde_id_data.azimuth = _look_angles.azimuth.toFixed(0);
sonde_id_data.elevation = _look_angles.elevation.toFixed(0);
sonde_id_data.azimuth = _look_angles.azimuth.toFixed(1);
sonde_id_data.elevation = _look_angles.elevation.toFixed(1);
sonde_id_data.range = (_look_angles.range/1000).toFixed(1);
} else{
// Insert blank data.
Expand All @@ -234,6 +235,7 @@
sonde_id_data.lon = sonde_id_data.lon.toFixed(5);
sonde_id_data.alt = sonde_id_data.alt.toFixed(1);
sonde_id_data.vel_v = sonde_id_data.vel_v.toFixed(1);
sonde_id_data.vel_h = (sonde_id_data.vel_h*3.6).toFixed(1);
// Add a link to HabHub if we have habitat enabled.
if ("habitat_enabled" in autorx_config){
if(autorx_config.habitat_enabled ==true){
Expand All @@ -255,6 +257,9 @@
sonde_id_data.other += "BT " + new Date(sonde_id_data.bt*1000).toISOString().substr(11, 8) + " ";
}
}
if (sonde_id_data.hasOwnProperty('batt')){
sonde_id_data.other += sonde_id_data.batt.toFixed(1) + " V";
}

telem_data.push(sonde_id_data);
});
Expand Down
2 changes: 1 addition & 1 deletion auto_rx/station.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ station_beacon_rate = 30

# Station beacon comment.
# <version> will be replaced with the current auto_rx version number
station_beacon_commment = radiosonde_auto_rx SondeGate v<version>
station_beacon_comment = radiosonde_auto_rx SondeGate v<version>

# Station Beacon Icon
# The APRS icon to use, as defined in http://www.aprs.org/symbols.html
Expand Down
Loading

0 comments on commit 97f165d

Please sign in to comment.