Working with pre 2.7.0

This commit is contained in:
Hemna 2022-12-20 12:22:12 -05:00
parent 618fb85358
commit d7260fbd71
2 changed files with 35 additions and 62 deletions

View File

@ -21,7 +21,7 @@ docs: build
cp Changelog docs/changelog.rst cp Changelog docs/changelog.rst
tox -edocs tox -edocs
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts clean: clean-build clean-pyc clean-test clean-dev ## remove all build, test, coverage and Python artifacts
clean-build: ## remove build artifacts clean-build: ## remove build artifacts
rm -fr build/ rm -fr build/
@ -42,6 +42,10 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/ rm -fr htmlcov/
rm -fr .pytest_cache rm -fr .pytest_cache
clean-dev: ## Clean out the venv
rm -rf $(VENVDIR)
rm Makefile.venv
coverage: ## check code coverage quickly with the default Python coverage: ## check code coverage quickly with the default Python
coverage run --source aprsd_weewx_plugin setup.py test coverage run --source aprsd_weewx_plugin setup.py test
coverage report -m coverage report -m

View File

@ -52,11 +52,11 @@ class WeewxMQTTPlugin(plugin.APRSDRegexCommandPluginBase):
if self.enabled: if self.enabled:
LOG.info("Creating WeewxMQTTThread") LOG.info("Creating WeewxMQTTThread")
self.queue = ClearableQueue(maxsize=1) self.queue = ClearableQueue(maxsize=1)
self.wx_queue = queue.Queue(maxsize=2) self.wx_queue = ClearableQueue(maxsize=1)
mqtt_thread = WeewxMQTTThread( mqtt_thread = WeewxMQTTThread(
config=self.config, config=self.config,
msg_queues=self.queue,
wx_queue=self.wx_queue, wx_queue=self.wx_queue,
msg_queue=self.queue,
) )
threads = [mqtt_thread] threads = [mqtt_thread]
@ -161,10 +161,10 @@ class WeewxMQTTPlugin(plugin.APRSDRegexCommandPluginBase):
class WeewxMQTTThread(threads.APRSDThread): class WeewxMQTTThread(threads.APRSDThread):
def __init__(self, config, msg_queues, wx_queue): def __init__(self, config, wx_queue, msg_queue):
super().__init__("WeewxMQTTThread") super().__init__("WeewxMQTTThread")
self.config = config self.config = config
self.msg_queues = msg_queues self.msg_queue = msg_queue
self.wx_queue = wx_queue self.wx_queue = wx_queue
self.setup() self.setup()
@ -201,15 +201,18 @@ class WeewxMQTTThread(threads.APRSDThread):
wx_data = json.loads(msg.payload) wx_data = json.loads(msg.payload)
LOG.debug(f"Got WX data {wx_data}") LOG.debug(f"Got WX data {wx_data}")
# Make sure we have only 1 item in the queue # Make sure we have only 1 item in the queue
if self.msg_queues.qsize() >= 1: if self.msg_queue.qsize() >= 1:
self.msg_queues.clear() self.msg_queue.clear()
self.msg_queues.put(wx_data) self.msg_queue.put(wx_data)
self.wx_queue.clear()
self.wx_queue.put(wx_data) self.wx_queue.put(wx_data)
def stop(self): def stop(self):
LOG.info("Disconnecting from MQTT") LOG.info(__class__.__name__+" Stop")
self.thread_stop = True self.thread_stop = True
LOG.info("Stopping loop")
self.client.loop_stop() self.client.loop_stop()
LOG.info("Disconnecting from MQTT")
self.client.disconnect() self.client.disconnect()
def loop(self): def loop(self):
@ -225,7 +228,7 @@ class WeewxWXAPRSThread(threads.APRSDThread):
self.wx_queue = wx_queue self.wx_queue = wx_queue
self.latitude = self.config.get("services.weewx.location.latitude") self.latitude = self.config.get("services.weewx.location.latitude")
self.longitude = self.config.get("services.weewx.location.longitude") self.longitude = self.config.get("services.weewx.location.longitude")
self.callsign = self.config.get("services.weewx.callsign") self.callsign = self.config.get("aprsd.callsign")
self.last_send = datetime.datetime.now() self.last_send = datetime.datetime.now()
if self.latitude and self.longitude: if self.latitude and self.longitude:
@ -233,7 +236,6 @@ class WeewxWXAPRSThread(threads.APRSDThread):
float(self.latitude), float(self.latitude),
float(self.longitude), float(self.longitude),
) )
self.address = f"{self.callsign}>APRS,TCPIP*:"
def decdeg2dmm_m(self, degrees_decimal): def decdeg2dmm_m(self, degrees_decimal):
is_positive = degrees_decimal >= 0 is_positive = degrees_decimal >= 0
@ -264,12 +266,6 @@ class WeewxWXAPRSThread(threads.APRSDThread):
minutes = str(det.get("minutes")).zfill(2) minutes = str(det.get("minutes")).zfill(2)
det.get("seconds") det.get("seconds")
hundredths = str(det.get("hundredths")).split(".")[1] hundredths = str(det.get("hundredths")).split(".")[1]
LOG.debug(
f"LAT degress {degrees} minutes {str(minutes)} "
"seconds {seconds} hundredths {hundredths} direction {direction}",
)
lat = f"{degrees}{str(minutes)}.{hundredths}{direction}" lat = f"{degrees}{str(minutes)}.{hundredths}{direction}"
return lat return lat
@ -284,12 +280,6 @@ class WeewxWXAPRSThread(threads.APRSDThread):
minutes = str(det.get("minutes")).zfill(2) minutes = str(det.get("minutes")).zfill(2)
det.get("seconds") det.get("seconds")
hundredths = str(det.get("hundredths")).split(".")[1] hundredths = str(det.get("hundredths")).split(".")[1]
LOG.debug(
f"LON degress {degrees} minutes {str(minutes)} "
"seconds {seconds} hundredths {hundredths} direction {direction}",
)
lon = f"{degrees}{str(minutes)}.{hundredths}{direction}" lon = f"{degrees}{str(minutes)}.{hundredths}{direction}"
return lon return lon
@ -309,8 +299,7 @@ class WeewxWXAPRSThread(threads.APRSDThread):
return retn_value return retn_value
def make_aprs_wx(self, wx_data): def build_wx_packet(self, wx_data):
# LOG.debug(wx_data)
wind_dir = float(wx_data.get("windDir", 0.00)) wind_dir = float(wx_data.get("windDir", 0.00))
wind_speed = float(wx_data.get("windSpeed_mph", 0.00)) wind_speed = float(wx_data.get("windSpeed_mph", 0.00))
wind_gust = float(wx_data.get("windGust_mph", 0.00)) wind_gust = float(wx_data.get("windGust_mph", 0.00))
@ -321,45 +310,27 @@ class WeewxWXAPRSThread(threads.APRSDThread):
humidity = float(wx_data.get("outHumidity", 0.00)) humidity = float(wx_data.get("outHumidity", 0.00))
# * 330.863886667 # * 330.863886667
pressure = float(wx_data.get("relbarometer", 0.00)) * 10 pressure = float(wx_data.get("relbarometer", 0.00)) * 10
LOG.info(f"wind_dir {wind_dir}") return aprsd.packets.WeatherPacket(
LOG.info(f"wind_speed {wind_speed}") from_call=self.callsign,
LOG.info(f"wind_gust {wind_gust}") to_call="APRS",
LOG.info(f"temperature {temperature}") latitude=self.convert_latitude(float(self.latitude)),
LOG.info(f"rain_last_hr {rain_last_hr}") longitude=self.convert_longitude(float(self.longitude)),
LOG.info(f"rain_last_24_hrs {rain_last_24_hrs}") course=int(wind_dir),
LOG.info(f"rain_since_midnight {rain_since_midnight}") speed=wind_speed,
LOG.info(f"humidity {humidity}") wind_gust=wind_gust,
LOG.info(f"pressure {pressure}") temperature=temperature,
rain_1h=rain_last_hr,
# Assemble the weather data of the APRS packet rain_24h=rain_last_24_hrs,
return "{}/{}g{}t{}r{}p{}P{}h{}b{}".format( rain_since_midnight=rain_since_midnight,
self.str_or_dots(wind_dir, 3), humidity=int(round(humidity)),
self.str_or_dots(wind_speed, 3), pressure=pressure,
self.str_or_dots(wind_gust, 3), comment="APRSD WX http://pypi.org/project/aprsd",
self.str_or_dots(temperature, 3),
self.str_or_dots(rain_last_hr, 3),
self.str_or_dots(rain_last_24_hrs, 3),
self.str_or_dots(rain_since_midnight, 3),
self.str_or_dots(humidity, 2),
self.str_or_dots(pressure, 5),
) )
def build_packet(self, wx_data):
utc_datetime = datetime.datetime.now()
packet_data = "{}@{}z{}{}{}".format(
self.address,
utc_datetime.strftime("%d%H%M"),
self.position,
self.make_aprs_wx(wx_data),
"APRSD",
)
return packet_data
def loop(self): def loop(self):
now = datetime.datetime.now() now = datetime.datetime.now()
delta = now - self.last_send delta = now - self.last_send
max_timeout = {"hours": 0.0, "minutes": 1, "seconds": 0} max_timeout = {"hours": 0.0, "minutes": 5, "seconds": 0}
max_delta = datetime.timedelta(**max_timeout) max_delta = datetime.timedelta(**max_timeout)
if delta >= max_delta: if delta >= max_delta:
if not self.wx_queue.empty(): if not self.wx_queue.empty():
@ -378,9 +349,7 @@ class WeewxWXAPRSThread(threads.APRSDThread):
# we have Weather now, so lets format the data # we have Weather now, so lets format the data
# and then send it out to APRS # and then send it out to APRS
raw_aprs_text = self.build_packet(wx) packet = self.build_wx_packet(wx)
packet = aprsd.messaging.RawMessage(raw_aprs_text)
LOG.debug(f"RAW WX Packet {packet}")
packet.retry_count = 1 packet.retry_count = 1
packet.send() packet.send()
self.last_send = datetime.datetime.now() self.last_send = datetime.datetime.now()