import http from 'http'; const OPTIONS = { hostname: '127.0.0.1', port: 3905, path: '/api/history?devName=Test&port=1&range=day', method: 'GET' }; const req = http.request(OPTIONS, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Status Code:', res.statusCode); try { const json = JSON.parse(data); console.log('Response Keys:', Object.keys(json)); if (json.start !== undefined && Array.isArray(json.temps)) { console.log('SUCCESS: API returned compressed structure.'); console.log('Step Size:', json.step); console.log('Temps Length:', json.temps.length); } else { console.log('FAILURE: API returned unexpected structure.', json); } } catch (e) { console.error('Failed to parse JSON:', e); console.log('Raw Data:', data); } }); }); req.on('error', (e) => { console.error('Request error (server might not be running):', e.message); }); req.end(); const OUTPUT_OPTIONS = { hostname: '127.0.0.1', port: 3905, path: '/api/outputs/history?range=day', method: 'GET' }; const reqOut = http.request(OUTPUT_OPTIONS, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Output History Status Code:', res.statusCode); try { const json = JSON.parse(data); const keys = Object.keys(json); console.log('Output Keys:', keys); if (keys.length > 0) { const firstKey = keys[0]; const entries = json[firstKey]; if (Array.isArray(entries) && entries.length > 0 && Array.isArray(entries[0])) { console.log('SUCCESS: Output API returned compressed dictionary.'); console.log('Sample Entry:', entries[0]); console.log(`Entries count for ${firstKey}: ${entries.length}`); } else { console.log('FAILURE: Output API format incorrect.', entries[0]); } } else { console.log('WARNING: Output API returned empty object (no history).'); } } catch (e) { console.error('Failed to parse Output JSON:', e); } }); }); reqOut.on('error', (e) => { console.error('Output Request error:', e.message); }); reqOut.end(); // Test offset const OFFSET_OPTIONS = { hostname: '127.0.0.1', port: 3905, path: '/api/history?devName=Tent&port=1&range=day&offset=1', method: 'GET' }; const reqOffset = http.request(OFFSET_OPTIONS, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log('Offset History Status Code:', res.statusCode); try { const json = JSON.parse(data); if (json.start && json.start > 0) { const startDate = new Date(json.start * 1000); console.log(`Offset 1 Start Time: ${json.start} (${startDate.toISOString()})`); // Check if it's roughly 48h ago (since offset 1 day means window start is -48h) // vs offset 0 start is -24h. const now = Date.now() / 1000; const hoursDiff = (now - json.start) / 3600; console.log(`Hours difference from now: ${hoursDiff.toFixed(1)}h (Should be ~48h)`); } } catch (e) { console.error(e); } }); }); reqOffset.end();