started working on OTA but downloading files is not functional yet

This commit is contained in:
Matthias Mitscherlich
2024-03-22 17:33:53 +01:00
parent 0fcd60ff57
commit 55c3ebbbe4
10 changed files with 531 additions and 219 deletions
+1
View File
@@ -19,6 +19,7 @@ idf_component_register(
"application/src/clockwordmap.cpp"
"application/src/daywordmap.cpp"
"application/src/wordmap.cpp"
"application/src/ota.cpp"
# "old/src/temperaturewordmap.cpp"
# "old/src/temperature.cpp"
INCLUDE_DIRS # optional, add here public include directories
+90
View File
@@ -0,0 +1,90 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ota.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_APPLICATION_INC_OTA_H_
#define MAIN_APPLICATION_INC_OTA_H_
/**
* ota implementation
* \defgroup ota
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <stdint.h>
// ProjectIncludes
// All include files that are provided by the project
#include "esp_event.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class ota
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
static const uint32_t checkInterval_ms = 10000;
// Class Constructor
ota();
void task(void);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
int imageSize;
static void eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data);
};
/** @} */
#endif /* MAIN_APPLICATION_INC_OTA_H_ */
+183
View File
@@ -0,0 +1,183 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ota.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <ota.h>
#include "esp_crt_bundle.h"
#include "esp_https_ota.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
ota::ota()
{
}
void ota::eventHandler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
if(event_base == ESP_HTTPS_OTA_EVENT)
{
switch(event_id)
{
case ESP_HTTPS_OTA_START:
LOGGER_INFO("OTA started");
break;
case ESP_HTTPS_OTA_CONNECTED:
LOGGER_INFO("Connected to server");
break;
case ESP_HTTPS_OTA_GET_IMG_DESC:
LOGGER_INFO("Reading image description");
break;
case ESP_HTTPS_OTA_VERIFY_CHIP_ID:
LOGGER_INFO("Verifying chip id of new image: %d", *(esp_chip_id_t *)event_data);
break;
case ESP_HTTPS_OTA_DECRYPT_CB:
LOGGER_INFO("Callback to decrypt function");
break;
case ESP_HTTPS_OTA_WRITE_FLASH:
{
int written = *(int *)event_data;
LOGGER_INFO("Writing to flash: %d written", written);
// ledRing->ledOn(((ledRing->nrOfLeds - 1) * written) / imageSize);
break;
}
case ESP_HTTPS_OTA_UPDATE_BOOT_PARTITION:
LOGGER_INFO("Boot partition updated. Next Partition: %d", *(esp_partition_subtype_t*)event_data);
break;
case ESP_HTTPS_OTA_FINISH:
LOGGER_INFO("OTA finished");
break;
case ESP_HTTPS_OTA_ABORT:
LOGGER_INFO("OTA aborted");
break;
}
}
}
void ota::task(void)
{
esp_err_t err = ESP_OK;
esp_https_ota_handle_t https_ota_handle = NULL;
static esp_http_client_config_t config;
esp_app_desc_t app_desc;
config.timeout_ms = 60000;
config.keep_alive_enable = true;
config.crt_bundle_attach = esp_crt_bundle_attach;
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,
};
LOGGER_INFO("OTA task executing");
// First try to download specific firmware
config.url = "http://10.10.1.32:8989/code.bin";
LOGGER_INFO("Trying URL %s", config.url);
err = esp_https_ota_begin(&ota_config, &https_ota_handle);
if(err != ESP_OK)
{
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";
LOGGER_INFO("Trying URL %s", config.url);
err = esp_https_ota_begin(&ota_config, &https_ota_handle);
if(err != ESP_OK)
{
LOGGER_ERROR("OTA connection failed");
esp_https_ota_abort(https_ota_handle);
}
}
if(err == ESP_OK)
{
err = esp_https_ota_get_img_desc(https_ota_handle, &app_desc);
if(err != ESP_OK)
{
LOGGER_ERROR("Failed to read image header");
esp_https_ota_abort(https_ota_handle);
}
}
if(err == ESP_OK)
{
imageSize = esp_https_ota_get_image_size(https_ota_handle);
LOGGER_INFO("Image is %d bytes large", imageSize);
if(imageSize == -1)
{
err = ESP_FAIL;
esp_https_ota_abort(https_ota_handle);
}
}
}
+29 -2
View File
@@ -42,6 +42,7 @@
#include "clock.h"
#include "clockwordmap.h"
#include "daywordmap.h"
#include "ota.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
@@ -77,11 +78,13 @@
static TaskHandle_t loggerTaskHandle;
static TaskHandle_t otaTaskHandle;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
void loggerTask(void* parameters);
void otaTask(void* parameters);
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
@@ -179,18 +182,31 @@ extern "C" void app_main(void)
// -----------------------------------------------------------------------------------------------------------------
// Programmable LEDs in a strip
//
ledmatrix matrix = ledmatrix(MATRIX_NMBR_ROWS, MATRIX_NMBR_COLUMS, GPIO_LED_STRIP);
// Set the matrix orientation to ROW-based, from left to right, beginning on the upside
matrix.setOrientation(ledmatrix::ORIENTATION_ROW_LEFT_UP);
// -----------------------------------------------------------------------------------------------------------------
// The clock which also handles the NTP
//
Clock clk = Clock(Clock::Mode_t::TEN_BEFORE_HALF);
// -----------------------------------------------------------------------------------------------------------------
// Wordmaps for clock(time), clock(day) and temperature
//
ClockWordmap clockwords = ClockWordmap(&matrix);
clockwords.setColour(0x80, 0x40, 0xFF);
DayWordmap daywords = DayWordmap(&matrix);
daywords.setColour(0xFF, 0x00, 0x80);
Clock clk = Clock(Clock::Mode_t::TEN_BEFORE_HALF);
// -----------------------------------------------------------------------------------------------------------------
// OTA handler
//
ota otaUpdater = ota();
// Call the OTA executable within a dedicated task and forget about it afterwards
xTaskCreate(otaTask, (const char*)"OTATask", 4000, &otaUpdater, 3, &otaTaskHandle);
std::list<std::string> clockWordlist;
@@ -223,3 +239,14 @@ void loggerTask(void* parameters)
vTaskDelay(10);
}
}
void otaTask(void* parameters)
{
ota* otaHandler = (ota*) parameters;
while (1)
{
otaHandler->task();
vTaskDelay(otaHandler->checkInterval_ms);
}
}
+18 -5
View File
@@ -67,17 +67,30 @@ class prgm_ledstrip
struct pixel
{
uint32_t index;
uint8_t red;
uint8_t green;
uint8_t blue;
uint32_t index;
union
{
struct
{
uint8_t red;
uint8_t green;
uint8_t blue;
} rgb;
struct
{
uint16_t hue;
uint8_t saturation;
uint8_t value;
} hsv;
};
};
// Class Constructor
prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio);
// Set and clear functions only update the pixel value(s) locally but do not push the values to the strip
FunctionStatus setPixel(struct pixel& pixel);
FunctionStatus setPixelRGB(struct pixel& pixel);
FunctionStatus setPixelHSV(struct pixel& pixel);
FunctionStatus clearAll(void);
// Clears all pixels locally and automatically pushes the values to the strip
+4 -4
View File
@@ -81,10 +81,10 @@ FunctionStatus ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, u
{
struct pixel p;
p.index = index;
p.red = red;
p.green = green;
p.blue = blue;
returnValue = prgm_ledstrip::setPixel(p);
p.rgb.red = red;
p.rgb.green = green;
p.rgb.blue = blue;
returnValue = prgm_ledstrip::setPixelRGB(p);
}
return returnValue;
+18 -2
View File
@@ -71,13 +71,29 @@ prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLED
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
}
FunctionStatus prgm_ledstrip::setPixel(struct pixel& pixel)
FunctionStatus prgm_ledstrip::setPixelRGB(struct pixel& pixel)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
if (pixel.index < numberOfLEDs)
{
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue));
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.rgb.red, pixel.rgb.green, pixel.rgb.blue));
}
else
{
returnValue = FUNCTION_STATUS_ERROR;
}
return returnValue;
}
FunctionStatus prgm_ledstrip::setPixelHSV(struct pixel& pixel)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
if (pixel.index < numberOfLEDs)
{
ESP_ERROR_CHECK(led_strip_set_pixel_hsv(led_strip, pixel.index, pixel.hsv.hue, pixel.hsv.saturation, pixel.hsv.value));
}
else
{
+4 -3
View File
@@ -47,9 +47,10 @@
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static const char* ssid = "Kowalski";
static const char* pass = "madagascar";
static const char* ssid = "Skipper";
static const char* pass = "w00t/?YeP";
//static const char* ssid = "Kowalski";
//static const char* pass = "madagascar";
//static const char* ssid = "vbchaos";
//static const char* pass = "mijninternet";