1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-04-19 09:49:01 -04:00

Fixed send-message with email command and others

This patch fixes a minor issue with the new send-message command
You now should use nargs to send the email command because it includes
a - as the start.  click assumed that any -<foo>  looks ike an argument.
So call aprsd with

aprsd send-command <callsign> -- -wb sendmap

This patch also adds -h as a help option for aprsd to make it simpler to
type.

This patch adds the VersionPlugin so you can remotely request the
version of aprsd that's running.
This commit is contained in:
Hemna 2020-12-20 12:14:51 -05:00
parent 923e1a7c3d
commit 3261710bf8
5 changed files with 40 additions and 9 deletions

View File

@ -41,6 +41,7 @@ class Client(object):
host = self.config["aprs"].get("host", "rotate.aprs.net")
port = self.config["aprs"].get("port", 14580)
connected = False
backoff = 1
while not connected:
try:
LOG.info("Creating aprslib client")
@ -49,10 +50,11 @@ class Client(object):
aprs_client.logger = LOG
aprs_client.connect()
connected = True
backoff = 1
except Exception as e:
LOG.error("Unable to connect to APRS-IS server.\n")
print(str(e))
time.sleep(5)
LOG.error("Unable to connect to APRS-IS server. '{}' ".format(e))
time.sleep(backoff)
backoff = backoff * 2
continue
LOG.debug("Logging in to APRS-IS with user '%s'" % user)
return aprs_client

View File

@ -23,6 +23,7 @@
# python included libs
import logging
import os
import random
import signal
import sys
import time
@ -50,6 +51,8 @@ LOG_LEVELS = {
"DEBUG": logging.DEBUG,
}
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
# localization, please edit:
# HOST = "noam.aprs2.net" # north america tier2 servers round robin
# USER = "KM6XXX-9" # callsign of this aprs client with SSID
@ -85,7 +88,7 @@ Default type: auto
)
@click.group(help=cmd_help)
@click.group(help=cmd_help, context_settings=CONTEXT_SETTINGS)
@click.version_option()
def main():
pass
@ -271,7 +274,7 @@ def sample_config():
help="the APRS-IS password for APRS_LOGIN",
)
@click.argument("tocallsign")
@click.argument("command", default="location")
@click.argument("command", nargs=-1)
def send_message(
loglevel, quiet, config_file, aprs_login, aprs_password, tocallsign, command
):
@ -294,16 +297,20 @@ def send_message(
setup_logging(config, loglevel, quiet)
LOG.info("APRSD Started version: {}".format(aprsd.__version__))
message_number = random.randint(1, 90)
if type(command) is tuple:
command = " ".join(command)
LOG.info("Sending Command '{}'".format(command))
def rx_packet(packet):
LOG.debug("Got packet back {}".format(packet))
# LOG.debug("Got packet back {}".format(packet))
messaging.log_packet(packet)
resp = packet.get("response", None)
if resp == "ack":
sys.exit(0)
cl = client.Client(config)
messaging.send_message_direct(tocallsign, command)
messaging.send_message_direct(tocallsign, command, message_number)
try:
# This will register a packet consumer with aprslib

View File

@ -200,10 +200,13 @@ def log_message(
LOG.info("\n".join(log_list))
def send_message_direct(tocall, message):
def send_message_direct(tocall, message, message_number=None):
"""Send a message without a separate thread."""
cl = client.get_client()
this_message_number = 1
if not message_number:
this_message_number = 1
else:
this_message_number = message_number
fromcall = CONFIG["aprs"]["login"]
line = "{}>APRS::{}:{}{{{}\n".format(
fromcall,

View File

@ -15,6 +15,7 @@ import requests
import six
from thesmuggler import smuggle
import aprsd
from aprsd import email, messaging
from aprsd.fuzzyclock import fuzzy
@ -31,6 +32,7 @@ CORE_PLUGINS = [
"aprsd.plugin.PingPlugin",
"aprsd.plugin.TimePlugin",
"aprsd.plugin.WeatherPlugin",
"aprsd.plugin.VersionPlugin",
]
@ -480,3 +482,19 @@ class EmailPlugin(APRSDPluginBase):
# messaging.send_message(fromcall, "Bad email address")
return reply
class VersionPlugin(APRSDPluginBase):
"""Version of APRSD Plugin."""
version = "1.0"
command_regex = "^[vV]"
command_name = "version"
# message_number:time combos so we don't resend the same email in
# five mins {int:int}
email_sent_dict = {}
def command(self, fromcall, message, ack):
LOG.info("Version COMMAND")
return "APRSD version '{}'".format(aprsd.__version__)

View File

@ -19,6 +19,7 @@ pbr==5.5.1 # via -r requirements.in
pluggy==0.13.1 # via -r requirements.in
py3-validate-email==0.2.12 # via -r requirements.in
pyyaml==5.3.1 # via -r requirements.in
requests==2.25.1 # via -r requirements.in
shellingham==1.3.2 # via click-completion
six==1.15.0 # via -r requirements.in, click-completion, imapclient
thesmuggler==1.0.1 # via -r requirements.in