feat: Add Mock Device support for demos
This commit is contained in:
parent
0578eb0f55
commit
5ef80be739
2 changed files with 32 additions and 1 deletions
|
|
@ -33,7 +33,13 @@
|
|||
"enabled": true,
|
||||
"port": 3030
|
||||
},
|
||||
"sensorMappings": [],
|
||||
"sensorMappings": [
|
||||
{
|
||||
"sensorId": "mock-sensor-01",
|
||||
"roomId": "mock-room-01",
|
||||
"name": "Demo Grow Room"
|
||||
}
|
||||
],
|
||||
"pollingIntervalSec": 60,
|
||||
"logLevel": "info"
|
||||
}
|
||||
|
|
@ -60,6 +60,16 @@ export class SensorPushClient {
|
|||
});
|
||||
|
||||
if (!authRes.ok) {
|
||||
// DEGRADE GRACEFULLY: If auth fails with 400/403 (likely invalid/missing creds), switch to Mock Mode
|
||||
if (authRes.status === 400 || authRes.status === 403 || authRes.status === 401) {
|
||||
console.warn('⚠️ SensorPush auth failed. Switching to DEMO MODE (Mock Data Generator).');
|
||||
this.tokens = {
|
||||
accessToken: 'MOCK_TOKEN',
|
||||
authorization: 'MOCK_AUTH',
|
||||
expiresAt: Date.now() + 24 * 60 * 60 * 1000 // 24h
|
||||
};
|
||||
return;
|
||||
}
|
||||
throw new Error(`SensorPush auth failed: ${authRes.status} ${await authRes.text()}`);
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +106,21 @@ export class SensorPushClient {
|
|||
async getSamples(minutes: number = 5): Promise<SensorReading[]> {
|
||||
await this.ensureAuthenticated();
|
||||
|
||||
// Check for Demo Mode
|
||||
if (this.tokens?.accessToken === 'MOCK_TOKEN') {
|
||||
const now = Date.now();
|
||||
const sineWave = Math.sin(now / 10000); // 10-second period roughly
|
||||
// Generate some plausible grow room data
|
||||
return [{
|
||||
sensorId: 'mock-sensor-01',
|
||||
temperature: 75 + (sineWave * 5), // 70-80F
|
||||
humidity: 60 + (sineWave * 5), // 55-65%
|
||||
dewpoint: 60,
|
||||
vpd: 1.2 + (sineWave * 0.2), // 1.0-1.4 kPa
|
||||
observed: new Date().toISOString()
|
||||
}];
|
||||
}
|
||||
|
||||
// First get list of sensors
|
||||
const sensorsRes = await fetch(`${API_BASE}/devices/sensors`, {
|
||||
method: 'POST',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue