Define and validate location data structures for pet tracking systems.
{
"location": {
"latitude": 37.7749,
"longitude": -122.4194,
"altitude": 52.3,
"accuracy": 5.2,
"timestamp": "2025-12-25T14:30:00Z"
},
"device": {
"id": "PET-TRACKER-12345",
"batteryLevel": 85,
"signalStrength": -72
},
"pet": {
"id": "pet_abc123",
"name": "Max",
"breed": "Golden Retriever"
}
}
{
"geofence": {
"id": "zone_home_001",
"name": "Home Safe Zone",
"type": "circle",
"center": {
"latitude": 37.7749,
"longitude": -122.4194
},
"radius": 100,
"unit": "meters",
"alerts": {
"onEnter": true,
"onExit": true,
"notificationChannels": ["push", "sms", "email"]
}
}
}
{
"event": {
"type": "location_update",
"petId": "pet_abc123",
"timestamp": "2025-12-25T14:30:00Z",
"location": {
"latitude": 37.7749,
"longitude": -122.4194,
"accuracy": 5.2
},
"activity": {
"type": "walking",
"speed": 1.2,
"distance": 450,
"duration": 375
},
"environment": {
"indoor": false,
"temperature": 22.5
}
}
}
Explore position calculation, geofencing, and battery optimization algorithms.
Kalman filter for smoothing GPS coordinates and removing noise:
function kalmanFilter(measurement, previousEstimate, errorCovariance) {
const processNoise = 0.01;
const measurementNoise = 5.0;
// Prediction
let predictedEstimate = previousEstimate;
let predictedCovariance = errorCovariance + processNoise;
// Update
const kalmanGain = predictedCovariance /
(predictedCovariance + measurementNoise);
const estimate = predictedEstimate +
kalmanGain * (measurement - predictedEstimate);
const covariance = (1 - kalmanGain) * predictedCovariance;
return { estimate, covariance };
}
function optimizeTrackingInterval(batteryLevel, movementSpeed, mode) {
// Adaptive tracking based on battery and activity
if (mode === 'power_save') {
return batteryLevel < 20 ? 600 : 300; // 10min or 5min
}
if (movementSpeed > 2.0) { // Fast movement (running/car)
return 10; // 10 seconds
} else if (movementSpeed > 0.5) { // Walking
return 30; // 30 seconds
} else { // Stationary
return batteryLevel < 30 ? 120 : 60; // 2min or 1min
}
}
Real-time location updates and event streaming protocols.
// Client connection
const ws = new WebSocket('wss://api.pettrack.wia.org/v1/stream');
ws.on('connect', () => {
ws.send(JSON.stringify({
type: 'subscribe',
petId: 'pet_abc123',
events: ['location', 'geofence', 'battery']
}));
});
ws.on('message', (data) => {
const event = JSON.parse(data);
handleLocationUpdate(event);
});
// MQTT Topic Structure
pet/{pet_id}/location // Location updates
pet/{pet_id}/status // Device status
pet/{pet_id}/alerts // Alert notifications
pet/{pet_id}/config // Configuration updates
// Example publish
mqtt.publish('pet/abc123/location', JSON.stringify({
lat: 37.7749,
lng: -122.4194,
accuracy: 5.2,
timestamp: Date.now()
}));
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/pets/{id}/location | Get current location |
| GET | /v1/pets/{id}/history | Get location history |
| POST | /v1/geofences | Create geofence zone |
| GET | /v1/pets/{id}/alerts | Get alert notifications |
| PUT | /v1/pets/{id}/mode | Update tracking mode |
Integrate pet tracking with mobile apps, smart home, and third-party services.
// iOS Swift Example
import WIAPetTracking
let tracker = PetTracker(apiKey: "your_api_key")
tracker.subscribe(petId: "pet_abc123") { location in
print("Pet location: \(location.latitude), \(location.longitude)")
updateMapView(location)
}
tracker.createGeofence(
center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
radius: 100,
onExit: { alert in
showNotification("Pet left safe zone!")
}
)
// Home Assistant Integration
automation:
- alias: "Pet Arrived Home"
trigger:
platform: state
entity_id: device_tracker.pet_max
to: 'home'
action:
- service: light.turn_on
entity_id: light.front_door
- service: notify.mobile_app
data:
message: "Max has arrived home!"
Simulate real-time pet tracking scenarios and test system behavior.