HamAlert spots, part two: different triggers, different rings
A forty-line program between HamAlert and Mast, so a summit-to-summit spot pages and the rest just beep.
This follows on from part one, where every HamAlert trigger with the URL action ticked rings the phone the same way. HamAlert allows one URL per account, so if you want different triggers to ring differently, something has to sit in the middle and sort the spots. That something is a little JavaScript. If one alert source is enough for you, part one is all you need.
what HamAlert puts on the address
HamAlert adds every detail of the spot to the end of the address, each as a named field. Mast reads the ones it knows and ignores the rest. From HamAlert's server code, the useful ones:
| Field | Example | Mast does |
|---|---|---|
title | SOTA W7ABC on W7W/LC-001 (7.032 CW) | uses it as the alert title |
fullCallsign, callsign | W7ABC, W7ABC (a /P stays on the first and comes off the second) | ignores; a bridge can use them |
frequency, band, mode | 7.032, 40m, cw (lowercase) | ignores |
source | sotawatch, pota, rbn, cluster | ignores |
summitRef, summitName, summitPoints | W7W/LC-001, Mount Saint Helens, 10 | ignores |
wwffRef, wwffName | US-1518, the park's name | ignores (POTA references travel in the WWFF fields) |
spotter, snr, comment | K1RA-4, 18, the spot's comment | ignores |
triggerComment | s2s | ignores; the bridge routes on it |
The whole list is in hamutil.js in HamAlert's server. HamAlert doesn't retry. If Mast can't be reached in the second the spot lands, that spot is gone. It hasn't been a problem so far.
where the program runs
The program below runs on Tissue Cloud, the other thing my company makes besides Mast.
Tissue Cloud is hosting for small programs. You write a file, run one command, and a few seconds later it's answering at a web address. There's no box to keep patched, nothing to renew, nothing listening on your home line. That last one is why the bridge can't just be another script on the shack Pi: HamAlert's servers have to be able to reach it, and a Pi behind your router isn't reachable without port forwarding, a dynamic DNS name and a certificate to keep on top of.
One of those programs is a Cell. A Cell is a folder with two files in it:
your code, and a short ribo.toml saying what it's called and what it needs. The
code is a fetch handler, which means a request comes in and you return a
response, written in plain JavaScript and running in its own V8 isolate. It imports nothing
of ours. The forty-odd lines in the next section are a whole Cell, start to finish. If you'd
sooner write Rust or C, it takes WebAssembly too.
Things attach to a Cell one line at a time in that manifest: a SQL database, a bucket for files, a secret, a schedule. The bridge below uses a secret, so the two Mast addresses aren't sitting in the code. A longer version of it could keep every spot that ever paged you in a SQL table, and serve you a page to look at them on.
The free plan covers the bridge with plenty to spare. It doesn't need a card, and a Cell gets
an address on tissue.dev the moment you deploy it.
two alert sources from one HamAlert URL
One address per HamAlert account is the limit you run into. Say you want the ATNO as a
page, S2S on a loud alert source, and the summit name under the title.
The fix is a small program that sits between the two. On Tissue Cloud that's called a
Cell: a few lines of JavaScript that run on our servers and answer at a web address of their
own. HamAlert calls the Cell, the Cell decides which Mast alert source gets the spot. About forty
lines, runs on the free plan. The two alert sources it sends to are the app's two free alert sources,
with the shack-pi heartbeat alongside, so it still needs no Mast account.
The two Mast addresses live in the Cell's vault, the place a Cell keeps its secrets, not in HamAlert's settings and not in the code.
The manifest
Two files in a folder. The first tells Tissue Cloud what the Cell is called and which secrets it needs.
# ribo.toml
[cell]
name = "hamalert"
js = "./hamalert.js"
# The two Mast send addresses. Set both with `ribo vault set` BEFORE the first
# deploy. A vault value that isn't there yet gets stored as a placeholder
# string, and the Cell then throws on every spot instead of sending.
[[bindings]]
type = "vault"
binding = "DX_URL"
[[bindings]]
type = "vault"
binding = "S2S_URL"The Cell
The second is the program itself.
// hamalert.js
export default {
async fetch(request, env) {
const q = new URL(request.url).searchParams;
const title = q.get("title");
if (!title) return new Response("no title", { status: 400 });
// Route on the trigger comment. HamAlert sends it as triggerComment,
// joined with ", " if more than one trigger matched.
const comments = (q.get("triggerComment") || "").split(",").map((s) => s.trim());
const s2s = comments.includes("s2s");
// Body text. SOTA spots carry the summit, POTA spots the park;
// the reference for both lands in the WWFF fields on POTA's side.
const where = q.get("summitName")
? `${q.get("summitRef")} ${q.get("summitName")}, ${q.get("summitPoints")} pts`
: q.get("wwffName")
? `${q.get("wwffRef")} ${q.get("wwffName")}`
: "";
const heard = q.get("spotter") ? `spotted by ${q.get("spotter")}` : "";
const body = [where, q.get("comment"), heard].filter(Boolean).join(" · ");
const alert = new URLSearchParams({
title,
body,
priority: s2s ? "loud" : "page",
ack: "required",
retry: "60",
expire: "900",
});
// Re-spots of the same station on the same band fold into one alert.
// Only when HamAlert sent both, or every spot would share one key.
const key = [q.get("callsign"), q.get("band")].filter(Boolean).join("-");
if (key) alert.set("key", key);
const res = await fetch(s2s ? env.S2S_URL : env.DX_URL, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: alert,
});
return new Response(res.ok ? "ok" : `mast said ${res.status}`, { status: res.ok ? 200 : 502 });
},
};
The Cell waits for Mast's answer before it replies, so opening the Cell's own URL in a
browser tells you whether the send worked. HamAlert won't tell you: it fires the URL and
drops the reply on the floor, so over there the proof is still the phone ringing. The
key means a respot of the same activator on the same band updates the alert you
already have instead of ringing a new one.
Deploy it
-
Install
ribo, the Tissue Cloud command-line tool. One static binary, nothing to install alongside it. There's a Raspberry Pi build, so this can run on the shack Pi rather than your laptop if that's easier, along with builds for both kinds of Mac and for 64-bit Intel Linux; Windows runs the same line under WSL. They're all on the download page. The Pi build wants the 64-bit Raspberry Pi OS: ifuname -mdoesn't sayaarch64you're on the 32-bit image, the installer stops and names the architecture it found.curl -fsSL https://tissue.systems/install.sh | sh ribo loginopens a browser and signs the CLI in. The free plan does it: five Cells, no card.- Make a folder with the two files above and
cdinto it. -
Put the two Mast addresses in the vault, each from its own alert source in the app:
ribo vault set hamalert DX_URL # prompts; paste the page channel's address ribo vault set hamalert S2S_URL # prompts; paste the s2s channel's address -
ribo deploy. The last lines give you the URL:deployed hamalert address 7f2a91c4h8k2m kind js url https://hamalert.quartz-4b.tissue.dev vault DX_URL, S2S_URL - In HamAlert, replace the Mast address with that
url. Method stays GET. Simulate.
From here, change whatever you like. Drop spots under a certain snr. Send park
spots to a third alert source only when you're home. Flag a dxcc on your needed
list. It's plain JavaScript and a redeploy takes a few seconds.
Two things to know before you do. Anyone who calls the Cell's address pages your phone, so
keep it to yourself the same way you keep the Mast addresses. And the values aren't always
what the title suggests: mode comes in lowercase, and a state comes with its
country in front, US_OR for Oregon.
73,
Denis, KI7KLT
HamAlert is by Manuel Kasper, HB9DQM. Corrections and questions reach support@tissue.systems.