advanced
Segway
IoT
integration

Segway IoT Integration

Complete technical guide to Segway native IoT integration - supported commands, telemetry data, lock/unlock operations, error codes, and configuration for Segway-powered vehicles.

Levy Fleets Team25 de diciembre de 202520 min read

Segway IoT Integration

Levy Fleets provides native integration with Segway IoT devices using the Segway TCP Telemetry Protocol. This guide covers the complete integration including supported commands, telemetry processing, error handling, and troubleshooting.

Protocol Version

Levy Fleets implements the Segway TCP Protocol v1.4.4, supporting 38+ commands across all operational categories.

Overview

Segway IoT devices communicate with Levy Fleets through a TCP-based protocol that provides:

  • Real-time GPS tracking with NMEA-format location data
  • Battery monitoring including dual-battery support
  • Lock/unlock control with acknowledgment
  • Heartbeat monitoring for connectivity status
  • Comprehensive vehicle status including speed, odometer, and temperature
  • Error and alarm handling with severity classification
  • OTA firmware updates via HTTP or FTP
  • Mechanical lock support for cable/wheel locks

Device Configuration

Server Settings

Configure your Segway device to communicate with Levy Fleets:

SettingValue
Server IP/DomainYour Levy Fleets IoT endpoint
PortAs provided during setup
ProtocolTCP

Authentication

Segway devices authenticate via API key. Ensure your deployment includes the correct API key in the x-api-key header for all communications.

Device Identification

Devices are identified by IMEI. The message format includes the device IMEI in the header:

*HBCR,NB,{IMEI},{COMMAND},...#

Supported Commands

Core Operations

CommandDescriptionDirection
R0Operation key exchangeDevice → Server
L0Unlock acknowledgmentDevice → Server
L1Lock acknowledgmentDevice → Server
H0Heartbeat with statusDevice → Server
Q0Device check-inDevice → Server
Q1Lock key queryDevice → Server

Lock/Unlock Protocol

The Segway lock/unlock process involves a key exchange:

1

Request Key (R0)

Server requests an operation key from the device. Device responds with operation code, key, user ID, and sequence number.

2

Send Command

Server sends lock (L1) or unlock (L0) command with the key

3

Receive Acknowledgment

Device executes the command and sends acknowledgment with status code

Acknowledgment Status Codes

CodeStatusDescription
0SuccessCommand executed successfully
1FailureGeneral failure
2Key InvalidAuthentication key rejected
3Ride In ProgressCannot lock during active ride
4ECU FailedVehicle controller error
5Strategy DeclinedBusiness logic prevented operation

Vehicle Status (S-Series)

CommandDescription
S1Speed limit settings
S2Power control response
S4Scooter settings block 2 (cruise, buttons, speed limits)
S5Device settings (intervals, accelerometer)
S6Real-time status (battery, speed, mileage, lock)
S7Scooter settings block 1 (lights, speed mode)
S8Extended status (temperatures, dual battery, error codes)
S9Additional settings (auto-lock, idle alert)
S20Ambient light settings

Location & Tracking (D-Series)

CommandDescription
D0GPS location report (NMEA format)
D1Tracking configuration
D2Tracking cooldown settings

D0 GPS Format

The D0 command uses NMEA-like format:

*HBCR,NB,{IMEI},D0,,{TIME},A,{LAT},{LAT_DIR},{LON},{LON_DIR},{SPEED},{COURSE},{DATE},{ALT},...#
  • TIME: HHMMSS.sss
  • A/V: Valid/Invalid fix
  • LAT: DDMM.MMMM (degrees and decimal minutes)
  • LAT_DIR: N/S
  • LON: DDDMM.MMMM
  • LON_DIR: E/W
  • SPEED: Knots (converted to km/h)
  • DATE: DDMMYY

Network Configuration (N-Series)

CommandDescription
N2MAC/IMEI configuration
N3Network parameters
N7APN settings
N8Server domain/IP configuration

Device Features (Various)

CommandDescription
V0Voice prompt acknowledgment
V1Voice configuration
G0Firmware version information
E0Error codes/alarms
K0BLE key management
P2Complete device status (30+ fields)

Mechanical Lock (C-Series)

CommandDescription
C0Cable lock battery status
C1Wireless charging status
C2Mechanical lock status
C3Mechanical lock control response
C4Mechanical lock parameters

Supported lock types:

  • Type 1: Cable lock
  • Type 6: Wheel lock
  • Type 8: Helmet/cable combo lock

OTA Updates (U-Series)

CommandDescription
U5HTTP OTA update status
U6FTP OTA update status

Update status codes:

  • 0: Started
  • 1: Downloading/Connecting
  • 2: Download complete
  • 3: Installing
  • 4: Success
  • 5: Failed
  • 6: Cancelled

Extended Reports

CommandDescription
JR5Charging data report (voltage, current)

Telemetry Processing

Heartbeat (H0)

The H0 heartbeat is the primary keep-alive signal and includes:

  • Lock Status: 0 (unlocked) or 1 (locked)
  • IoT Voltage: Raw voltage in centivolt units
  • Signal Strength: Cellular signal level
  • Battery Percent: Vehicle battery (0-100%)
  • Charging State: 0 (not charging) or 1 (charging)

The system calculates IoT battery percentage from voltage:

IoT Battery % = ((voltage_mv - 3200) / (4200 - 3200)) * 100

Status Report (S6)

Provides comprehensive real-time status:

FieldDescription
Battery PercentMain battery level
Speed ModeCurrent speed mode setting
Speed (km/h)Current vehicle speed
Total MileageLifetime odometer in meters
Remaining RangeEstimated range in 10-meter units
Ride DurationCurrent ride time in seconds
Lock FlagLock state
Charging StateCharging indicator
Battery PluggedBattery connected indicator

Extended Status (S8)

Detailed vehicle diagnostics:

FieldDescription
Charging FlagCurrently charging (0/1)
Controller VoltageECU voltage
Battery 1 CyclesPrimary battery charge cycles
Battery 1 SOCPrimary battery state of charge
Battery 2 SOCSecondary battery (if dual-battery)
Battery 1/2 Internal TempBattery pack temperatures
Battery 1/2 External TempAmbient battery temperatures
Error CodeCurrent ECU error code
Throttle PercentThrottle position
Brake StatusBrake engaged indicator

Complete Status (P2)

The P2 command returns 30+ fields for complete vehicle diagnostics:

  • Device model, firmware, hardware versions
  • Battery: percent, voltage, current, temperature
  • Motor and controller temperatures
  • Speed: current, average, max
  • Mileage: total and trip
  • GPS: coordinates, speed, signal
  • GSM signal strength
  • Accelerometer data (X, Y, Z)

Error Code Handling

Error Code Translation

Segway E0 error codes are automatically translated to human-readable messages. The system:

  1. Parses the error codes from the E0 message
  2. Translates each code using the Segway error code mapping
  3. Determines severity level (warning, error, critical)
  4. Formats a user-friendly message
  5. Updates the vehicle record with error status

Severity Levels

LevelDescriptionImpact
WarningMinor issue, vehicle operationalLogged for review
ErrorSignificant issue, may affect operationAlert generated
CriticalMajor fault, vehicle should not be usedRide blocked, immediate alert

Complete Alarm Code Reference

Levy Fleets translates Segway alarm codes into actionable alerts. Below is the complete reference:

Security Alarms

CodeAlarmSeverityUser Message
1Illegal moving alarmWarningUnauthorized movement detected
3Illegal disassembling alarmCriticalTampering detected
22Vehicle stationary while unlockedWarningVehicle stationary while unlocked

Safety Alarms

CodeAlarmSeverityUser Message
2Falling alarmErrorVehicle has fallen over
4Falling alarm (confirmed)ErrorVehicle fall confirmed
13Brakeline faultCriticalBrake line fault - do not ride
14Tandem ridingWarningMultiple riders detected
21Tyre burnt eventCriticalTire overheating - stop immediately

Battery Alarms

CodeAlarmSeverityUser Message
7Abnormal battery functionErrorBattery function abnormal
12Low batteryWarningBattery low - please charge
30BMS passcode format invalidErrorBattery passcode format error
31BMS passcode verified wrongErrorBattery passcode incorrect
41Cell voltage difference (high/high)ErrorBattery cell imbalance
42Cell voltage difference (low/small)ErrorBattery cell imbalance
43Cell voltage difference (high/high current)ErrorBattery cell imbalance
44Cell voltage difference (low/high current)ErrorBattery cell imbalance
45Cell voltage too highErrorBattery cell voltage high
46Cell temp difference abnormalWarningBattery temperature imbalance
47MOS temp too highCriticalBattery electronics overheating
48Cell temp high when lockedWarningBattery temperature high while parked
49Cell temp high when unlockedCriticalBattery overheating - stop riding

Communication Alarms

CodeAlarmSeverityUser Message
8Helmet lock communication malfunctionWarningHelmet lock communication error
9Cable lock communication malfunctionWarningCable lock communication error
15AI communication failWarningAI box communication error

Hardware Alarms

CodeAlarmSeverityUser Message
16Throttle hall sensor abnormalCriticalThrottle sensor fault - do not ride
17Moment axis abnormalErrorTorque sensor abnormal
18ECU high temperatureCriticalController overheating - stop riding
99ECU Alarm detectedErrorController alarm - check vehicle

Alarm Categories

The system categorizes alarms into the following groups:

CategoryDescriptionTypical Response
SecurityTheft/tampering detectionAlert and track
SafetyRider safety concernsMay block ride
BatteryBattery health issuesSchedule maintenance
CommunicationLock/accessory connectivityRetry/investigate
HardwareComponent faultsService required
AIAI box communicationCheck connectivity

Auto-Dismissible Alarms

Some alarms (like falling detection) are automatically dismissed when the condition clears. Non-auto-dismissible alarms (like battery issues) require manual acknowledgment or physical inspection.

Email Notifications

For error codes with severity "error" or "critical":

  1. System generates an email notification
  2. Email is sent to configured fleet managers
  3. Includes: vehicle ID, IMEI, error code, description, severity
  4. Sent asynchronously to not block telemetry processing

Critical Errors

Vehicles with critical errors have ride_precluded_by_error set to true, preventing new rides from starting until the issue is resolved.

Location Processing

GPS Data Conversion

D0 messages contain NMEA-format coordinates that are converted to decimal degrees:

// Convert DDMM.MMMM to decimal degrees
degrees = floor(coordinate / 100)
minutes = coordinate - (degrees * 100)
decimal = degrees + (minutes / 60)
// Apply direction (negative for S/W)

Ride Location History

During active rides, D0 messages:

  1. Extract GPS coordinates and speed
  2. Insert into ride_locations table
  3. Include altitude and moving status
  4. Trigger zone enforcement check
  5. Update ride statistics

Zone Enforcement

After processing D0 location during an active ride:

  1. Check if coordinates fall within any defined zones
  2. Apply speed limits for slow zones
  3. Disable throttle for no-go zones
  4. Update ride statistics RPC

Vehicle Updates

Fields Updated by Telemetry

SourceUpdated Fields
H0battery_level, lock_status, charging, iot_battery_pct, iot_last_update
S6battery_level, speed, odometer_m, lock_status, ignition_status
S8battery_level, is_charging, last_error_code, has_error
D0latitude, longitude, last_location_update, speed
G0firmware_version, controller_version
E0has_error, last_error_codes, error_message, ride_precluded_by_error
P2Comprehensive update (20+ fields)

Timestamps

Every telemetry update sets:

  • updated_at - General update timestamp
  • iot_last_update - Last IoT communication
  • last_signal_at - Last signal received

Location updates also set:

  • last_location_update - Last GPS fix

Sending Commands

IoT Password

Configure the Segway password in Settings:

Settings > Vehicles > IoT Passwords > Segway

Default password: 0000

Available Dashboard Commands

CommandAction
LockSend L1 lock command
UnlockSend L0 unlock command
SoundPlay alert sound
LocateFlash lights

Command Sequence

For lock/unlock:

  1. Dashboard sends R0 (request key)
  2. Device responds with operation key
  3. Dashboard sends L0/L1 with key
  4. Device executes and sends acknowledgment
  5. Dashboard updates vehicle status

Configuration Reference

Device Settings (S5)

ParameterDescription
Accelerometer SensitivityMotion detection threshold
Upload SwitchEnable/disable data upload
Heartbeat IntervalSeconds between H0 messages
Riding Upload IntervalGPS interval when unlocked/riding
Unlocked Upload IntervalGPS interval when unlocked/idle
Power On Upload IntervalGPS interval on power on

Tracking Settings (D1/D2)

ParameterDescription
Unlocked IntervalGPS reporting when unlocked
Locked Still IntervalGPS when locked, not moving
Locked Moving IntervalGPS when locked but moving
Low Battery Still IntervalGPS when low battery, still
Low Battery Moving IntervalGPS when low battery, moving
Movement CooldownSeconds before movement detected
Low Battery ThresholdBattery % for low-battery mode

Speed Settings (S1/S4)

ParameterDescription
Low Speed LimitMode 1 max speed (km/h)
Medium Speed LimitMode 2 max speed (km/h)
High Speed LimitMode 3 max speed (km/h)
Speed Unitkm/h or mph
Cruise ControlEnable/disable
Push AssistEnable/disable

Troubleshooting

Device Not Connecting

Symptoms: No heartbeats received, device offline

Solutions:

  1. Verify server IP and port configuration
  2. Check cellular connectivity and SIM activation
  3. Confirm APN settings match carrier requirements
  4. Power cycle the vehicle
  5. Check for firewall blocking TCP connections

Lock Commands Failing

Symptoms: Lock/unlock returns error status

Check status code:

  • Code 2 (Key Invalid): Password mismatch - verify IoT password in Settings
  • Code 3 (Ride In Progress): End the current ride first
  • Code 4 (ECU Failed): Vehicle controller issue - check E0 errors
  • Code 5 (Strategy Declined): Business logic block - check vehicle status

GPS Not Updating

Symptoms: Location stays at same point or shows (0,0)

Solutions:

  1. Check for "V" (invalid) fix indicator in D0 messages
  2. Ensure vehicle has clear sky view
  3. Wait for GPS to acquire satellites (up to 5 min cold start)
  4. Verify D1 tracking intervals aren't too long
  5. Check if device is in low-power mode

Battery Reading Incorrect

Symptoms: Battery shows 0%, wrong value, or doesn't change

Solutions:

  1. For dual-battery vehicles, check both SOC values in S8
  2. Verify BMS communication (check battery cycle counts)
  3. Some readings require vehicle power on (not just IoT)
  4. Check if battery is properly connected

Error Codes Appearing

Symptoms: E0 messages showing error codes

Actions:

  1. Note the error code number
  2. Check email notifications for translation
  3. Review vehicle record for error_message field
  4. Critical errors require physical inspection
  5. Clear errors by power cycling if appropriate

Data Storage

Telemetry Records

All Segway messages are stored with:

  • vehicle_uuid - Associated vehicle
  • vehicle_number - Human-readable ID
  • imei - Device identifier
  • raw_payload - Complete message as JSON
  • message_type - Command type (e.g., "H0_HEARTBEAT")
  • timestamp - Message timestamp
  • idempotency_key - Deduplication key

Idempotency

Each telemetry record includes a generated idempotency key:

{vehicleId}-{imei}-{timestamp}-{messageType}

This prevents duplicate entries from retried messages.

API Reference

Endpoint

POST /api/iot/segway

Headers

x-api-key: your-iot-api-key
Content-Type: application/json

Request Body

{
  "imei": "867648045123456",
  "cmd": "H0",
  "raw": "*HBCR,NB,867648045123456,H0,1,420,25,85,0#",
  "timestamp": "2025-12-25T12:00:00Z",
  "parsed": {}
}

Response

{
  "success": true,
  "vehicle_number": "LV-001",
  "ride_number": null,
  "command": "H0",
  "cmd": "H0"
}

Health Check

GET /api/iot/segway

Returns:

{
  "service": "Segway TCP Telemetry Ingestion",
  "status": "healthy",
  "timestamp": "2025-12-25T12:00:00Z",
  "supported_commands": ["R0", "L0", "L1", "H0", ...]
}

Technical Support

For Segway integration issues, contact support@levyelectric.com with:

  • Device IMEI
  • Raw message data (if available)
  • Timestamp of the issue
  • Expected vs. actual behavior