This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_esp32_route.js
More file actions
89 lines (82 loc) · 2.67 KB
/
create_esp32_route.js
File metadata and controls
89 lines (82 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const mongoose = require('mongoose');
const Route = require('./dist/models/Route.js').default;
async function createESP32Route() {
try {
// Use the connection string from env or fallback
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://sri-express:[email protected]/sri_express?retryWrites=true&w=majority';
await mongoose.connect(mongoUri);
console.log('✅ Connected to MongoDB');
// Delete any existing route with this ID
await Route.deleteOne({ _id: '68c0dcf350719c991fe9e5d8' });
// Create route with EXACT ID that ESP32 expects
const routeData = {
_id: new mongoose.Types.ObjectId('68c0dcf350719c991fe9e5d8'), // EXACT ID from ESP32
routeId: "RT001KML",
name: "Kottawa → Mount Lavinia Express",
startLocation: {
name: "Kottawa Bus Stand",
coordinates: [79.9639299, 6.8408351], // CORRECT coordinates
address: "RXR7+8HM Kottawa Bus Station, Pannipitiya 10230"
},
endLocation: {
name: "Mount Lavinia",
coordinates: [79.8638, 6.8389],
address: "Mount Lavinia Bus Stand, Mount Lavinia"
},
waypoints: [
{
name: "Maharagama",
coordinates: [79.9275, 6.8448],
estimatedTime: 10,
order: 1
},
{
name: "Nugegoda",
coordinates: [79.8990, 6.8748],
estimatedTime: 20,
order: 2
}
],
distance: 15,
estimatedDuration: 45,
schedules: [{
departureTime: "06:00",
arrivalTime: "06:45",
frequency: 15,
daysOfWeek: ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"],
isActive: true
}],
operatorInfo: {
fleetId: new mongoose.Types.ObjectId(),
companyName: "Western Provincial Transport",
contactNumber: "+94112123456"
},
vehicleInfo: {
type: "bus",
capacity: 50,
amenities: ["Comfortable_Seats", "Standing_Space"]
},
pricing: {
basePrice: 35,
pricePerKm: 2.5,
discounts: [
{ type: "student", percentage: 25 },
{ type: "senior", percentage: 20 },
{ type: "military", percentage: 15 }
]
},
status: "active"
};
const route = new Route(routeData);
await route.save();
console.log('🎉 SUCCESS! Created route with ESP32 ID:');
console.log(`Route ID: ${route._id}`);
console.log(`Name: ${route.name}`);
console.log('✅ Your ESP32 should now work!');
process.exit(0);
} catch (error) {
console.error('❌ Error:', error);
process.exit(1);
}
}
createESP32Route();