Added and integrated bmp280 temperature sensor
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
// ProjectIncludes
|
||||
// All include files that are provided by the project
|
||||
#include "esp_event.h"
|
||||
#include "esp_http_client.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -65,6 +66,9 @@ class ota
|
||||
|
||||
static const uint32_t checkInterval_ms = 10000;
|
||||
|
||||
typedef void (*updateStatusCallback)(int);
|
||||
static updateStatusCallback usCallback;
|
||||
|
||||
// Class Constructor
|
||||
ota();
|
||||
|
||||
@@ -79,7 +83,8 @@ class ota
|
||||
// Private Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
private:
|
||||
int imageSize;
|
||||
static bool updateActive;
|
||||
static int imageSize;
|
||||
static void eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data);
|
||||
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "esp_crt_bundle.h"
|
||||
#include "esp_https_ota.h"
|
||||
#include "esp_http_client.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
@@ -50,10 +51,12 @@
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ota::updateStatusCallback ota::usCallback = NULL;
|
||||
int ota::imageSize = 0;
|
||||
bool ota::updateActive = false;
|
||||
ota::ota()
|
||||
{
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ESP_HTTPS_OTA_EVENT, ESP_EVENT_ANY_ID, &eventHandler, NULL));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +107,10 @@ void ota::eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id,
|
||||
LOGGER_INFO("OTA aborted");
|
||||
break;
|
||||
}
|
||||
if (usCallback != NULL)
|
||||
{
|
||||
usCallback(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,30 +125,33 @@ void ota::task(void)
|
||||
config.timeout_ms = 60000;
|
||||
config.keep_alive_enable = true;
|
||||
config.crt_bundle_attach = esp_crt_bundle_attach;
|
||||
// config.event_handler = eventHandler;
|
||||
esp_https_ota_config_t ota_config =
|
||||
{
|
||||
.http_config = &config,
|
||||
.http_client_init_cb = NULL,
|
||||
.bulk_flash_erase = true,
|
||||
.partial_http_download = false,
|
||||
.max_http_request_size = 4096,
|
||||
.max_http_request_size = 0,
|
||||
};
|
||||
|
||||
LOGGER_INFO("OTA task executing");
|
||||
|
||||
|
||||
// First try to download specific firmware
|
||||
config.url = "http://10.10.1.32:8989/code.bin";
|
||||
config.url = "https://esp.vbchaos.nl/code.bin";
|
||||
LOGGER_INFO("Trying URL %s", config.url);
|
||||
|
||||
err = esp_https_ota_begin(&ota_config, &https_ota_handle);
|
||||
if(err != ESP_OK)
|
||||
|
||||
updateActive = false;
|
||||
{
|
||||
LOGGER_ERROR("OTA connection failed");
|
||||
esp_https_ota_abort(https_ota_handle);
|
||||
|
||||
// No specific firmware found, try generic firmware
|
||||
config.url = "http://10.10.1.32:8989/code.bin";
|
||||
config.url = "https://esp.vbchaos.nl/code.bin";
|
||||
LOGGER_INFO("Trying URL %s", config.url);
|
||||
|
||||
err = esp_https_ota_begin(&ota_config, &https_ota_handle);
|
||||
@@ -165,6 +175,18 @@ void ota::task(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
LOGGER_INFO("App description: Magicword: %i", app_desc.magic_word);
|
||||
LOGGER_INFO("App description: SecureVer: %i", app_desc.secure_version);
|
||||
LOGGER_INFO("App description: version: %s", app_desc.version);
|
||||
LOGGER_INFO("App description: PrjctName: %s", app_desc.project_name);
|
||||
LOGGER_INFO("App description: Time: %s", app_desc.time);
|
||||
LOGGER_INFO("App description: Date: %s", app_desc.date);
|
||||
LOGGER_INFO("App description: IDF Ver: %s", app_desc.idf_ver);
|
||||
LOGGER_INFO("App description: SHA256 %s", app_desc.app_elf_sha256);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(err == ESP_OK)
|
||||
@@ -180,4 +202,46 @@ void ota::task(void)
|
||||
}
|
||||
}
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
esp_err_t otaStatus;
|
||||
|
||||
do
|
||||
{
|
||||
// esp_https_ota_perform returns after every read operation which gives user the ability to
|
||||
// monitor the status of OTA upgrade by calling esp_https_ota_get_image_len_read, which gives length of image
|
||||
// data read so far.
|
||||
//Logger_log("Image bytes read: %d", esp_https_ota_get_image_len_read(https_ota_handle));
|
||||
otaStatus = esp_https_ota_perform(https_ota_handle);
|
||||
} while(otaStatus == ESP_ERR_HTTPS_OTA_IN_PROGRESS);
|
||||
|
||||
if(!esp_https_ota_is_complete_data_received(https_ota_handle))
|
||||
{
|
||||
// the OTA image was not completely received and user can customise the response to this situation.
|
||||
LOGGER_ERROR("Complete data was not received.");
|
||||
err = ESP_FAIL;
|
||||
esp_https_ota_abort(https_ota_handle);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
err = esp_https_ota_finish(https_ota_handle);
|
||||
|
||||
if(err != ESP_OK)
|
||||
{
|
||||
LOGGER_ERROR("Image validation failed, image is corrupted");
|
||||
}
|
||||
}
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
LOGGER_SUCCESS("OTA upgrade successful");
|
||||
|
||||
LOGGER_INFO("Rebooting");
|
||||
vTaskDelay(100);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user