--[[ altlog.lua Verson: 1.2 A Lua script for EdgeTX. When activated, logs the instantaneous value of "Alt+" to a CSV file. USAGE ----- EdgeTX Special Function, type='Lua Script', value = 'altlog.lua', repeat = '1x' WHAT IT DOES ============ On activation of special function: 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 ============ Install the script on your EdgeTX radio as follows: 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 special function with these settings: Trigger: Function: 'Lua Script' Value: altlog.lua Repeat: 1x (important to avoid repeated logging while the switch is held) Enable: checked To record launch heights with an RC-Soar DLG template, identify the existing special function which calls out launch height, and use the same trigger in the new special function. HISTORY ======= 2026-08-27: v1.2 - More robust checking for telemetry stream 2026-08-26: v1.1 - Mild refactoring 2026-08-25: v1.0 - Initial release 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 buildTimestamps() local dt = getDateTime() local dateStr = string.format("%04d-%02d-%02d", dt.year, dt.mon, dt.day) local timeStr = string.format("%02d:%02d:%02d", dt.hour, dt.min, 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 alt = getSourceValue(ALT_SENSOR) local line if 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 }