Skip to content

Commit 1d52103

Browse files
committed
Add sweep buffer and recovery endpoints
Implement sweep recovery and stop controls: add a SweepDataPoint buffer (MAX_SWEEP_BUFFER) to store recent sweep points, track sweepInProgress and sweepStopRequested, and persist points during a sweep. Introduce HTTP endpoints /sweep_buffer (GET) to retrieve buffered data and /sweep_stop (POST) to request stopping a running sweep. Update sweep loop to check for client disconnect or explicit stop request and improve logging; ensure buffer reset at sweep start and clear flags at completion. Other updates: bump build metadata (date/time/git hash), update README esptool path, add an image width attribute in index.html, reorder a serial unknown-command log branch, update many embedded website HTML assets, and include an updated firmware binary.
1 parent d3d8f16 commit 1d52103

19 files changed

Lines changed: 873 additions & 449 deletions

Production_Files/Software/ODMR_Server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pio device list # cross-platform
234234
### Option A — Flash merged binary at 0x0 (recommended for initial install)
235235

236236
```bash
237-
python -m esptool \
237+
/Users/bene/.platformio/penv/bin/python -m esptool \
238238
--chip esp32c3 \
239239
-p /dev/cu.usbmodem101 \
240240
-b 460800 \
Binary file not shown.

Production_Files/Software/ODMR_Server/data/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h3 class="h5 mb-3" data-lang-key="nv_centers_title">Was sind NV-Zentren?</h3>
8888
</div>
8989
<div class="col-lg-6">
9090
<figure class="text-center">
91-
<img src="NVGitter.png" class="img-fluid rounded shadow" alt="NV Center Structure" data-lang-key="nv_structure_alt">
91+
<img src="NVGitter.png" class="img-fluid rounded shadow" alt="NV Center Structure" data-lang-key="nv_structure_alt" width="200">
9292
<figcaption class="mt-2 small text-muted" data-lang-key="nv_structure_caption">
9393
Struktur des NV-Zentrums im Diamantgitter
9494
</figcaption>

Production_Files/Software/ODMR_Server/src/main.cpp

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ volatile uint16_t cachedIR = 0;
9595
unsigned long lastSensorRead = 0;
9696
const unsigned long SENSOR_READ_INTERVAL = 100; // Read sensor every 100ms
9797

98+
// Sweep data buffer for broken-connection recovery
99+
// Stores the last sweep results so they can be retrieved via /sweep_buffer
100+
struct SweepDataPoint {
101+
float frequency;
102+
uint32_t intensity;
103+
};
104+
static const int MAX_SWEEP_BUFFER = 500;
105+
SweepDataPoint sweepBuffer[MAX_SWEEP_BUFFER];
106+
int sweepBufferCount = 0;
107+
bool sweepInProgress = false;
108+
volatile bool sweepStopRequested = false;
109+
98110
// WebServer on port 80
99111
WebServer server(80);
100112

@@ -719,6 +731,11 @@ void handleSweep()
719731
Serial.printf("Sweep start: %.1f -> %.1f MHz, step %.1f, avg %d, settle %d ms, %d pts\n",
720732
fBegin, fEnd, fStep, averages, settle_ms, totalPoints);
721733

734+
// Reset sweep buffer for this new sweep
735+
sweepBufferCount = 0;
736+
sweepInProgress = true;
737+
sweepStopRequested = false;
738+
722739
setLEDStatus(LED_MEASURING);
723740
adf.begin();
724741

@@ -733,10 +750,10 @@ void handleSweep()
733750

734751
for (float f = fBegin; f <= fEnd + 0.001f; f += fStep)
735752
{
736-
// Check if client disconnected (user pressed stop / closed page)
737-
if (!client.connected())
753+
// Check if client disconnected or stop requested
754+
if (!client.connected() || sweepStopRequested)
738755
{
739-
Serial.println("Sweep: client disconnected, stopping");
756+
Serial.println(sweepStopRequested ? "Sweep: stop requested" : "Sweep: client disconnected, stopping");
740757
break;
741758
}
742759

@@ -753,6 +770,14 @@ void handleSweep()
753770
}
754771
uint32_t intensity = (uint32_t)(sum / averages);
755772

773+
// Store in buffer for recovery
774+
if (sweepBufferCount < MAX_SWEEP_BUFFER)
775+
{
776+
sweepBuffer[sweepBufferCount].frequency = f;
777+
sweepBuffer[sweepBufferCount].intensity = intensity;
778+
sweepBufferCount++;
779+
}
780+
756781
// Send data point as SSE event
757782
String msg = "data: {\"f\":";
758783
msg += String(f, 1);
@@ -777,10 +802,47 @@ void handleSweep()
777802
server.sendContent(""); // End chunked transfer
778803

779804
adf.stop();
805+
sweepInProgress = false;
806+
sweepStopRequested = false;
780807
setLEDStatus(LED_CONNECTED);
781808
Serial.printf("Sweep complete: %d points measured\n", pointIndex);
782809
}
783810

811+
// Endpoint to retrieve buffered sweep data (for broken-connection recovery)
812+
void handleSweepBuffer()
813+
{
814+
String json = "{\"in_progress\":";
815+
json += sweepInProgress ? "true" : "false";
816+
json += ",\"count\":";
817+
json += String(sweepBufferCount);
818+
json += ",\"data\":[";
819+
for (int i = 0; i < sweepBufferCount; i++)
820+
{
821+
if (i > 0) json += ",";
822+
json += "{\"f\":";
823+
json += String(sweepBuffer[i].frequency, 1);
824+
json += ",\"I\":";
825+
json += String(sweepBuffer[i].intensity);
826+
json += "}";
827+
}
828+
json += "]}";
829+
server.send(200, "application/json", json);
830+
}
831+
832+
// Endpoint to explicitly stop a running sweep
833+
void handleSweepStop()
834+
{
835+
if (sweepInProgress)
836+
{
837+
sweepStopRequested = true;
838+
server.send(200, "application/json", "{\"status\":\"ok\",\"message\":\"stop requested\"}");
839+
}
840+
else
841+
{
842+
server.send(200, "application/json", "{\"status\":\"ok\",\"message\":\"no sweep running\"}");
843+
}
844+
}
845+
784846
void setup()
785847
{
786848

@@ -1046,6 +1108,8 @@ void setup()
10461108
server.on("/tsl/integration_time", HTTP_POST, handleSetTSLIntegrationTime);
10471109
server.on("/ratio", HTTP_GET, handleMeasureRatio);
10481110
server.on("/sweep", HTTP_GET, handleSweep);
1111+
server.on("/sweep_buffer", HTTP_GET, handleSweepBuffer);
1112+
server.on("/sweep_stop", HTTP_POST, handleSweepStop);
10491113

10501114
// ADF4351 enable/disable endpoints (P1 #9)
10511115
server.on("/ADF_Enable", HTTP_POST, []()
@@ -1160,10 +1224,6 @@ void loop()
11601224
Serial.printf("STATUS connected:%d freq_range:[%.1f,%.1f] led:%d\n",
11611225
WiFi.softAPgetStationNum(), ADF_FREQ_MIN, ADF_FREQ_MAX, (int)currentLEDStatus);
11621226
}
1163-
else if (rxBuf.length() > 0)
1164-
{
1165-
Serial.printf("ERR unknown command: %s\n", rxBuf.c_str());
1166-
}
11671227
else if (rxBuf.startsWith("RATIO "))
11681228
{
11691229
// Format: RATIO f1 f2
@@ -1190,6 +1250,10 @@ void loop()
11901250
Serial.println("ERR RATIO syntax");
11911251
}
11921252
}
1253+
else if (rxBuf.length() > 0)
1254+
{
1255+
Serial.printf("ERR unknown command: %s\n", rxBuf.c_str());
1256+
}
11931257
}
11941258
rxBuf = "";
11951259
}

Production_Files/Software/ODMR_Server/src/version_info.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#define __VERSION_INFO_H__
66

77
#define FIRMWARE_VERSION "1.0.0"
8-
#define BUILD_DATE "2026-03-11"
9-
#define BUILD_TIME "11:11:10"
10-
#define BUILD_TIMESTAMP "20260311111110"
11-
#define GIT_HASH "1b29b12"
8+
#define BUILD_DATE "2026-03-12"
9+
#define BUILD_TIME "14:12:01"
10+
#define BUILD_TIMESTAMP "20260312141201"
11+
#define GIT_HASH "d3d8f16"
1212
#define GIT_BRANCH "fix-listoferrors"
1313

1414
// Combined version string

Production_Files/Software/ODMR_Server/src/website/index_html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Production_Files/Software/ODMR_Server/src/website/infos_html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Production_Files/Software/ODMR_Server/src/website/justage_html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Production_Files/Software/ODMR_Server/src/website/messung_html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Production_Files/Software/ODMR_Server/src/website/messung_webserial_html.h

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)