working OTA
This commit is contained in:
parent
b9f10bbd30
commit
2bbce4bc8d
4
build.sh
4
build.sh
@ -3,10 +3,12 @@
|
||||
# first device connected
|
||||
|
||||
idf.py -DROLE=SENDER build
|
||||
|
||||
cp build/wellhub.bin /var/www/esp_ota
|
||||
|
||||
ret_val=$?
|
||||
|
||||
if (($ret_val != 0)); then
|
||||
exit
|
||||
fi
|
||||
|
||||
cp build/wellhub.bin /var/www/esp_ota
|
||||
|
||||
10
main/App.cpp
10
main/App.cpp
@ -6,8 +6,8 @@
|
||||
#include "Settings.h"
|
||||
#include "errors.h"
|
||||
|
||||
#include "ProvisionSoftAP.h"
|
||||
#include "OTA.h"
|
||||
#include "ProvisionSoftAP.h"
|
||||
|
||||
#define LED_PIN 26
|
||||
|
||||
@ -27,7 +27,7 @@ void App::init()
|
||||
if(SETTINGS.wifi.num > 0)
|
||||
{
|
||||
// try connecting
|
||||
m_led->setPulse(0, 255, 0);
|
||||
m_led->setColor(0, 255, 0);
|
||||
uint32_t status = m_wifi->start();
|
||||
if(status == WH_OK)
|
||||
{
|
||||
@ -42,15 +42,17 @@ void App::init()
|
||||
ProvisionSoftAP provision(80);
|
||||
provision.start();
|
||||
}
|
||||
OTA ota;
|
||||
|
||||
ota_update::OTA ota(*this);
|
||||
ota.start();
|
||||
m_led->setColor(0, 0, 0);
|
||||
}
|
||||
|
||||
void App::start()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||
vTaskDelay(pdMS_TO_TICKS(10020));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,9 +12,11 @@
|
||||
class App
|
||||
{
|
||||
protected:
|
||||
Led * m_led = nullptr;
|
||||
Wifi * m_wifi = nullptr;
|
||||
|
||||
public:
|
||||
Led * m_led = nullptr;
|
||||
|
||||
public:
|
||||
App();
|
||||
void init();
|
||||
|
||||
41
main/OTA.cpp
41
main/OTA.cpp
@ -4,24 +4,29 @@
|
||||
* Created on: Apr 23, 2019
|
||||
* Author: miro
|
||||
*/
|
||||
#include "App.h"
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_ota_ops.h"
|
||||
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "esp_partition.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "OTA.h"
|
||||
|
||||
#define EXAMPLE_SERVER_URL "http://192.168.1.131/wellhub.bin"
|
||||
|
||||
#define OTA_URL "http://192.168.1.131/wellhub.bin"
|
||||
|
||||
static const char *TAG = "OTA";
|
||||
|
||||
#define _FORCE_UPDATE
|
||||
namespace ota_update
|
||||
{
|
||||
|
||||
OTA::OTA()
|
||||
OTA::OTA(App & app) : m_app(app)
|
||||
{
|
||||
|
||||
}
|
||||
@ -66,7 +71,7 @@ void OTA::start()
|
||||
running->address);
|
||||
|
||||
esp_http_client_config_t config = { };
|
||||
config.url = EXAMPLE_SERVER_URL;
|
||||
config.url = OTA_URL;
|
||||
|
||||
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||
if (client == NULL)
|
||||
@ -82,6 +87,10 @@ void OTA::start()
|
||||
}
|
||||
esp_http_client_fetch_headers(client);
|
||||
|
||||
int remote_len = esp_http_client_get_content_length(client);
|
||||
|
||||
ESP_LOGI(TAG,"remote len %d", remote_len);
|
||||
|
||||
update_partition = esp_ota_get_next_update_partition(NULL);
|
||||
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x", update_partition->subtype,
|
||||
update_partition->address);
|
||||
@ -102,7 +111,7 @@ void OTA::start()
|
||||
}
|
||||
else if (data_read > 0)
|
||||
{
|
||||
printf(".");
|
||||
//printf(".");
|
||||
if (image_header_was_checked == false)
|
||||
{
|
||||
// this is the first 1k of received image
|
||||
@ -157,14 +166,17 @@ void OTA::start()
|
||||
#ifndef FORCE_UPDATE
|
||||
if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version) + sizeof(new_app_info.project_name) + sizeof(new_app_info.time) + sizeof(new_app_info.date)) == 0)
|
||||
{
|
||||
ESP_LOGW(TAG, "Current running version is the same as a new. We will not continue the update.");
|
||||
ESP_LOGW(TAG, "Current running version is the same as a remote. No need for update.");
|
||||
httpCleanup(client);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
m_app.m_led->setPulse(255, 0, 255);
|
||||
|
||||
image_header_was_checked = true;
|
||||
|
||||
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
|
||||
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
|
||||
@ -175,10 +187,11 @@ void OTA::start()
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "received package is not fit len");
|
||||
ESP_LOGE(TAG, "received package does not fit len");
|
||||
httpCleanup(client);
|
||||
taskFatalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = esp_ota_write(update_handle, (const void *) otaWriteData, data_read);
|
||||
@ -188,7 +201,16 @@ void OTA::start()
|
||||
taskFatalError();
|
||||
}
|
||||
binary_file_length += data_read;
|
||||
ESP_LOGD(TAG, "Written image length %d", binary_file_length);
|
||||
|
||||
int progress = binary_file_length*100/remote_len;
|
||||
static int last_reported = -1;
|
||||
|
||||
if(last_reported != progress)
|
||||
{
|
||||
last_reported = progress;
|
||||
ESP_LOGI(TAG, "%d%%", last_reported);
|
||||
}
|
||||
|
||||
}
|
||||
else if (data_read == 0)
|
||||
{
|
||||
@ -208,6 +230,8 @@ void OTA::start()
|
||||
taskFatalError();
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "esp_ota_end");
|
||||
|
||||
err = esp_ota_set_boot_partition(update_partition);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
@ -223,3 +247,4 @@ void OTA::start()
|
||||
OTA::~OTA()
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -12,8 +12,12 @@
|
||||
#define BUFFSIZE 1024
|
||||
#define HASH_LEN 32 /* SHA-256 digest length */
|
||||
|
||||
namespace ota_update
|
||||
{
|
||||
#include "App.h"
|
||||
#include "esp_http_client.h"
|
||||
|
||||
|
||||
class OTA
|
||||
{
|
||||
public:
|
||||
@ -22,13 +26,15 @@ public:
|
||||
private:
|
||||
char otaWriteData[BUFFSIZE + 1] = { 0 };
|
||||
void httpCleanup(esp_http_client_handle_t client);
|
||||
App & m_app;
|
||||
|
||||
private:
|
||||
void taskFatalError();
|
||||
|
||||
public:
|
||||
OTA();
|
||||
OTA(App & app);
|
||||
virtual ~OTA();
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __OTA_H__ */
|
||||
17
ota.sh
Executable file
17
ota.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# first device connected
|
||||
|
||||
idf.py clean
|
||||
idf.py -DROLE=SENDER build
|
||||
|
||||
ret_val=$?
|
||||
|
||||
if (($ret_val != 0)); then
|
||||
exit
|
||||
fi
|
||||
|
||||
cp build/wellhub.bin /var/www/esp_ota
|
||||
|
||||
idf.py -p /dev/ttyUSB1 monitor -B 450000
|
||||
|
||||
@ -586,7 +586,7 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y
|
||||
|
||||
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4584
|
||||
CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
|
||||
@ -1452,7 +1452,7 @@ CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y
|
||||
# CONFIG_ESP32S2_PANIC_GDBSTUB is not set
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=4584
|
||||
# CONFIG_CONSOLE_UART_DEFAULT is not set
|
||||
CONFIG_CONSOLE_UART_CUSTOM=y
|
||||
# CONFIG_ESP_CONSOLE_UART_NONE is not set
|
||||
|
||||
@ -45,7 +45,7 @@ CONFIG_ENABLE_ARDUINO_DEPENDS=y
|
||||
CONFIG_ARDUINO_RUN_CORE1=y
|
||||
# CONFIG_ARDUINO_RUN_NO_AFFINITY is not set
|
||||
CONFIG_ARDUINO_RUNNING_CORE=1
|
||||
CONFIG_ARDUINO_LOOP_STACK_SIZE=8192
|
||||
CONFIG_ARDUINO_LOOP_STACK_SIZE=1024
|
||||
# CONFIG_ARDUINO_EVENT_RUN_CORE0 is not set
|
||||
CONFIG_ARDUINO_EVENT_RUN_CORE1=y
|
||||
# CONFIG_ARDUINO_EVENT_RUN_NO_AFFINITY is not set
|
||||
@ -586,7 +586,7 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y
|
||||
|
||||
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=35840
|
||||
CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user