JAndrassy / ArduinoOTA

Arduino library to upload sketch over network to Arduino board with WiFi or Ethernet libraries
GNU Lesser General Public License v2.1
450 stars 91 forks source link

Status Code 200 Received but New Program Not Loaded #163

Closed JEG8 closed 2 years ago

JEG8 commented 2 years ago

Hi,

I am running into an issue on my Arduino IOT 33 where the OTA downloads the file and I receive a 200 status code, but the file is not replaced on the device. The old file is loaded back on. Do you know why this is happening? Could it be check sum related? The performance is very inconsistent.

Joe

JAndrassy commented 2 years ago

there is no checksum. how do you test if the new or old version is running?

JEG8 commented 2 years ago

I have a firmware version number that gets updated when I add a new version to my server. Also, I can see that when I make edits to print statements, they do not show up on the serial monitor, indicating that the new version was never loaded on. However, I can see that the download occurs correctly because the size of the file matches the BIN output of the IDE.

JAndrassy commented 2 years ago

you use InternalStorage directly?

JEG8 commented 2 years ago

No, I don't know what you mean by "InternalStorage". I am saving the downloaded file to a SPI Flash. I am then checking the size of the file, and comparing it to the "length" returned by the server. If they match, I proceed with the update. That all works fine. However, it appears that the bootloader portion isnt working properly. The file is not replaced on the hardware.

JAndrassy commented 2 years ago

so you don't use the ArduinoOTA library at all. you download the file to external SPI flash and it should be bootloaded by what? I don't know about a library similar to SDU library, which would load the update binary from SPI flash as the SDU library does from SD card

JEG8 commented 2 years ago

Is the SDU library strictly for SD card? I am using Adafruit library which can be used with either an SD card or a SPI Flash. I figured because they both use SDFat library, they could be used interchangeably and the update would still work with the SDU library.

JAndrassy commented 2 years ago

SDU library is just an array set to be prepended by the linker before your sketch. And that array is a compiled extra sketch which loads the binary from SD card, writes it to flash and hands over the execution to regular sketch. It knows nothing about your SPI flash or the Adaruit_SPIFlash libray.

JEG8 commented 2 years ago

Hi,

I should clarify, when I say SPIFlash - I am using a Winbond W25Q128JVSIM flash memory in place of an SD Card (to save space).

I think you pointed me to the right location. It looks like the SDU Library uses the following on (Line 49 SDUBoot.INO) to look for the update file on the SD Card.

if (SD.begin(SDCARD_SS_PIN) && SD.exists(UPDATE_FILE)) { File updateFile = SD.open(UPDATE_FILE); uint32_t updateSize = updateFile.size(); bool updateFlashed = false;

That file is actually on my SPI Flash, stored the same way. I should just need to point the SDU to look at my SPI Flash for the file, right?

JAndrassy commented 2 years ago

That file is actually on my SPI Flash, stored the same way. I should just need to point the SDU to look at my SPI Flash for the file, right?

right. you have to write and test the modified 'extras' sketch which will use the SPFlash library instead of the SD library. Then you have to convert the compiled binary of that sketch to an array of bytes in a .h file (there is some tool I found long time ago on Internet which can help with it). Then you create a library with that .h file and use it with your sketch.