IoT & Tracking
Build real-time IoT applications and tracking systems with NoLag.
Overview
NoLag is ideal for IoT applications that require real-time data streaming from devices. Whether you're tracking vehicles, monitoring sensors, or controlling smart devices, NoLag provides the low-latency infrastructure you need.
Fleet Tracking Example
import { NoLag } from '@nolag/js-sdk'
const client = NoLag('device_access_token')
await client.connect()
const fleet = client.setApp('fleet-tracker').setRoom('vehicles')
// Subscribe to all vehicle updates
fleet.subscribe('location')
fleet.subscribe('telemetry')
// Handle location updates
fleet.on('location', (data) => {
updateMapMarker(data.vehicleId, {
lat: data.latitude,
lng: data.longitude,
heading: data.heading,
speed: data.speed
})
})
// Handle telemetry data
fleet.on('telemetry', (data) => {
updateVehicleStatus(data.vehicleId, {
fuel: data.fuelLevel,
engine: data.engineStatus,
battery: data.batteryVoltage
})
})Device Publishing
On the IoT device, publish updates at regular intervals:
// On the IoT device: publish location updates
setInterval(() => {
const location = gps.getLocation()
device.emit('location', {
vehicleId: DEVICE_ID,
latitude: location.lat,
longitude: location.lng,
heading: location.heading,
speed: location.speed,
timestamp: Date.now()
})
}, 5000) // Every 5 secondsUse Cases
- Fleet management - Track vehicles, deliveries, and drivers
- Asset tracking - Monitor equipment and inventory location
- Sensor networks - Collect data from environmental sensors
- Smart home - Control and monitor IoT devices
- Wearables - Stream health and fitness data
Best Practices
- Use device-type actors for IoT devices
- Batch telemetry data to reduce message frequency
- Use QoS 1 for important status updates
- Implement reconnection logic for unreliable networks
- Consider data retention and historical storage needs