Hello, I’m using the ota OTA updater from Juraj https://github.com/JAndrassy/ArduinoOTA in the Examples/Advanced/OTASketchDownload sketch. I ran into a problem with it. Some how after downloading the new bin file and rebooting the zero board. It keeps trying to install the same file. I'm not sure why is that or how to stop it. once it updates to the new bin file. I really need help. Can someone please help me?
Thatis what I'm unsure of. In serial monitor it looks like it keeps repeating the same thing. I don't know If it downloading again and again and installing the bin file over or is it just checking to see if the bin file has changed.
All I can tell from the serial monitor it keeps repeating the same thing over and over.
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42644 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42644 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42644 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42644 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
I made no changes to the code other then add an led blink to test it.
I tried this to see if it is resetting the setup then the loop and this is what happens.
Here is the output from the serial monitor. What i did was put in setup I put
Serial.println("setup");
Serial.println("1");
and in loop I put
Serial.println("2");
delay(1000);
It is Redownloading over and over the sketch sketch.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
setup
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42684 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
setup
1
Loop
2
Loop
2
Loop
2
Loop
2
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42684 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
setup
1
Loop
2
Loop
2
Loop
2
Loop
2
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42684 bytes
Sketch update apply and reset.
Sketch version 1
Initialize Ethernet with DHCP:
Ethernet connected
setup
1
Loop
2
Loop
2
Loop
2
Loop
2
Check for update file /updateblink/blink.bin
Update status code: -2
Loop
2
Loop
2
Loop
2
Loop
2
Check for update file /updateblink/blink.bin
Update status code: 200
Server returned update file of size 42684 bytes
This is my sketch.
/*
This example downloads sketch update over network.
It doesn't start the OTA upload sever of the ArduinoOTA library,
it only uses the InternalStorage object of the library
to store and apply the downloaded binary file.
To create the bin file for update of a SAMD board (except of M0),
use in Arduino IDE command "Export compiled binary".
To create a bin file for AVR boards see the instructions in README.MD.
To try this example, you should have a web server where you put
the binary update.
Modify the constants below to match your configuration.
Created for ArduinoOTA library in February 2020
by Juraj Andrassy
*/
#include <ArduinoOTA.h> // only for InternalStorage
#include <Ethernet.h>
#include <ArduinoHttpClient.h>
const short VERSION = 1;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
#ifdef ARDUINO_SAM_ZERO // M0
#define Serial SerialUSB
#endif
void handleSketchDownload() {
const char* SERVER = "deletethis.info"; // must be string for HttpClient
const unsigned short SERVER_PORT = 80;
const char* PATH = "/updateblink/blink.bin";
const unsigned long CHECK_INTERVAL = 5000;
static unsigned long previousMillis;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis < CHECK_INTERVAL)
return;
previousMillis = currentMillis;
EthernetClient transport;
HttpClient client(transport, SERVER, SERVER_PORT);
char buff[32];
snprintf(buff, sizeof(buff), PATH, VERSION + 1);
Serial.print("Check for update file ");
Serial.println(buff);
client.get(buff);
int statusCode = client.responseStatusCode();
Serial.print("Update status code: ");
Serial.println(statusCode);
if (statusCode != 200) {
client.stop();
return;
}
long length = client.contentLength();
if (length == HttpClient::kNoContentLengthHeader) {
client.stop();
Serial.println("Server didn't provide Content-length header. Can't continue with update.");
return;
}
Serial.print("Server returned update file of size ");
Serial.print(length);
Serial.println(" bytes");
if (!InternalStorage.open(length)) {
client.stop();
Serial.println("There is not enough space to store the update. Can't continue with update.");
return;
}
byte b;
while (length > 0) {
if (!client.readBytes(&b, 1)) // reading a byte with timeout
break;
InternalStorage.write(b);
length--;
}
InternalStorage.close();
client.stop();
if (length > 0) {
Serial.print("Timeout downloading update file at ");
Serial.print(length);
Serial.println(" bytes. Can't continue with update.");
return;
}
Serial.println("Sketch update apply and reset.");
Serial.flush();
InternalStorage.apply(); // this doesn't return
}
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.print("Sketch version ");
Serial.println(VERSION);
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while (true);
}
Serial.println("Ethernet connected");
Serial.println("setup");
Serial.println("1");
}
void loop() {
// check for updates
handleSketchDownload();
Serial.println("Loop");
Serial.println("2");
delay(1000);
// add your normal loop code below ...
}
This is the original sketch with no changes at all.
/*
This example downloads sketch update over network.
It doesn't start the OTA upload sever of the ArduinoOTA library,
it only uses the InternalStorage object of the library
to store and apply the downloaded binary file.
To create the bin file for update of a SAMD board (except of M0),
use in Arduino IDE command "Export compiled binary".
To create a bin file for AVR boards see the instructions in README.MD.
To try this example, you should have a web server where you put
the binary update.
Modify the constants below to match your configuration.
Created for ArduinoOTA library in February 2020
by Juraj Andrassy
*/
#include <ArduinoOTA.h> // only for InternalStorage
#include <Ethernet.h>
#include <ArduinoHttpClient.h>
const short VERSION = 1;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
#ifdef ARDUINO_SAM_ZERO // M0
#define Serial SerialUSB
#endif
void handleSketchDownload() {
const char* SERVER = "192.168.1.108"; // must be string for HttpClient
const unsigned short SERVER_PORT = 80;
const char* PATH = "/update-v%d.bin";
const unsigned long CHECK_INTERVAL = 5000;
static unsigned long previousMillis;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis < CHECK_INTERVAL)
return;
previousMillis = currentMillis;
EthernetClient transport;
HttpClient client(transport, SERVER, SERVER_PORT);
char buff[32];
snprintf(buff, sizeof(buff), PATH, VERSION + 1);
Serial.print("Check for update file ");
Serial.println(buff);
client.get(buff);
int statusCode = client.responseStatusCode();
Serial.print("Update status code: ");
Serial.println(statusCode);
if (statusCode != 200) {
client.stop();
return;
}
long length = client.contentLength();
if (length == HttpClient::kNoContentLengthHeader) {
client.stop();
Serial.println("Server didn't provide Content-length header. Can't continue with update.");
return;
}
Serial.print("Server returned update file of size ");
Serial.print(length);
Serial.println(" bytes");
if (!InternalStorage.open(length)) {
client.stop();
Serial.println("There is not enough space to store the update. Can't continue with update.");
return;
}
byte b;
while (length > 0) {
if (!client.readBytes(&b, 1)) // reading a byte with timeout
break;
InternalStorage.write(b);
length--;
}
InternalStorage.close();
client.stop();
if (length > 0) {
Serial.print("Timeout downloading update file at ");
Serial.print(length);
Serial.println(" bytes. Can't continue with update.");
return;
}
Serial.println("Sketch update apply and reset.");
Serial.flush();
InternalStorage.apply(); // this doesn't return
}
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.print("Sketch version ");
Serial.println(VERSION);
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while (true);
}
Serial.println("Ethernet connected");
}
void loop() {
// check for updates
handleSketchDownload();
// add your normal loop code below ...
}
I took nothing out. Was I suppose to change that version number everytime I change the code?
I'm lost on this and Not sure What I'm doing wrong. Why it keep on reseeting the setup and downloading the same bin file and installing it? Is there a way to stop that after it's got that bin file and set it up from repeating again?
%d is replaced with the version number with snprintf in the sketch so the sketch requests "update-v1.bin" if the VERSION is 1. you can change the name or rename the bin as you wish, just do some versioning
Hello jural. This is how I changed it to try to update.
const short VERSION = 3;
const char* SERVER = "192.168.1.108"; // must be string for HttpClient
const unsigned short SERVER_PORT = 80;
const char* PATH = "/blink-v3.bin";
const unsigned long CHECK_INTERVAL = 5000;
I think this way you don't need const short VERSION = 3; since you put the number directly into the file name. then you can remove the sprintf and use PATH directly
That was just an example. I haven't done it yet. I also got an error before I forgot of 300. That was the last thing I did before I shut it off. Not sure why I got that error. I'm not even sure what I'm doing wrong. Or how to even do this correctly.