Radio sonde + auto mode
This commit is contained in:
54
server/src/radiosonde.mjs
Normal file
54
server/src/radiosonde.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
import {cfg} from './config.mjs';
|
||||
|
||||
let sondeCache = null;
|
||||
let sondeCacheTs = 0;
|
||||
const SONDE_TTL = 1000;
|
||||
|
||||
export async function getSondes() {
|
||||
if (sondeCache && Date.now() - sondeCacheTs < SONDE_TTL) return sondeCache;
|
||||
const {ADSB_URL} = cfg();
|
||||
if (!ADSB_URL) return {data: []};
|
||||
|
||||
const r = await fetch(`${ADSB_URL}:9989/get_telemetry_archive`);
|
||||
const data = await r.json();
|
||||
|
||||
sondeCache = Object.entries(data).map(([id, sonde]) => {
|
||||
const t = sonde.latest_telem ?? {};
|
||||
const path = sonde.path ?? [];
|
||||
|
||||
return {
|
||||
id,
|
||||
type: t.type,
|
||||
subtype: t.subtype,
|
||||
lat: t.lat,
|
||||
lon: t.lon,
|
||||
altitude: t.alt,
|
||||
heading: t.heading,
|
||||
speed: t.vel_h,
|
||||
vertical_speed: t.vel_v,
|
||||
sats: t.sats,
|
||||
timestamp: t.datetime ? Date.parse(t.datetime) : sonde.timestamp * 1000,
|
||||
datetime: t.datetime,
|
||||
frame: t.frame,
|
||||
battery: t.batt,
|
||||
temperature: t.temp,
|
||||
humidity: t.humidity,
|
||||
pressure: t.pressure,
|
||||
frequency: t.freq_float,
|
||||
frequency_hz: t.tx_frequency,
|
||||
snr: t.snr,
|
||||
ppm: t.ppm,
|
||||
aprsid: t.aprsid?.trim(),
|
||||
rs41_mainboard: t.rs41_mainboard,
|
||||
rs41_mainboard_fw: t.rs41_mainboard_fw,
|
||||
version: t.version,
|
||||
ref_datetime: t.ref_datetime,
|
||||
ref_position: t.ref_position,
|
||||
sdr_device_idx: t.sdr_device_idx,
|
||||
path
|
||||
};
|
||||
});
|
||||
|
||||
sondeCacheTs = Date.now();
|
||||
return sondeCache;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {dailyWeather, hourlyWeather} from './openmeteo.mjs';
|
||||
import {getTinyGSData} from './sats.mjs';
|
||||
import {getSpaceWeather} from './space.mjs';
|
||||
import {Aurora} from './aurora.mjs';
|
||||
import {getSondes} from './radiosonde.mjs';
|
||||
|
||||
// ── Uncaught error handlers ───────────────────────────────────────────────────
|
||||
|
||||
@@ -152,7 +153,7 @@ app.get('/api/space', async (req, res) => {
|
||||
res.json(filterFields(await getSpaceWeather(), fields));
|
||||
});
|
||||
|
||||
// ── ADSB/AIS/SAT Proxy ────────────────────────────────────────────────────────────
|
||||
// ── ADSB/AIS/SAT/RadioSonde Proxy ────────────────────────────────────────────────────────────
|
||||
|
||||
app.get('/api/adsb', asyncHandler(async (req, res) => res.json(await getADSB())));
|
||||
app.get('/api/adsb/:icao/image', asyncHandler(async (req, res) => {
|
||||
@@ -167,6 +168,8 @@ app.get('/api/ais/:mmsi/image', asyncHandler(async (req, res) => {
|
||||
res.contentType('image/jpeg').send(buffer)
|
||||
}));
|
||||
|
||||
app.get('/api/sondes', asyncHandler(async (req, res) => res.json(await getSondes())));
|
||||
|
||||
app.get('/api/sats', (_req, res) => res.json(getTinyGSData()));
|
||||
|
||||
// ── DOCS ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user