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:
| Setting | Value |
|---|---|
| Server IP/Domain | Your Levy Fleets IoT endpoint |
| Port | As provided during setup |
| Protocol | TCP |
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
| Command | Description | Direction |
|---|---|---|
| R0 | Operation key exchange | Device → Server |
| L0 | Unlock acknowledgment | Device → Server |
| L1 | Lock acknowledgment | Device → Server |
| H0 | Heartbeat with status | Device → Server |
| Q0 | Device check-in | Device → Server |
| Q1 | Lock key query | Device → Server |
Lock/Unlock Protocol
The Segway lock/unlock process involves a key exchange:
Request Key (R0)
Server requests an operation key from the device. Device responds with operation code, key, user ID, and sequence number.
Send Command
Server sends lock (L1) or unlock (L0) command with the key
Receive Acknowledgment
Device executes the command and sends acknowledgment with status code
Acknowledgment Status Codes
| Code | Status | Description |
|---|---|---|
| 0 | Success | Command executed successfully |
| 1 | Failure | General failure |
| 2 | Key Invalid | Authentication key rejected |
| 3 | Ride In Progress | Cannot lock during active ride |
| 4 | ECU Failed | Vehicle controller error |
| 5 | Strategy Declined | Business logic prevented operation |
Vehicle Status (S-Series)
| Command | Description |
|---|---|
| S1 | Speed limit settings |
| S2 | Power control response |
| S4 | Scooter settings block 2 (cruise, buttons, speed limits) |
| S5 | Device settings (intervals, accelerometer) |
| S6 | Real-time status (battery, speed, mileage, lock) |
| S7 | Scooter settings block 1 (lights, speed mode) |
| S8 | Extended status (temperatures, dual battery, error codes) |
| S9 | Additional settings (auto-lock, idle alert) |
| S20 | Ambient light settings |
Location & Tracking (D-Series)
| Command | Description |
|---|---|
| D0 | GPS location report (NMEA format) |
| D1 | Tracking configuration |
| D2 | Tracking 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)
| Command | Description |
|---|---|
| N2 | MAC/IMEI configuration |
| N3 | Network parameters |
| N7 | APN settings |
| N8 | Server domain/IP configuration |
Device Features (Various)
| Command | Description |
|---|---|
| V0 | Voice prompt acknowledgment |
| V1 | Voice configuration |
| G0 | Firmware version information |
| E0 | Error codes/alarms |
| K0 | BLE key management |
| P2 | Complete device status (30+ fields) |
Mechanical Lock (C-Series)
| Command | Description |
|---|---|
| C0 | Cable lock battery status |
| C1 | Wireless charging status |
| C2 | Mechanical lock status |
| C3 | Mechanical lock control response |
| C4 | Mechanical lock parameters |
Supported lock types:
- Type 1: Cable lock
- Type 6: Wheel lock
- Type 8: Helmet/cable combo lock
OTA Updates (U-Series)
| Command | Description |
|---|---|
| U5 | HTTP OTA update status |
| U6 | FTP OTA update status |
Update status codes:
- 0: Started
- 1: Downloading/Connecting
- 2: Download complete
- 3: Installing
- 4: Success
- 5: Failed
- 6: Cancelled
Extended Reports
| Command | Description |
|---|---|
| JR5 | Charging 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:
| Field | Description |
|---|---|
| Battery Percent | Main battery level |
| Speed Mode | Current speed mode setting |
| Speed (km/h) | Current vehicle speed |
| Total Mileage | Lifetime odometer in meters |
| Remaining Range | Estimated range in 10-meter units |
| Ride Duration | Current ride time in seconds |
| Lock Flag | Lock state |
| Charging State | Charging indicator |
| Battery Plugged | Battery connected indicator |
Extended Status (S8)
Detailed vehicle diagnostics:
| Field | Description |
|---|---|
| Charging Flag | Currently charging (0/1) |
| Controller Voltage | ECU voltage |
| Battery 1 Cycles | Primary battery charge cycles |
| Battery 1 SOC | Primary battery state of charge |
| Battery 2 SOC | Secondary battery (if dual-battery) |
| Battery 1/2 Internal Temp | Battery pack temperatures |
| Battery 1/2 External Temp | Ambient battery temperatures |
| Error Code | Current ECU error code |
| Throttle Percent | Throttle position |
| Brake Status | Brake 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:
- Parses the error codes from the E0 message
- Translates each code using the Segway error code mapping
- Determines severity level (warning, error, critical)
- Formats a user-friendly message
- Updates the vehicle record with error status
Severity Levels
| Level | Description | Impact |
|---|---|---|
| Warning | Minor issue, vehicle operational | Logged for review |
| Error | Significant issue, may affect operation | Alert generated |
| Critical | Major fault, vehicle should not be used | Ride blocked, immediate alert |
Complete Alarm Code Reference
Levy Fleets translates Segway alarm codes into actionable alerts. Below is the complete reference:
Security Alarms
| Code | Alarm | Severity | User Message |
|---|---|---|---|
| 1 | Illegal moving alarm | Warning | Unauthorized movement detected |
| 3 | Illegal disassembling alarm | Critical | Tampering detected |
| 22 | Vehicle stationary while unlocked | Warning | Vehicle stationary while unlocked |
Safety Alarms
| Code | Alarm | Severity | User Message |
|---|---|---|---|
| 2 | Falling alarm | Error | Vehicle has fallen over |
| 4 | Falling alarm (confirmed) | Error | Vehicle fall confirmed |
| 13 | Brakeline fault | Critical | Brake line fault - do not ride |
| 14 | Tandem riding | Warning | Multiple riders detected |
| 21 | Tyre burnt event | Critical | Tire overheating - stop immediately |
Battery Alarms
| Code | Alarm | Severity | User Message |
|---|---|---|---|
| 7 | Abnormal battery function | Error | Battery function abnormal |
| 12 | Low battery | Warning | Battery low - please charge |
| 30 | BMS passcode format invalid | Error | Battery passcode format error |
| 31 | BMS passcode verified wrong | Error | Battery passcode incorrect |
| 41 | Cell voltage difference (high/high) | Error | Battery cell imbalance |
| 42 | Cell voltage difference (low/small) | Error | Battery cell imbalance |
| 43 | Cell voltage difference (high/high current) | Error | Battery cell imbalance |
| 44 | Cell voltage difference (low/high current) | Error | Battery cell imbalance |
| 45 | Cell voltage too high | Error | Battery cell voltage high |
| 46 | Cell temp difference abnormal | Warning | Battery temperature imbalance |
| 47 | MOS temp too high | Critical | Battery electronics overheating |
| 48 | Cell temp high when locked | Warning | Battery temperature high while parked |
| 49 | Cell temp high when unlocked | Critical | Battery overheating - stop riding |
Communication Alarms
| Code | Alarm | Severity | User Message |
|---|---|---|---|
| 8 | Helmet lock communication malfunction | Warning | Helmet lock communication error |
| 9 | Cable lock communication malfunction | Warning | Cable lock communication error |
| 15 | AI communication fail | Warning | AI box communication error |
Hardware Alarms
| Code | Alarm | Severity | User Message |
|---|---|---|---|
| 16 | Throttle hall sensor abnormal | Critical | Throttle sensor fault - do not ride |
| 17 | Moment axis abnormal | Error | Torque sensor abnormal |
| 18 | ECU high temperature | Critical | Controller overheating - stop riding |
| 99 | ECU Alarm detected | Error | Controller alarm - check vehicle |
Alarm Categories
The system categorizes alarms into the following groups:
| Category | Description | Typical Response |
|---|---|---|
| Security | Theft/tampering detection | Alert and track |
| Safety | Rider safety concerns | May block ride |
| Battery | Battery health issues | Schedule maintenance |
| Communication | Lock/accessory connectivity | Retry/investigate |
| Hardware | Component faults | Service required |
| AI | AI box communication | Check 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":
- System generates an email notification
- Email is sent to configured fleet managers
- Includes: vehicle ID, IMEI, error code, description, severity
- 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:
- Extract GPS coordinates and speed
- Insert into
ride_locationstable - Include altitude and moving status
- Trigger zone enforcement check
- Update ride statistics
Zone Enforcement
After processing D0 location during an active ride:
- Check if coordinates fall within any defined zones
- Apply speed limits for slow zones
- Disable throttle for no-go zones
- Update ride statistics RPC
Vehicle Updates
Fields Updated by Telemetry
| Source | Updated Fields |
|---|---|
| H0 | battery_level, lock_status, charging, iot_battery_pct, iot_last_update |
| S6 | battery_level, speed, odometer_m, lock_status, ignition_status |
| S8 | battery_level, is_charging, last_error_code, has_error |
| D0 | latitude, longitude, last_location_update, speed |
| G0 | firmware_version, controller_version |
| E0 | has_error, last_error_codes, error_message, ride_precluded_by_error |
| P2 | Comprehensive update (20+ fields) |
Timestamps
Every telemetry update sets:
updated_at- General update timestampiot_last_update- Last IoT communicationlast_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
| Command | Action |
|---|---|
| Lock | Send L1 lock command |
| Unlock | Send L0 unlock command |
| Sound | Play alert sound |
| Locate | Flash lights |
Command Sequence
For lock/unlock:
- Dashboard sends R0 (request key)
- Device responds with operation key
- Dashboard sends L0/L1 with key
- Device executes and sends acknowledgment
- Dashboard updates vehicle status
Configuration Reference
Device Settings (S5)
| Parameter | Description |
|---|---|
| Accelerometer Sensitivity | Motion detection threshold |
| Upload Switch | Enable/disable data upload |
| Heartbeat Interval | Seconds between H0 messages |
| Riding Upload Interval | GPS interval when unlocked/riding |
| Unlocked Upload Interval | GPS interval when unlocked/idle |
| Power On Upload Interval | GPS interval on power on |
Tracking Settings (D1/D2)
| Parameter | Description |
|---|---|
| Unlocked Interval | GPS reporting when unlocked |
| Locked Still Interval | GPS when locked, not moving |
| Locked Moving Interval | GPS when locked but moving |
| Low Battery Still Interval | GPS when low battery, still |
| Low Battery Moving Interval | GPS when low battery, moving |
| Movement Cooldown | Seconds before movement detected |
| Low Battery Threshold | Battery % for low-battery mode |
Speed Settings (S1/S4)
| Parameter | Description |
|---|---|
| Low Speed Limit | Mode 1 max speed (km/h) |
| Medium Speed Limit | Mode 2 max speed (km/h) |
| High Speed Limit | Mode 3 max speed (km/h) |
| Speed Unit | km/h or mph |
| Cruise Control | Enable/disable |
| Push Assist | Enable/disable |
Troubleshooting
Device Not Connecting
Symptoms: No heartbeats received, device offline
Solutions:
- Verify server IP and port configuration
- Check cellular connectivity and SIM activation
- Confirm APN settings match carrier requirements
- Power cycle the vehicle
- 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:
- Check for "V" (invalid) fix indicator in D0 messages
- Ensure vehicle has clear sky view
- Wait for GPS to acquire satellites (up to 5 min cold start)
- Verify D1 tracking intervals aren't too long
- Check if device is in low-power mode
Battery Reading Incorrect
Symptoms: Battery shows 0%, wrong value, or doesn't change
Solutions:
- For dual-battery vehicles, check both SOC values in S8
- Verify BMS communication (check battery cycle counts)
- Some readings require vehicle power on (not just IoT)
- Check if battery is properly connected
Error Codes Appearing
Symptoms: E0 messages showing error codes
Actions:
- Note the error code number
- Check email notifications for translation
- Review vehicle record for
error_messagefield - Critical errors require physical inspection
- Clear errors by power cycling if appropriate
Data Storage
Telemetry Records
All Segway messages are stored with:
vehicle_uuid- Associated vehiclevehicle_number- Human-readable IDimei- Device identifierraw_payload- Complete message as JSONmessage_type- Command type (e.g., "H0_HEARTBEAT")timestamp- Message timestampidempotency_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