refactor #2
@ -1,4 +1,4 @@
|
|||||||
idf_component_register(SRCS "https_client.c" "Mesh_network_handler.c" "Mesh_network.c" "Mesh_OTA.c"
|
idf_component_register(SRCS "HTTPS_client.c" "Mesh_network_handler.c" "Mesh_network.c" "Mesh_OTA.c"
|
||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
REQUIRES nvs_flash
|
REQUIRES nvs_flash
|
||||||
esp_http_client
|
esp_http_client
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "https_client.h"
|
#include "HTTPS_client.h"
|
||||||
|
|
||||||
static const char *TAG = "https_client";
|
static const char *TAG = "https_client";
|
||||||
|
|
@ -48,7 +48,7 @@ esp_err_t errMeshOTAInitialize()
|
|||||||
|
|
||||||
if(err == ESP_OK)
|
if(err == ESP_OK)
|
||||||
{
|
{
|
||||||
xReturned = xTaskCreate(vTaskServerWorker, "vTaskServerWorker", 4096, NULL, 5, NULL);
|
xReturned = xTaskCreate(vTaskServerWorker, "vTaskServerWorker", 8192, NULL, 5, NULL);
|
||||||
if(xReturned != pdPASS)
|
if(xReturned != pdPASS)
|
||||||
{
|
{
|
||||||
ESP_LOGE(LOG_TAG, "Unable to create the server worker task");
|
ESP_LOGE(LOG_TAG, "Unable to create the server worker task");
|
||||||
@ -128,6 +128,18 @@ void vTaskOTAWorker(void *arg)
|
|||||||
|
|
||||||
void vTaskServerWorker(void *arg)
|
void vTaskServerWorker(void *arg)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
esp_err_t err = ESP_OK;
|
||||||
|
uint32_t u32BufferLenght = 1024U;
|
||||||
|
char buffer[1024U];
|
||||||
|
uint32_t u32BytesRead = 0;
|
||||||
|
char pcRemoteVersionNumber[12];
|
||||||
|
const esp_partition_t * currentPartition;
|
||||||
|
const esp_partition_t * otaPartition;
|
||||||
|
static esp_ota_handle_t otaHandle;
|
||||||
|
uint32_t u32StartOffset;
|
||||||
|
esp_app_desc_t otaPartitionDesc;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
xSemaphoreTake(bsStartStopServerWorker, portMAX_DELAY); //wait for binary semaphore that allows to start the worker
|
xSemaphoreTake(bsStartStopServerWorker, portMAX_DELAY); //wait for binary semaphore that allows to start the worker
|
||||||
@ -139,6 +151,71 @@ void vTaskServerWorker(void *arg)
|
|||||||
|
|
||||||
//server get version
|
//server get version
|
||||||
|
|
||||||
|
currentPartition = esp_ota_get_boot_partition();
|
||||||
|
ESP_LOGI(LOG_TAG, "Type: %d", (*currentPartition).subtype);
|
||||||
|
ESP_LOGI(LOG_TAG, "Start address: %d", (*currentPartition).address);
|
||||||
|
ESP_LOGI(LOG_TAG, "Size: %d", (*currentPartition).size);
|
||||||
|
ESP_LOGI(LOG_TAG, "Encrypted: %d", (*currentPartition).encrypted);
|
||||||
|
|
||||||
|
esp_app_desc_t curPartitionDesc;
|
||||||
|
err = esp_ota_get_partition_description(currentPartition, &curPartitionDesc);
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
ESP_LOGI(LOG_TAG, "currentPartition project_name: %s", (curPartitionDesc).project_name);
|
||||||
|
ESP_LOGI(LOG_TAG, "currentPartition version: %s", (curPartitionDesc).version);
|
||||||
|
ESP_LOGI(LOG_TAG, "currentPartition Timestamp: %s %s", (curPartitionDesc).date, (curPartitionDesc).time);
|
||||||
|
|
||||||
|
https_clientInitialize();
|
||||||
|
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||||
|
ESP_LOGI(LOG_TAG, "Data received: %i", u32BytesRead);
|
||||||
|
err = errExtractVersionNumber(buffer, &u32BytesRead, pcRemoteVersionNumber);
|
||||||
|
|
||||||
|
if(err == ESP_OK)
|
||||||
|
{
|
||||||
|
if(bNewerVersion((curPartitionDesc).version, pcRemoteVersionNumber))
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "Newer Version available");
|
||||||
|
//write ota
|
||||||
|
otaPartition= esp_ota_get_next_update_partition(currentPartition);
|
||||||
|
|
||||||
|
err = errFindImageStart(buffer, &u32BufferLenght, &u32StartOffset);
|
||||||
|
|
||||||
|
ESP_LOGI(LOG_TAG, "first byte offset: %i", u32StartOffset);
|
||||||
|
ESP_LOGI(LOG_TAG, "first byte: %x", buffer[u32StartOffset]);
|
||||||
|
|
||||||
|
err = esp_ota_begin(otaPartition, OTA_SIZE_UNKNOWN, &otaHandle);
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "OTA-Data written: %i", u32BytesRead);
|
||||||
|
err = esp_ota_write(otaHandle, (const void*) buffer+u32StartOffset, (u32BytesRead-u32StartOffset));
|
||||||
|
u32StartOffset = 0U;
|
||||||
|
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||||
|
}
|
||||||
|
while (u32BytesRead > 0);
|
||||||
|
|
||||||
|
err = esp_ota_end(otaHandle);
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
err = esp_ota_get_partition_description(otaPartition, &otaPartitionDesc);
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
ESP_LOGI(LOG_TAG, "otaPartition project_name: %s", (otaPartitionDesc).project_name);
|
||||||
|
err = esp_ota_set_boot_partition(otaPartition);
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
//esp_restart();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "NO newer Version available");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "errExtractVersionNumber failed: %i", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
https_clientDeinitialize();
|
||||||
|
|
||||||
//ota update if newer
|
//ota update if newer
|
||||||
|
|
||||||
//lock ota mutex
|
//lock ota mutex
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
|
|
||||||
#include "Mesh_network.h"
|
#include "Mesh_network.h"
|
||||||
|
#include "HTTPS_client.h"
|
||||||
|
|
||||||
#define ERASE_NVS //erase non volatile storage if full
|
#define ERASE_NVS //erase non volatile storage if full
|
||||||
#define QUEUE_NODES_SIZE 10
|
#define QUEUE_NODES_SIZE 10
|
||||||
|
@ -84,7 +84,8 @@ void vTaskReadUserInput(void *arg)
|
|||||||
meshPacket.type = APP_Data; //this is a app packet
|
meshPacket.type = APP_Data; //this is a app packet
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{ //check for BTN press
|
{
|
||||||
|
//check for BTN press
|
||||||
if(gpio_get_level(GPIO_BOOT_BTN) == 0)
|
if(gpio_get_level(GPIO_BOOT_BTN) == 0)
|
||||||
{
|
{
|
||||||
err = ESP_OK;
|
err = ESP_OK;
|
||||||
@ -173,7 +174,8 @@ void vTaskReceiveData(void *arg)
|
|||||||
memcpy(meshPacket.au8Payload, &bTmpPacket, sizeof(BLINKY_PACKET_t)); //copy led action in mesh packet payload
|
memcpy(meshPacket.au8Payload, &bTmpPacket, sizeof(BLINKY_PACKET_t)); //copy led action in mesh packet payload
|
||||||
|
|
||||||
for (uint16_t u16Index = 0; u16Index < u16ChildrenSize; u16Index++)
|
for (uint16_t u16Index = 0; u16Index < u16ChildrenSize; u16Index++)
|
||||||
{ //loop through children
|
{
|
||||||
|
//loop through children
|
||||||
if(bCheckMACEquality(bTmpPacket.meshSenderAddr.addr, childrenAddr[u16Index].addr) == false) //exclude the sender node
|
if(bCheckMACEquality(bTmpPacket.meshSenderAddr.addr, childrenAddr[u16Index].addr) == false) //exclude the sender node
|
||||||
{
|
{
|
||||||
ERROR_CHECK (errSendMeshPacket(&childrenAddr[u16Index], &meshPacket)); //send to child
|
ERROR_CHECK (errSendMeshPacket(&childrenAddr[u16Index], &meshPacket)); //send to child
|
||||||
|
15
style_code.sh
Normal file
15
style_code.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
cd main
|
||||||
|
astyle --style=gnu *.c
|
||||||
|
astyle --style=gnu *.h
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
cd components/mesh_ota
|
||||||
|
astyle --style=gnu *.c
|
||||||
|
cd include
|
||||||
|
astyle --style=gnu *.h
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user