-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ota.cpp
35 lines (32 loc) · 931 Bytes
/
Ota.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <Arduino.h>
#include "Ota.h"
#define FULL_PACKET 1436 // HTTP_UPLOAD_BUFLEN in WebServer,h
void Ota::updateFirmware(uint8_t* buf, size_t size)
{
if(!_updateStarted && size == 0)
{
Serial.println("OTA upload cancelled, size is 0.");
return;
}
if (!_updateStarted)
{ //If it's the first packet of OTA since bootup, begin OTA
Serial.println("BeginOTA");
esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN, &otaHandler);
_updateStarted = true;
}
esp_ota_write(otaHandler, buf, size);
if (size != FULL_PACKET)
{
esp_ota_end(otaHandler);
Serial.println("EndOTA");
if (ESP_OK == esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)))
{
delay(2000);
esp_restart();
}
else
{
Serial.println("Upload Error");
}
}
}