simple-bpq-telnet-application
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| simple-bpq-telnet-application [2024/11/28 17:18] – created kc2ihx | simple-bpq-telnet-application [2026/01/01 22:42] (current) – [BPQ configuration] kc2ihx | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Creating a simple BPQ Application ====== | ====== Creating a simple BPQ Application ====== | ||
| This tutorial shows you how to set up a simple python script [[https:// | This tutorial shows you how to set up a simple python script [[https:// | ||
| + | |||
| + | In order to do this we'll do the following: | ||
| + | - Create a location for the script, data, and a python '' | ||
| + | - Write the script | ||
| + | - Add the application to '' | ||
| + | - Setup a '' | ||
| + | |||
| + | ===== Setup ===== | ||
| + | To organize this project, I created a python virtual environment called '' | ||
| + | |||
| + | I'm using the python virtual environment framework to help manage the various dependencies I might want to use for these scripts. | ||
| + | |||
| + | < | ||
| + | $ cd ~/.local | ||
| + | $ python -m venv bpq-apps | ||
| + | $ cd ./bpq-apps | ||
| + | $ mkdir scripts data | ||
| + | $ source ./ | ||
| + | (bpq-apps)$ pip install telnetlib3 | ||
| + | </ | ||
| ===== Writing the program ===== | ===== Writing the program ===== | ||
| I chose to write this in Python to be a //little// more clear than the Perl application provided in the link above. | I chose to write this in Python to be a //little// more clear than the Perl application provided in the link above. | ||
| - | This program, called '' | + | The BPQ Application, called '' |
| - | + | ||
| - | I saved both of these to '' | + | |
| ==== Program Code ==== | ==== Program Code ==== | ||
| Line 13: | Line 31: | ||
| < | < | ||
| - | import asyncio, telnetlib3, json | + | import asyncio, telnetlib3, json, sys |
| from optparse import OptionParser | from optparse import OptionParser | ||
| Line 22: | Line 40: | ||
| messages = json.load(open(options.filename,' | messages = json.load(open(options.filename,' | ||
| + | |||
| + | def print_log(*a): | ||
| + | print(*a, file=sys.stderr) | ||
| + | |||
| async def shell(reader, | async def shell(reader, | ||
| incall = await reader.readline() | incall = await reader.readline() | ||
| - | | + | |
| writer.write(" | writer.write(" | ||
| writer.write(" | writer.write(" | ||
| textblocks = messages[" | textblocks = messages[" | ||
| - | | + | leave = False #inp[0].upper() in [" |
| - | | + | rolled = False |
| + | inp = await reader.read(1) | ||
| while inp and not leave and len(textblocks) > 0: | while inp and not leave and len(textblocks) > 0: | ||
| - | print(" | + | |
| - | writer.write(textblocks.pop()) | + | writer.write(textblocks.pop(0)) |
| await writer.drain() | await writer.drain() | ||
| inp = await reader.readline() | inp = await reader.readline() | ||
| - | leave = inp[0].upper() in [" | + | |
| + | # notify that rolling has happened | ||
| + | print_log(" | ||
| + | rolled = True | ||
| + | | ||
| writer.close() | writer.close() | ||
| Line 67: | Line 94: | ||
| In my '' | In my '' | ||
| < | < | ||
| - | CMDPORT=8005 63001 4565 10001 | + | CMDPORT=8005 63001 10001 |
| </ | </ | ||
| - | and in the application list, I added a new entry, where '' | + | and in the application list, I added a new entry, where '' |
| < | < | ||
| - | APPLICATION | + | APPLICATION |
| </ | </ | ||
| ===== Configuring this as a service ===== | ===== Configuring this as a service ===== | ||
| - | //todo write block describing adding | + | Next we'll configure |
| + | Put this file in ''/ | ||
| + | < | ||
| + | # service for RRoAX25 server | ||
| + | # replace USER with the username under which you created the bpq-apps venv | ||
| + | [Unit] | ||
| + | Description=" | ||
| + | After=network.target | ||
| + | # this might be backwards, but I do need linbpq for this to work. | ||
| + | Requires=linbpq.service | ||
| + | [Service] | ||
| + | Type=simple | ||
| + | User=evan | ||
| + | Group=evan | ||
| + | WorkingDirectory=/ | ||
| + | ExecStart=/ | ||
| + | Restart=always | ||
| + | RestartSec=3 | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=default.target | ||
| + | </ | ||
| + | |||
| + | Activate it by running: | ||
| + | < | ||
| + | sudo systemctl enable rick.service | ||
| + | sudo systemctl start rick.service | ||
| + | </ | ||
| + | |||
| + | Then check the status to confirm it is working: | ||
| + | |||
| + | < | ||
| + | systemctl status rick.service | ||
| + | </ | ||
| + | |||
| + | If you need to edit the service file, reload it with: | ||
| + | < | ||
| + | systemctl daemon-reload | ||
| + | </ | ||
| + | |||
| + | Finally, to see who has used it: | ||
| + | < | ||
| + | journalctl -u rick.service -f | ||
| + | </ | ||
simple-bpq-telnet-application.1732814305.txt.gz · Last modified: by kc2ihx