--[[ altlog.lua Verson: 1.0 A Lua script for EdgeTX to log on demand the maximum altitude (from the "Alt+" telemetry sensor) to a CSV file. USAGE ----- EdgeTX Special Function -> Lua Script: altlog WHAT IT DOES ============ On activation it: 1. Builds a log filename from the model name and today's date: /LOGS/modelname_ALT_yyyy-mm-dd.csv 2. Creates the file (with a header row) if it doesn't already exist. 3. Reads the "Alt+" telemetry sensor (max altitude). 4. Appends one line: either 2026-08-12 15:23:26, 45 m or, if no telemetry is available: 2026-08-12 15:23:26, no ALT+ telemetry INSTALLATION ============ 1. Rename the file to altlog.lua (if different) 2. Copy the file to /SCRIPTS/FUNCTIONS/ on the SD card or flash memory. 3. In MODEL -> Special Functions, add a new special function: Trigger: Function: 'Lua Script' Value: altlog.lua Repeat: 1x Enable: checked To avoid writing dozens of lines every time you hold the switch, make sure that Repeat is set to 1x. To record launch heights with an RC-Soar DLG template, identify the SF which calls out the launch height, and use the same switch to trigger the script. CODE NOTES ========== - Change ALT_SENSOR below if your telemetry uses a different sensor name for altitude. - Telemetry presence is detected via RSSI: if RSSI is 0, we treat telemetry as unavailable. - Model names are sanitised (spaces and punctuation become "_") so they're safe to use in a filename. LICENSE ======= Copyright (c) Mike Shellim This script is provided under the GNU General Public License v3. https://www.gnu.org/licenses/gpl-3.0.en.html ]] local LOG_DIR = "/LOGS/" local ALT_SENSOR = "Alt+" -- '+' so that maximum height is logged, not current height local function sanitise(name) return (string.gsub(name, "[^%w%-]", "_")) end local function twoDigits(n) return string.format("%02d", n) end local function buildTimestamps() local dt = getDateTime() local dateStr = string.format("%04d-%02d-%02d", dt.year, dt.mon, dt.day) local timeStr = string.format("%s:%s:%s", twoDigits(dt.hour), twoDigits(dt.min), twoDigits(dt.sec)) return dateStr, dateStr .. " " .. timeStr end local function logFilePath(dateStr) local modelName = sanitise(model.getInfo().name or "model") return LOG_DIR .. modelName .. "_ALT_" .. dateStr .. ".csv" end local function fileExists(path) local f = io.open(path, "r") if f then io.close(f) return true end return false end local function writeRecord() local dateStr, timestamp = buildTimestamps() local path = logFilePath(dateStr) local isNew = not fileExists(path) local f = io.open(path, "a") if not f then -- Couldn't open (e.g. /LOGS missing on the SD card) - nothing more -- we can do from here. return end if isNew then io.write(f, "time, altitude\n") end local telemetryOk = getRSSI() ~= 0 local alt = getValue(ALT_SENSOR) local line if telemetryOk and alt ~= nil then line = string.format("%s, %.2f", timestamp, alt) else line = string.format("%s, no %s telemetry", timestamp, ALT_SENSOR) end io.write(f, line .. "\n") io.close(f) end local function init() end local function run(event) writeRecord() return 0 end return { init = init, run = run }