|
@@ -355,6 +355,7 @@ static volatile bool uploadVerify = false;
|
|
|
static volatile bool uploadFailed = false;
|
|
static volatile bool uploadFailed = false;
|
|
|
static volatile uint32_t uploadBytes = 0;
|
|
static volatile uint32_t uploadBytes = 0;
|
|
|
static volatile uint32_t uploadCrc = 0;
|
|
static volatile uint32_t uploadCrc = 0;
|
|
|
|
|
+static char uploadErrorMsg[80] = "";
|
|
|
|
|
|
|
|
//=============================================================
|
|
//=============================================================
|
|
|
// HTTP handlers
|
|
// HTTP handlers
|
|
@@ -399,7 +400,9 @@ static void handleRoot() {
|
|
|
|
|
|
|
|
static void handleUploadDone() {
|
|
static void handleUploadDone() {
|
|
|
if (uploadFailed) {
|
|
if (uploadFailed) {
|
|
|
- httpServer.send(500, "application/json", "{\"ok\":false}");
|
|
|
|
|
|
|
+ char buf[128];
|
|
|
|
|
+ snprintf(buf, sizeof(buf), "{\"ok\":false,\"error\":\"%s\"}", uploadErrorMsg);
|
|
|
|
|
+ httpServer.send(500, "application/json", buf);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
char buf[80];
|
|
char buf[80];
|
|
@@ -415,19 +418,29 @@ static void handleUploadStream() {
|
|
|
|
|
|
|
|
if (up.status == UPLOAD_FILE_START) {
|
|
if (up.status == UPLOAD_FILE_START) {
|
|
|
uploadActive = true; uploadFailed = false; uploadBytes = 0; uploadCrc = 0;
|
|
uploadActive = true; uploadFailed = false; uploadBytes = 0; uploadCrc = 0;
|
|
|
|
|
+ uploadErrorMsg[0] = '\0';
|
|
|
uploadVerify = httpServer.hasArg("verify");
|
|
uploadVerify = httpServer.hasArg("verify");
|
|
|
Serial.println(); Serial.print("HTTP upload start: "); Serial.println(up.filename);
|
|
Serial.println(); Serial.print("HTTP upload start: "); Serial.println(up.filename);
|
|
|
Serial.print("Verify: "); Serial.println(uploadVerify ? "yes" : "no");
|
|
Serial.print("Verify: "); Serial.println(uploadVerify ? "yes" : "no");
|
|
|
Wire.beginTransmission(EEPROM_7BIT);
|
|
Wire.beginTransmission(EEPROM_7BIT);
|
|
|
- Serial.print("EEPROM probe err: "); Serial.println(Wire.endTransmission());
|
|
|
|
|
|
|
+ uint8_t probeErr = Wire.endTransmission();
|
|
|
|
|
+ Serial.print("EEPROM probe err: "); Serial.println(probeErr);
|
|
|
|
|
+ if (probeErr != 0) {
|
|
|
|
|
+ snprintf(uploadErrorMsg, sizeof(uploadErrorMsg), "EEPROM not found (I2C err %u)", probeErr);
|
|
|
|
|
+ uploadFailed = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else if (up.status == UPLOAD_FILE_WRITE) {
|
|
else if (up.status == UPLOAD_FILE_WRITE) {
|
|
|
if (uploadFailed) return;
|
|
if (uploadFailed) return;
|
|
|
if ((uploadBytes + up.currentSize) > EEPROM_SIZE_BYTES) {
|
|
if ((uploadBytes + up.currentSize) > EEPROM_SIZE_BYTES) {
|
|
|
- Serial.println("Upload too large for 24C256"); uploadFailed = true; return;
|
|
|
|
|
|
|
+ snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
|
|
|
|
|
+ "File too large: %u bytes (max 32768)", uploadBytes + up.currentSize);
|
|
|
|
|
+ Serial.println(uploadErrorMsg); uploadFailed = true; return;
|
|
|
}
|
|
}
|
|
|
if (!eepromWriteBlock((uint16_t)uploadBytes, up.buf, (uint16_t)up.currentSize)) {
|
|
if (!eepromWriteBlock((uint16_t)uploadBytes, up.buf, (uint16_t)up.currentSize)) {
|
|
|
- Serial.println("EEPROM write failed"); uploadFailed = true; return;
|
|
|
|
|
|
|
+ snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
|
|
|
|
|
+ "EEPROM I2C write failed at offset %u", (uint32_t)uploadBytes);
|
|
|
|
|
+ Serial.println(uploadErrorMsg); uploadFailed = true; return;
|
|
|
}
|
|
}
|
|
|
uploadCrc = esp_rom_crc32_le(uploadCrc, up.buf, up.currentSize);
|
|
uploadCrc = esp_rom_crc32_le(uploadCrc, up.buf, up.currentSize);
|
|
|
uploadBytes += up.currentSize;
|
|
uploadBytes += up.currentSize;
|
|
@@ -442,12 +455,20 @@ static void handleUploadStream() {
|
|
|
uint32_t remaining = uploadBytes; uint16_t addr = 0;
|
|
uint32_t remaining = uploadBytes; uint16_t addr = 0;
|
|
|
while (remaining) {
|
|
while (remaining) {
|
|
|
uint16_t n = remaining > sizeof(tmp) ? sizeof(tmp) : (uint16_t)remaining;
|
|
uint16_t n = remaining > sizeof(tmp) ? sizeof(tmp) : (uint16_t)remaining;
|
|
|
- if (!i2cReadBlock(EEPROM_7BIT, addr, tmp, n)) { Serial.println("EEPROM read failed"); uploadFailed = true; break; }
|
|
|
|
|
|
|
+ if (!i2cReadBlock(EEPROM_7BIT, addr, tmp, n)) {
|
|
|
|
|
+ snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
|
|
|
|
|
+ "EEPROM read failed at offset %u", (uint32_t)addr);
|
|
|
|
|
+ Serial.println(uploadErrorMsg); uploadFailed = true; break;
|
|
|
|
|
+ }
|
|
|
crc = esp_rom_crc32_le(crc, tmp, n);
|
|
crc = esp_rom_crc32_le(crc, tmp, n);
|
|
|
addr += n; remaining -= n; delay(0);
|
|
addr += n; remaining -= n; delay(0);
|
|
|
}
|
|
}
|
|
|
- Serial.print("Verify CRC32: 0x"); Serial.println(crc, HEX);
|
|
|
|
|
- if (!uploadFailed && crc != uploadCrc) { Serial.println("CRC mismatch"); uploadFailed = true; }
|
|
|
|
|
|
|
+ Serial.printf("Verify CRC32: wrote=0x%08X read=0x%08X\n", (uint32_t)uploadCrc, crc);
|
|
|
|
|
+ if (!uploadFailed && crc != uploadCrc) {
|
|
|
|
|
+ snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
|
|
|
|
|
+ "CRC mismatch: wrote 0x%08X, read 0x%08X", (uint32_t)uploadCrc, crc);
|
|
|
|
|
+ Serial.println(uploadErrorMsg); uploadFailed = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
uploadActive = false; ledOff();
|
|
uploadActive = false; ledOff();
|
|
|
Serial.println(uploadFailed ? "HTTP upload result: FAIL" : "HTTP upload result: OK");
|
|
Serial.println(uploadFailed ? "HTTP upload result: FAIL" : "HTTP upload result: OK");
|