Skip to main content

Ruptela Lua Scripting

Article about Ruptela scripting solution

1. What is it?

Ruptela devices run a built-in Lua 5.4 engine, letting you run custom logic directly on the device (edge computing) — reducing server load and latency.

2. Compatible Devices

Scripting works ONLY on:

  • Smart5 (all variants)

  • HCV5 Lite / Pro5 Lite

Other Ruptela devices (HCV5, Pro5, Eco5, Plug5, Trace5) do NOT support scripting.

3. Hardware I/O

I/O

Smart5

HCV5 Lite / Pro5 Lite

AIN

AIN1

AIN1, AIN2

DIN

DIN1, DIN2, DIN4, DIN5

DIN1, DIN2, DIN3

DOUT

DOUT1, DOUT2

DOUT1–DOUT4

All DOUTs must be set as "DOUT via script control" in Device Center.

4. Libraries

lua
-- Common (no require) pause(ms)          -- min 10ms, MANDATORY in loops getTime()          -- year,month,day,hour,min,sec,wday (UTC)  -- gpio gpio.getAin(n)             -- mV gpio.getDin(n)             -- 0 or 1 gpio.setDout(n, HIGH/LOW)  -- gps gps.status()               -- 3 = fix gps.coords()               -- lon,lat,alt,angle,sats,speed,hdop gps.distance(lon1,lat1,lon2,lat2)  -- meters gps.bSpeed()               -- km/h  -- io io.get(ioID)               -- returns size, value io.set(size, slot, value)  -- size 1/2/4/8, slot 0-9  -- sms sms.send(phone, msg)       -- phone no '+', msg max 160 sms.on("sent"/"error"/"recv", fn) sms.cmd("command")         -- run SMS command locally  -- timer local t = timer.new() t:start(ms); t:expired(); t:passed(); t:stop()

5. Critical Rules

  1. pause(ms) MANDATORY in every loop (min 10ms) — or device reboots.

  2. 10% CPU limit — max 100ms per 1 second.

  3. Signed values:

    • 1B: if v > 127 then v = v - 256 end

    • 2B: if v > 32767 then v = v - 65536 end

  4. Check error values: 255 (1B), 65535 (2B), 4294967295 (4B).

  5. io.set() needs integers: io.set(4, 0, math.floor(v))

  6. GPS format: decimal degrees × 10,000,000 → math.floor(54.7411 * 10000000)

  7. Phone: no '+' → "37012345678"

  8. Multipliers/offsets after read: rpm = raw * 0.25, temp = raw - 40

  9. IO 29 = vehicle battery | IO 30 = internal battery.

6. Script Template

lua
-- MY_SCRIPT.LUA local io = require("io") local sms = require("sms")  local PHONE = "37012345678" local THRESHOLD = 100  sms.on("sent", function(s) print("sent: "..s) end)  print("=== STARTED ===") while true do     -- logic here     pause(1000) end

7. Compile & Deploy

code
luac.exe -s -o script.lc script.lua

Upload .lc via Device Center. Monitor with IO 1141: 0=running, 2=runtime error, 3=syntax error, 4=out of memory, 255=off.

8. Common IO Parameters

IO

Description

Size

2–5

DIN1–DIN4

1B

22, 23

AIN1, AIN2

2B (mV)

29

Vehicle battery

2B (mV)

30

Internal battery

2B (mV)

49–51

Accelerometer X/Y/Z

1B (×0.05G)

65

Virtual odometer

4B (m)

176

GPS speed

1B (km/h)

197

CAN engine RPM

2B (×0.125)

210

CAN wheel speed

2B (×1/256 km/h)

251

Virtual ignition

1B (0/1)

1101–1140

Custom writable IOs

1B/2B/4B/8B


Want me to add ready-made script examples (geofence, speed alert, battery monitor) or an SMS commands section to this sheet?

Lua Code Review

Review

The file appears to be split into two blocks: a reference/documentation block and the actual script block. I'll focus on the runnable code.

Reference Block (top)

  • Info: Lines like pause(ms), getTime(), gpio.getAin(n), etc. are not valid runnable codems, n, HIGH/LOW are undefined globals. If this block is actually executed:

    • Critical: pause(ms)ms is nil, will error.

    • Critical: gpio.getAin(n) etc. — gpio, gps, timer not required, and n is nil → runtime errors / termination.

    • Assuming this is meant purely as a comment/reference cheat-sheet, it should be fully commented out or removed. As written, it is live code and will crash.

Actual Script Block (MY_SCRIPT.LUA)

  • Warning: io is required but never used. Minor, but wastes memory on an embedded device.

  • Info: sms required and used only for the sent callback — fine.

  • Info: PHONE ("37012345678") — valid international format, no +, ≤15 digits. Good.

  • Info: THRESHOLD = 100 declared but unused (placeholder — acceptable if logic will be added).

  • Good: while true do ... pause(1000) end — pause present, satisfies the mandatory-pause rule. 1000ms gives plenty of headroom for the 10% throttle limit.

  • Good: sms.on("sent", ...) callback signature is correct (fn(status)).

Summary

  • The script block is essentially correct (empty loop with proper pause).

  • The main problem is the reference block: if it is not commented out, it will terminate the script immediately with nil/undefined-variable errors. Comment it out or delete it.

  • Remove the unused require("io") unless you plan to use it.

Verdict: Script logic is fine; fix/comment the top reference block before running.

Did this answer your question?