IoT Device Import
When adding multiple IoT devices to your fleet, the CSV import feature saves significant time compared to adding devices individually. This guide explains how to prepare your CSV file and successfully import devices in bulk.
When to Use CSV Import
CSV import is recommended when adding 5 or more devices at once. For 1-4 devices, using the individual "Add Device" form may be faster.
Import Process Overview
The IoT device import process follows these steps:
- Prepare your CSV file with device data
- Upload the file through the IoT Devices page
- System validates the data and shows any errors
- Data is staged in a temporary import table
- Import function executes to create/update device records
- Vehicle identity cache is cleared to ensure proper linking
CSV File Requirements
File Format
- Format: CSV (Comma-Separated Values)
- Delimiter: Semicolon (
;) - NOT comma - Encoding: UTF-8 recommended
- Headers: First row must contain column headers
- Quotes: Use double quotes (
") for text fields containing special characters
Semicolon Delimiter
Levy Fleets uses semicolons (;) as the CSV delimiter, not commas. This is to avoid conflicts with IMEI numbers and other data that may contain commas. Configure your spreadsheet software accordingly when exporting.
Required Columns
| Column Name | Description | Example |
|---|---|---|
imei | 15-digit device identifier (required, unique) | 867648045123456 |
Optional Columns
| Column Name | Description | Example |
|---|---|---|
iccid | SIM card identifier (19-20 digits) | 8901260123456789012 |
subaccount_id | UUID of the subaccount | a1b2c3d4-e5f6-... |
iot_model | Device model number | GL530M |
iot_type | Device manufacturer type | queclink |
owner_name | Device owner/manager name | John Smith |
owner_email | Owner contact email | john@example.com |
notes | Additional notes about the device | Installed 2025-01 |
Valid IoT Types
The iot_type field must be one of these values:
| Value | Description |
|---|---|
teltonika | Teltonika FMB/FMC devices |
omni | Omni IoT devices |
okai | OKAI ZK Series devices |
queclink | Queclink GL530 devices |
particle | Particle Electron/Boron |
segway | Native Segway IoT |
zimo | ZIMO MQTT devices |
other | Other/unspecified type |
Preparing Your CSV File
Using Microsoft Excel
- Open a new Excel workbook
- Enter column headers in row 1
- Add your device data starting from row 2
- Save As and choose "CSV (Comma delimited)"
- Open the saved CSV file in a text editor
- Find and Replace all commas (
,) with semicolons (;) - Save the file
Using Google Sheets
- Create a new spreadsheet
- Enter column headers in row 1
- Add your device data starting from row 2
- Go to File > Download > Comma-separated values (.csv)
- Open the downloaded file in a text editor
- Find and Replace all commas (
,) with semicolons (;) - Save the file
Download CSV Template
Instead of creating a file from scratch, you can download a pre-formatted template:
- Go to IoT Devices in the sidebar
- Click Import to open the import dialog
- Click Download Template
- The template CSV includes all column headers and example data
- Replace the example data with your actual device information
- Save and upload the modified file
Template Benefits
Using the template ensures correct column names and formatting, reducing import errors.
Example CSV Content
imei;iccid;iot_type;iot_model;owner_name;notes
867648045123456;8901260123456789012;queclink;GL530M;Operations Team;Fleet A
867648045123457;8901260123456789013;queclink;GL530M;Operations Team;Fleet A
867648045123458;8901260123456789014;segway;;Operations Team;Fleet B
867648045123459;8901260123456789015;okai;ZK200;;New shipment
Uploading the CSV File
Step-by-Step Upload
Navigate to IoT Devices
Go to IoT Devices in the sidebar navigation
Click Import Button
Click the Import button (or CSV icon) in the toolbar. This opens the import dialog.
Select Your File
Click Choose File or drag and drop your CSV file into the upload area
Preview Data
The system will parse your file and display a preview of the data. Review the columns and sample rows.
Confirm Import
If everything looks correct, click Import to begin the process
Review Results
After import completes, you'll see a summary showing:
- Number of devices imported
- Any errors or warnings
- Total devices now in the system
What Happens During Import
Staging Process
- The system clears the staging table (
iot_devices_import) - Your CSV data is inserted into the staging table
- Basic validation is performed on required fields
Import Function
The import_iot_devices() database function:
- Validates each row in the staging table
- Creates new device records for new IMEIs
- Updates existing records if IMEI already exists
- Sets default values for missing fields:
online_status: falseactivation_status: pendingtotal_rides: 0trips_current_month: 0current_month_revenue: 0previous_month_revenue: 0iot_added_on: current timestamp
Cache Clearing
After a successful import, the vehicle identity cache is automatically cleared. This ensures:
- New IMEI-to-vehicle mappings are recognized
- Updated device information takes effect immediately
- No stale data affects telemetry processing
Handling Import Errors
Common Validation Errors
| Error | Cause | Solution |
|---|---|---|
| "IMEI is required" | Missing IMEI value in a row | Ensure every row has an IMEI |
| "Duplicate IMEI" | Same IMEI appears twice in file | Remove duplicate rows |
| "Invalid IoT type" | Unrecognized iot_type value | Use one of the valid type values |
| "Invalid ICCID format" | ICCID not 19-20 digits | Verify ICCID numbers |
| "Invalid subaccount_id" | UUID doesn't exist | Check subaccount UUID is correct |
File Format Errors
| Error | Cause | Solution |
|---|---|---|
| "Invalid CSV format" | Wrong delimiter or encoding | Use semicolons, save as UTF-8 |
| "Missing headers" | First row not recognized | Ensure column names match exactly |
| "Empty file" | No data rows | Add device data after header row |
| "File too large" | Exceeds size limit | Split into smaller files |
Resolving Errors
- Download the error report if available
- Fix issues in your original spreadsheet
- Re-export with correct format
- Upload the corrected file
Partial Imports
If some rows fail validation, successfully validated rows may still be imported. Check the results summary carefully to see which devices were added.
Updating Existing Devices
If you import a CSV containing IMEIs that already exist in the system:
- Existing devices are updated with new values from the CSV
- Empty cells don't overwrite existing data
- The
iot_added_ondate is preserved for existing devices
This allows you to use CSV import for both initial setup and bulk updates.
Linking Devices to Vehicles After Import
After importing IoT devices, you'll typically want to link them to vehicles. There are several approaches:
Option 1: Import Vehicles with IMEIs
When importing vehicles via CSV, include the iot_imei column. The system will automatically link devices to vehicles based on matching IMEI values.
Option 2: Manual Linking
- Go to Vehicles
- Click on a vehicle
- Edit and add the IMEI in the IoT IMEI field
- Save the vehicle
Option 3: Link from IoT Devices Page
- Go to IoT Devices
- Click on an unlinked device
- Click Link to Vehicle
- Select the target vehicle
- Confirm the link
Best Practices
Before Import
- Validate IMEIs - Ensure all 15-digit IMEIs are correct
- Check for duplicates - Remove any duplicate IMEI rows
- Verify subaccounts - Confirm subaccount UUIDs exist
- Test with small batch - Try importing 5-10 devices first
File Preparation
- Use consistent formatting - Same date format, case, etc.
- Remove empty rows - Delete any blank rows at the end
- Save a backup - Keep your original spreadsheet
- Document your mappings - Note which columns you used
After Import
- Verify count - Check total devices matches expected
- Spot check records - Open a few devices to verify data
- Test connectivity - Confirm devices can communicate
- Link to vehicles - Associate devices with fleet vehicles
Programmatic Import
For advanced users, IoT devices can also be imported via the API:
API Endpoint
POST /api/iot-devices/import
Request Format
{
"csv_data": [
{
"imei": "867648045123456",
"iccid": "8901260123456789012",
"iot_type": "queclink",
"iot_model": "GL530M",
"notes": "Fleet A"
},
{
"imei": "867648045123457",
"iccid": "8901260123456789013",
"iot_type": "queclink"
}
]
}
Response
{
"success": true,
"message": "Successfully imported IoT devices",
"total_count": 150
}
Linking Device to Vehicle via API
You can also link an IoT device to a vehicle programmatically:
PUT /api/iot-devices/import
Request Body
{
"imei": "867648045123456",
"vehicle_uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Response
{
"success": true,
"message": "IoT device linked to vehicle successfully",
"vehicle_uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"imei": "867648045123456"
}
This endpoint:
- Updates the vehicle's
iot_imeifield with the provided IMEI - Clears the vehicle identity cache to ensure immediate recognition
- Returns confirmation of the link
Authentication Required
API imports require authentication. Include your session token or API key in the request headers.
Troubleshooting
Import Succeeds But Devices Don't Appear
- Check the subaccount filter - you may be viewing a different subaccount
- Refresh the page to ensure latest data is loaded
- Search by IMEI to locate specific devices
Devices Imported But Not Linked to Vehicles
- Verify the IMEI matches exactly (no spaces or dashes)
- Check that vehicles exist with matching
iot_imeivalues - Try unlinking and relinking manually
Telemetry Not Arriving After Import
- Confirm the device is powered and has connectivity
- Verify server settings on the device match your endpoint
- Check the "Unmatched Devices" list for any issues
- Wait 5-10 minutes for the first heartbeat
Need Help?
If you encounter persistent import issues, contact support@levyelectric.com with your CSV file and error messages.