ESP32-Mesh-OTA/components/mesh_ota/include/Mesh_OTA.h

58 lines
2.2 KiB
C

#ifndef H_MESH_OTA
#define H_MESH_OTA
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_mesh.h"
#include "esp_mesh_internal.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "Mesh_network.h"
#include "HTTPS_client.h"
#define ERASE_NVS //erase non volatile storage if full
#define QUEUE_NODES_SIZE 10
#define QUEUE_MESSAGE_OTA_SIZE 10
#define SERVER_CHECK_INTERVAL 30 //in seconds
#define OTA_HTTPS_SEGMENT_SIZE 2048U
#define OTA_PROGRESS_LOG_INTERVAL 7U
#define ERROR_CHECK(x) if (err == ESP_OK) \
{ \
err = (x); \
if (err != ESP_OK) \
{ \
ESP_LOGE(LOG_TAG, "%s failed with error: 0x%x -> %s", #x, err, esp_err_to_name(err)); \
} \
} \
esp_err_t errMeshOTAInitialize();
esp_err_t errOTAHTTPS(bool* pbNewOTAImage);
//helper functions
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten);
void vAddAllNeighboursToQueue(void);
//Handler
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC);
void vAddOTAControllMessageToQueue(MESH_PACKET_t* puMeshPacket);
void vChangeStateOfServerWorker(bool state);
//Tasks
void vTaskServerWorker(void *arg);
void vTaskOTAWorker(void *arg);
#endif /* H_MESH_OTA */