Redis API Reference

All Librescoot services communicate through Redis on the MDB. Below are the state hashes, command queues, and pub/sub channels.

Connection
Redis runs on the MDB at 192.168.7.1:6379. The DBC connects over USB Ethernet. From a connected machine:
redis-cli -h 192.168.7.1
# or via SSH tunnel:
ssh -L 6379:localhost:6379 root@<mdb-ip>
redis-ipc library
Go services use the redis-ipc library which wraps go-redis with helpers for hash publishing, queue processing, and pub/sub. Read its README for the patterns used across all services.

State Hashes

State is stored in Redis hashes. Services update fields with HSET and publish change notifications on channels of the same name.

vehicle

redis-cli -h 192.168.7.1 HGETALL vehicle
FieldValuesDescription
statestand-by / ready-to-drive / parked / booting / shutting-down / hibernating / updatingVehicle operating state
handlebar:positionon-place / off-placeHandlebar position sensor
handlebar:lock-sensorlocked / unlockedHandlebar lock state
seatbox:lockopen / closedSeatbox lock state
seatbox:buttonon / offSeat open button
kickstandup / downSide stand position
brake:left / brake:righton / offBrake lever states
blinker:switchleft / right / both / offBlinker switch position
blinker:stateon / offBlinker currently active
main-poweron / offMain power state
horn:buttonon / offHorn button

battery:0 / battery:1

redis-cli -h 192.168.7.1 HGETALL battery:0
FieldTypeDescription
presenttrue / falseBattery presence
statestringBattery state
chargeinteger (%)Charge level
voltageinteger (mV)Battery voltage
currentinteger (mA)Battery current
temperature:0temperature:3integer (°C)Temperature sensors
state-of-healthinteger (%)Battery health
cycle-countintegerCharge cycles
serial-numberstringBattery serial
fw-versionstringBMS firmware version

engine-ecu

redis-cli -h 192.168.7.1 HGETALL engine-ecu
FieldTypeDescription
speedinteger (km/h)Vehicle speed
rpmintegerMotor RPM
odometerinteger (m)Total distance
motor:voltageinteger (mV)Motor voltage
motor:currentinteger (mA)Motor current
temperatureinteger (°C)ECU temperature
throttleon / offThrottle active
kerson / offRegenerative braking active
kers-reason-offstringWhy KERS is off (none / cold / hot)
gearintegerGear position
fw-versionhex stringECU firmware version

internet

FieldDescription
statusConnection status (connected / disconnected)
access-techAccess technology (e.g. LTE)
signal-qualitySignal strength 0–100
ip-addressCurrent IP address
modem-stateModem power state

gps

FieldDescription
stateoff / searching / fix-established / error
latitude / longitudeCurrent position (6 decimal places)
altitudeAltitude in meters
speedGPS speed
courseHeading in degrees
timestampGPS timestamp (ISO format)

alarm

FieldValues
statusdisabled / disarmed / delay-armed / armed / level-1-triggered / level-2-triggered / seatbox-access. motion-service watches this and reactively re-derives the BMX055 chip profile.

motion

Written by motion-service (BMX055 owner). Heading fields refresh from each magnetometer sample (5 Hz).

FieldDescription
current-profileidle / armed-awake / armed-hibernation / level1 / waiting — chip configuration in registers
heading0–359 degrees, integer, vehicle NED frame
heading-degTilt-compensated, EMA-smoothed
heading-accuracyHeuristic 1-σ degrees
heading-tiltVehicle tilt angle from level
initialized / streaming / polling-rate-hzService status
last-interrupt-timestampUnix-ms of last motion-engine fire
wake-causeSet once on motion-service startup if INT_STATUS had a latched bit (wake-from-hibernation indicator). Read + deleted by alarm-service.

Pub/sub channels published by motion-service:

  • motion:sensors — 10 Hz JSON IMU stream {accel, gyro, mag}
  • motion:heading — 5 Hz JSON HeadingReading with raw + EMA-smoothed angles, accuracy, tilt
  • motion:interrupt — JSON {type, timestamp, engine} motion edges; type:"wake-hibernation" for the post-resume sentinel
  • motion:ready — fired once on startup
  • motion:rpc — request channel for synchronous methods (prepare-hibernation, get-calibration, clear-latch, soft-reset)

settings

Persistent configuration managed by settings-service. All fields are readable/writable via lsc settings get/set. Notable keys:

KeyDescription
alarm.enabledtrue/false, alarm system on/off
alarm.honktrue/false, horn during alarm
alarm.durationAlarm duration in seconds
updates.mdb.channelOTA channel: testing / nightly / stable
updates.mdb.methodfull or delta
dashboard.valhalla-urlRouting engine endpoint
dashboard.map.typeonline / offline
scooter.auto-standby-secondsAuto-lock timeout (0 = disabled)
pm.hibernation-timerDelay-based hibernation timeout in seconds (0 = disabled; minimum 300 s — values 1–299 are clamped up). Default 259200 (3 days). Timer runs whenever the vehicle is in any idle state and resets on activity.
pm.default-stateIdle-time target power state: run (stay awake) or suspend (auto-sleep after the pre-suspend delay)
pm.scheduled-hibernate-enabledtrue/false — arms the cron-based hibernation schedule. Requires a valid pm.scheduled-hibernate-cron, a non-zero pm.scheduled-hibernate-duration, and a time-synced wall clock before any fires are dispatched.
pm.scheduled-hibernate-cron5-field cron expression (minute hour day-of-month month day-of-week) defining when scheduled hibernation fires. Empty disables. Fires are rate-limited to one every 15 min — pathological expressions like * * * * * or */5 * * * * can’t put the scooter into a hibernate loop. Example: 0 22 * * * (every day at 22:00).
pm.scheduled-hibernate-durationWake-by duration applied at fire time as a Go duration string (e.g. 8h, 30m). The system wakes at fire-time + duration (wall-clock target). If the vehicle isn’t in stand-by at fire time, the request is deferred until the next stand-by transition; the wake-by target is preserved.
pm.wake-timer-max-secondsSafety cap on the wake-timer duration sent to the nRF52 for any hibernate-for request (ad-hoc or scheduled). Requests above this are clamped. Minimum 60, maximum/default 604800 (1 week).
pm.wake-timer-ack-timeoutHow long pm-service waits for the nRF52 to confirm a wake-timer was armed before aborting the hibernation. Go duration string, minimum 1 s, default 10s.

ota

FieldDescription
status:mdb / status:dbcidle / downloading / installing / rebooting / error
download-progress:mdbDownload progress 0–100
update-version:mdbTarget version string
error-message:mdbError description if status is error

version:mdb / version:dbc

Written by version-service from /etc/os-release. Contains fields like version_id, build_id, id.

Command Queues

Services accept commands via Redis lists. Send with LPUSH; services consume with BRPOP.

QueueCommands
scooter:statelock, unlock, lock-hibernate
scooter:seatboxopen
scooter:powerrun, suspend, hibernate, hibernate-manual, reboot
scooter:blinkerleft, right, both, off
scooter:hornon, off
scooter:alarmenable, disable, start:<seconds>, stop
scooter:modemenable, disable, gps:enable, gps:disable
scooter:updatecheck-now
scooter:bluetoothadvertising-start-with-whitelisting, advertising-restart-no-whitelisting, advertising-stop, delete-all-bonds

Example:

redis-cli -h 192.168.7.1 LPUSH scooter:state unlock
redis-cli -h 192.168.7.1 LPUSH scooter:alarm start:30

Pub/Sub

When a service updates a hash field, it publishes the changed field name to a channel with the same name as the hash. Consumers subscribe and re-read only the changed field.

# Subscribe to vehicle state changes
redis-cli -h 192.168.7.1 SUBSCRIBE vehicle

# Subscribe to battery updates
redis-cli -h 192.168.7.1 SUBSCRIBE battery:0 battery:1

The published message payload is the field name that changed (e.g. "state", "charge"). Recipients call HGET <hash> <field> to get the new value.

This pattern is implemented in the redis-ipc library.

← Build Guide