While updating my firmware on ESP8266 with OTA I'm getting magic byte error I checked my bin file and 0xE9 is first byte. My code snippet:
- std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
- client->setInsecure();
- HTTPClient http;
- http.begin(*client, "https://example.com/firmware.bin");
- int httpCode = http.GET();
- if (httpCode <= 0) {
- Serial.printf("HTTP failed, error: %s\n",
- http.errorToString(httpCode).c_str());
- return;
- }
- // Check that we have enough space for the new binary.
- int contentLen = http.getSize();
- Serial.printf("Content-Length: %d\n", contentLen);
- bool canBegin = Update.begin(contentLen);
- if (!canBegin)
- {
- Serial.println("Not enough space to begin OTA");
- return;
- }
- // Write the HTTP stream to the Update library.
- WiFiClient *client2 = http.getStreamPtr();
- size_t written = Update.writeStream(*client2);
- Serial.printf("OTA: %d/%d bytes written.\n", written, contentLen);
If I comment out code in Updater.cpp method _verifyHeader that checks the byte - OTA process works as expected.
Commented code:
- bool UpdaterClass::_verifyHeader(uint8_t data) {
- if(_command == U_FLASH) {
- // check for valid first magic byte (is always 0xE9)
- // if(data != 0xE9) {
- // _currentAddress = (_startAddress + _size);
- // _setError(UPDATE_ERROR_MAGIC_BYTE);
- // return false;
- // }
- return true;
- } else if(_command == U_SPIFFS) {
- // no check of SPIFFS possible with first byte.
- return true;
- }
- return false;
- }
Kind regards,