-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspa_example.html
More file actions
829 lines (720 loc) · 31.1 KB
/
spa_example.html
File metadata and controls
829 lines (720 loc) · 31.1 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mediainbox XDR Status & Spectrum</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
align-items: center;
}
/* Spectrum Styles */
.spectrum-container {
width: 90%;
max-width: 1200px;
margin: 0 auto 30px;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
position: relative;
}
.chart-container {
position: relative;
width: 100%;
height: 400px;
margin: 20px 0;
}
#spectrumChart {
position: absolute;
left: 0;
top: 0;
width: 100% !important;
height: 100% !important;
}
.controls {
margin: 20px 0;
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: center;
}
button,
select,
input {
padding: 8px 16px;
border: 1px solid #ddd;
border-radius: 4px;
background: white;
cursor: pointer;
}
button:hover {
background-color: #f0f0f0;
}
.loading {
text-align: center;
padding: 20px;
color: #666;
}
/* Status Cards Styles */
.container {
width: 90%;
max-width: 1200px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
padding: 15px;
}
.status-card {
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 15px 18px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
height: auto;
min-height: 200px;
}
.status-card:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}
.status-card h2 {
margin: 0 0 12px 0;
color: #2c3e50;
font-size: 1.2em;
padding-bottom: 8px;
border-bottom: 1px solid #eee;
}
.status-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.status-item {
margin-bottom: 10px;
}
.status-label {
display: block;
font-size: 0.85em;
color: #7f8c8d;
margin-bottom: 3px;
}
.status-value {
font-weight: 600;
color: #2c3e50;
font-size: 1.05em;
}
.frequency {
color: #2980b9;
font-weight: bold;
}
.volume-level {
color: #27ae60;
font-weight: bold;
}
.squelch {
color: #e74c3c;
font-weight: bold;
}
.status-ok {
color: #27ae60;
}
.status-warning {
color: #f39c12;
}
.status-error {
color: #e74c3c;
}
</style>
</head>
<body>
<!-- Spectrum Section -->
<div class="spectrum-container">
<h1>Spectrum Graph</h1>
<div class="controls">
<button id="refreshBtn">Refresh</button>
<select id="bandSelect">
<option value="fm">FM Band (87.5-108 MHz)</option>
<option value="airband">Airband (118-137 MHz)</option>
<option value="custom">Custom Range</option>
</select>
<div id="customRange" style="display: none;">
<input type="number" id="minFreq" step="0.1" min="0" placeholder="Min (MHz)">
<span>to</span>
<input type="number" id="maxFreq" step="0.1" min="0" placeholder="Max (MHz)">
<button id="applyRange">Apply</button>
</div>
</div>
<div class="chart-container">
<canvas id="spectrumChart"></canvas>
<div id="loading" class="loading" style="display: none;">Loading spectrum data...</div>
</div>
</div>
<!-- Status Cards Section -->
<div class="container">
<div class="status-card" id="status-1">
<h2>Receiver 1</h2>
<div class="status-grid">
<div class="status-item">
<span class="status-label">Frequency</span>
<span class="status-value frequency" id="freq-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Volume</span>
<span class="status-value volume-level" id="volume-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Squelch</span>
<span class="status-value squelch" id="squelch-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Bandwidth</span>
<span class="status-value" id="bandwidth-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">AGC</span>
<span class="status-value" id="agc-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Antenna</span>
<span class="status-value" id="antenna-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">DAA</span>
<span class="status-value" id="daa-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Deemphasis</span>
<span class="status-value" id="deemphasis-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Gain</span>
<span class="status-value" id="gain-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Rotator</span>
<span class="status-value" id="rotator-1">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Interval</span>
<span class="status-value" id="interval-1">Loading...</span>
</div>
</div>
</div>
<div class="status-card" id="status-2">
<h2>Receiver 2</h2>
<div class="status-grid">
<div class="status-item">
<span class="status-label">Frequency</span>
<span class="status-value frequency" id="freq-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Volume</span>
<span class="status-value volume-level" id="volume-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Squelch</span>
<span class="status-value squelch" id="squelch-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Bandwidth</span>
<span class="status-value" id="bandwidth-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">AGC</span>
<span class="status-value" id="agc-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Antenna</span>
<span class="status-value" id="antenna-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">DAA</span>
<span class="status-value" id="daa-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Deemphasis</span>
<span class="status-value" id="deemphasis-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Gain</span>
<span class="status-value" id="gain-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Rotator</span>
<span class="status-value" id="rotator-2">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Interval</span>
<span class="status-value" id="interval-2">Loading...</span>
</div>
</div>
</div>
<div class="status-card" id="status-3">
<h2>Receiver 3</h2>
<div class="status-grid">
<div class="status-item">
<span class="status-label">Frequency</span>
<span class="status-value frequency" id="freq-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Volume</span>
<span class="status-value volume-level" id="volume-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Squelch</span>
<span class="status-value squelch" id="squelch-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Bandwidth</span>
<span class="status-value" id="bandwidth-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">AGC</span>
<span class="status-value" id="agc-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Antenna</span>
<span class="status-value" id="antenna-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">DAA</span>
<span class="status-value" id="daa-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Deemphasis</span>
<span class="status-value" id="deemphasis-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Gain</span>
<span class="status-value" id="gain-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Rotator</span>
<span class="status-value" id="rotator-3">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Interval</span>
<span class="status-value" id="interval-3">Loading...</span>
</div>
</div>
</div>
<div class="status-card" id="status-4">
<h2>Receiver 4</h2>
<div class="status-grid">
<div class="status-item">
<span class="status-label">Frequency</span>
<span class="status-value frequency" id="freq-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Volume</span>
<span class="status-value volume-level" id="volume-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Squelch</span>
<span class="status-value squelch" id="squelch-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Bandwidth</span>
<span class="status-value" id="bandwidth-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">AGC</span>
<span class="status-value" id="agc-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Antenna</span>
<span class="status-value" id="antenna-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">DAA</span>
<span class="status-value" id="daa-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Deemphasis</span>
<span class="status-value" id="deemphasis-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Gain</span>
<span class="status-value" id="gain-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Rotator</span>
<span class="status-value" id="rotator-4">Loading...</span>
</div>
<div class="status-item">
<span class="status-label">Interval</span>
<span class="status-value" id="interval-4">Loading...</span>
</div>
</div>
</div>
</div>
<script>
// Spectrum Chart Code
let spectrumChart;
const refreshBtn = document.getElementById('refreshBtn');
const bandSelect = document.getElementById('bandSelect');
const customRange = document.getElementById('customRange');
const minFreqInput = document.getElementById('minFreq');
const maxFreqInput = document.getElementById('maxFreq');
const applyRangeBtn = document.getElementById('applyRange');
const loadingIndicator = document.getElementById('loading');
// Initialize chart with data
function initChart(labels, data) {
// Make sure we have valid data
if (!labels || !data || labels.length === 0 || data.length === 0) {
console.error('Invalid data provided to initChart');
loadingIndicator.textContent = 'Error: No valid data to display';
loadingIndicator.style.color = 'red';
return false;
}
// Get the canvas element
const canvas = document.getElementById('spectrumChart');
if (!canvas) {
console.error('Canvas element not found');
return false;
}
// Hide the canvas until we're ready to render
canvas.style.display = 'none';
// Set explicit canvas dimensions
const maxCanvasWidth = 2048;
const maxCanvasHeight = 2048;
canvas.width = Math.min(1000, maxCanvasWidth);
canvas.height = Math.min(400, maxCanvasHeight);
canvas.style.margin = '20px auto';
// Get the 2D context
const ctx = canvas.getContext('2d');
if (!ctx) {
console.error('Could not get 2D context');
return false;
}
// Destroy existing chart instance if it exists
if (window.spectrumChart) {
try {
window.spectrumChart.destroy();
} catch (e) {
console.warn('Error destroying previous chart:', e);
}
window.spectrumChart = null;
}
try {
// Create the chart with the provided data
spectrumChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Signal Strength (dB)',
data: data,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1,
fill: false,
pointRadius: 0,
tension: 0.1
}]
},
options: {
responsive: false,
maintainAspectRatio: false,
devicePixelRatio: 1,
scales: {
x: {
type: 'linear',
position: 'bottom',
title: { display: true, text: 'Frequency (MHz)' },
min: Math.min(...labels),
max: Math.max(...labels)
},
y: {
beginAtZero: true,
title: { display: true, text: 'Signal Strength (dB)' }
}
},
animation: { duration: 0 },
plugins: {
legend: { display: true, position: 'top' },
tooltip: {
mode: 'index',
intersect: false,
callbacks: {
label: context => `${context.parsed.x.toFixed(2)} MHz: ${context.parsed.y.toFixed(2)} dB`
}
},
zoom: false
},
layout: { padding: 10 },
elements: { line: { borderWidth: 1 } }
}
});
// Store the chart instance in window for later reference
window.spectrumChart = spectrumChart;
// Only show the canvas after the chart is fully rendered
setTimeout(() => {
canvas.style.display = 'block';
loadingIndicator.style.display = 'none';
}, 0);
return true;
} catch (e) {
console.error('Error creating chart:', e);
loadingIndicator.textContent = 'Error creating chart: ' + e.message;
loadingIndicator.style.color = 'red';
return false;
}
}
// Fetch spectrum data from API
async function fetchSpectrumData(minFreq = 87.5, maxFreq = 108) {
try {
loadingIndicator.style.display = 'block';
loadingIndicator.textContent = 'Loading spectrum data...';
loadingIndicator.style.color = '#666';
// API endpoint - update this to your actual API endpoint
const apiUrl = `http://localhost:5000/api/scan/1`;
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
let data = await response.text();
// Parse the custom data format: ["U86000=15.85,86100=11.75,...]
try {
// Remove the ["U and "] from the string
data = data.replace(/^\["U|"\]$/g, '');
// Split into frequency=strength pairs
const pairs = data.split(',');
const frequencies = [];
const strengths = [];
// Process each pair
for (const pair of pairs) {
const [freq, strength] = pair.split('=');
if (freq && strength) {
// Convert frequency from kHz to MHz for display
frequencies.push(parseFloat(freq) / 1000);
strengths.push(parseFloat(strength));
}
}
// Validate data
if (frequencies.length === 0 || frequencies.length !== strengths.length) {
throw new Error('Invalid data format after parsing');
}
// Update chart with new data
updateChart(frequencies, strengths);
// Hide loading indicator
loadingIndicator.style.display = 'none';
return { frequencies, strengths };
} catch (error) {
console.error('Error parsing spectrum data:', error);
loadingIndicator.textContent = 'Error parsing spectrum data: ' + error.message;
loadingIndicator.style.color = 'red';
return { frequencies: [], strengths: [] };
}
} catch (error) {
console.error('Error fetching spectrum data:', error);
loadingIndicator.textContent = 'Error loading spectrum data: ' + error.message;
loadingIndicator.style.color = 'red';
return { frequencies: [], strengths: [] };
}
}
// Update chart with new data
function updateChart(frequencies, strengths) {
if (!spectrumChart) {
initChart(frequencies, strengths);
return;
}
// Update chart data
spectrumChart.data.labels = frequencies.map(f => f.toFixed(2));
spectrumChart.data.datasets[0].data = strengths;
// Update chart
spectrumChart.update();
}
// Event Listeners for Spectrum
refreshBtn.addEventListener('click', async () => {
const minFreq = parseFloat(minFreqInput.value) || 87.5;
const maxFreq = parseFloat(maxFreqInput.value) || 108;
const { frequencies, strengths } = await fetchSpectrumData(minFreq, maxFreq);
updateChart(frequencies, strengths);
});
bandSelect.addEventListener('change', (e) => {
if (e.target.value === 'custom') {
customRange.style.display = 'flex';
customRange.style.gap = '10px';
customRange.style.alignItems = 'center';
} else {
customRange.style.display = 'none';
// Set default values based on band
let minFreq, maxFreq;
if (e.target.value === 'fm') {
minFreq = 87.5;
maxFreq = 108;
} else if (e.target.value === 'airband') {
minFreq = 118;
maxFreq = 137;
}
minFreqInput.value = minFreq;
maxFreqInput.value = maxFreq;
// Refresh data with new range
refreshBtn.click();
}
});
applyRangeBtn.addEventListener('click', () => {
refreshBtn.click();
});
// Status Cards Code
const urls = [
'http://127.0.0.1:5000/api/state/1',
'http://127.0.0.1:5000/api/state/2',
'http://127.0.0.1:5000/api/state/3',
'http://127.0.0.1:5000/api/state/4'
];
// Helper function to sleep
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Helper function to safely update a field if the element exists
function updateField(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}
// Fetch data for a single status
async function fetchData(url, statusId) {
try {
console.log(`Fetching data from: ${url}`);
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(`Received data for status ${statusId}:`, data);
// Update frequency with kHz (format: '96950,10')
if (data.freq_khz) {
try {
const freqParts = String(data.freq_khz).split(',');
const freqValue = parseInt(freqParts[0]) || 0;
updateField(`freq-${statusId}`, `${(freqValue / 1000).toFixed(2)} MHz`);
} catch (e) {
console.error('Error parsing frequency:', e);
updateField(`freq-${statusId}`, 'N/A');
}
}
// Update volume with percentage
const volume = data.volume !== undefined ? `${data.volume}%` : 'N/A';
updateField(`volume-${statusId}`, volume);
// Update squelch display (0 = OFF, 1-100 = threshold value)
if (data.squelch !== undefined) {
const squelchText = data.squelch === 0 ? 'OFF' : data.squelch.toString();
updateField(`squelch-${statusId}`, squelchText);
}
// Update bandwidth in kHz
if (data.bandwidth !== undefined) {
const bandwidthKHz = (parseInt(data.bandwidth) || 0) / 1000;
updateField(`bandwidth-${statusId}`, `${bandwidthKHz} kHz`);
}
// Update AGC (0=OFF, 1=FAST, 2=MED, 3=SLOW)
const agcModes = ['OFF', 'FAST', 'MED', 'SLOW'];
const agcValue = data.agc !== undefined ? (agcModes[data.agc] || data.agc) : 'N/A';
updateField(`agc-${statusId}`, agcValue);
// Update antenna (0=Auto, 1=Ant1, 2=Ant2)
const antennas = ['Auto', 'Ant1', 'Ant2'];
const antennaValue = data.antenna !== undefined ? (antennas[data.antenna] || data.antenna) : 'N/A';
updateField(`antenna-${statusId}`, antennaValue);
// Update DAA (dynamic attenuation adjustment)
const daaValue = data.daa ?
data.daa.charAt(0).toUpperCase() + data.daa.slice(1) : 'N/A';
updateField(`daa-${statusId}`, daaValue);
// Update deemphasis
updateField(`deemphasis-${statusId}`, data.deemphasis || 'N/A');
// Update gain
updateField(`gain-${statusId}`, data.gain !== undefined ? data.gain : 'N/A');
// Update rotator
updateField(`rotator-${statusId}`, data.rotator !== undefined ? data.rotator : 'N/A');
// Update interval sampling
updateField(`interval-${statusId}`, data.interval_sampling !== undefined ? `${data.interval_sampling} ms` : 'N/A');
// Update card styling
const card = document.getElementById(`status-${statusId}`);
if (card) {
// Default to green border
let borderColor = '#2ecc71';
// Update based on squelch if available
if (data.squelch !== undefined) {
// New format: 0 = off, 1-100 = on with threshold
if (data.squelch === 0) {
borderColor = '#e74c3c'; // Red for squelch off
}
}
// Update based on signal level if available
if (data.signal_level !== undefined) {
const signalLevel = parseFloat(data.signal_level) || 0;
borderColor = signalLevel > 10 ? '#27ae60' :
signalLevel > 5 ? '#f39c12' : '#e74c3c';
}
card.style.borderLeft = `4px solid ${borderColor}`;
}
return data;
} catch (error) {
console.error(`Error fetching data for Receiver ${statusId}:`, error);
const errorText = 'Error';
const fields = [
'freq', 'volume', 'squelch', 'bandwidth', 'agc', 'antenna',
'daa', 'deemphasis', 'gain', 'rotator', 'interval'
];
fields.forEach(field => {
updateField(`${field}-${statusId}`, errorText);
});
// Set error state styling
const card = document.getElementById(`status-${statusId}`);
if (card) {
card.style.borderLeft = '4px solid #f39c12';
}
return null;
}
}
// Load data for each status with delay
async function loadDataWithDelay() {
while (true) {
// Process each status one at a time with delay
for (let i = 0; i < urls.length; i++) {
try {
await fetchData(urls[i], i + 1);
// Wait 3 seconds before the next API call
await sleep(3000);
} catch (error) {
console.error(`Error in loadDataWithDelay for Receiver ${i + 1}:`, error);
// Continue with next receiver even if one fails
}
}
// Wait 3 seconds after the last receiver before starting over
await sleep(3000);
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
// Set default values for custom range
minFreqInput.value = '87.5';
maxFreqInput.value = '108';
// Initial data load
const initialLoad = async () => {
const minFreq = parseFloat(minFreqInput.value) || 87.5;
const maxFreq = parseFloat(maxFreqInput.value) || 108;
const { frequencies, strengths } = await fetchSpectrumData(minFreq, maxFreq);
updateChart(frequencies, strengths);
};
// Start loading data
initialLoad();
// Start status updates
if (urls && urls.length > 0) {
loadDataWithDelay();
} else {
console.error('No status API endpoints defined');
}
});
</script>
</body>
</html>