cleanup
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
idf_component_register(SRCS "https_client.c" "mesh_ota.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES nvs_flash
|
||||
esp_http_client bootloader_support
|
||||
PRIV_REQUIRES log app_update
|
||||
)
|
||||
esp_http_client
|
||||
bootloader_support
|
||||
app_update
|
||||
log)
|
||||
|
@ -8,6 +8,7 @@ static const char *REQUEST = "GET " CONFIG_OTA_HTTPS_URL " HTTP/1.1\r\n"
|
||||
"Authorization: Basic " CONFIG_OTA_HTTPS_AUTH "\r\n"
|
||||
"\r\n";
|
||||
|
||||
|
||||
static HTTPS_Client_t sHTTPS_ClientConfig;
|
||||
|
||||
https_client_ret_t https_clientInitEmbedTLS();
|
||||
@ -288,41 +289,3 @@ https_client_ret_t https_clientSendRequest()
|
||||
}
|
||||
return i32RetHTTPClient;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static void https_get_task(void *pvParameters)
|
||||
{
|
||||
|
||||
https_clientInitialize();
|
||||
|
||||
uint32_t u32BufferLenght = 1024U;
|
||||
unsigned char buffer[1024U];
|
||||
uint32_t u32BytesRead = 0;
|
||||
|
||||
https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead);
|
||||
|
||||
// Print response directly to stdout as it is read
|
||||
for(uint32_t i = 0; i < u32BytesRead; i++) {
|
||||
putchar(buffer[i]);
|
||||
// printf("%x ", buffer[i]);
|
||||
}
|
||||
printf("\n END \n");
|
||||
|
||||
https_clientDeinitialize();
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK( nvs_flash_init() );
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
xTaskCreate(&https_get_task, "https_get_task", 8192, NULL, 5, NULL);
|
||||
}
|
||||
*/
|
||||
|
@ -28,11 +28,22 @@
|
||||
#include "mbedtls/certs.h"
|
||||
#include "esp_crt_bundle.h"
|
||||
|
||||
/* Constants that aren't configurable in menuconfig, yet */
|
||||
//#define CONFIG_OTA_HTTPS_SERVER_COMMON_NAME "ota.hendrikschutter.com"
|
||||
//#define CONFIG_OTA_HTTPS_SERVER_PORT "443"
|
||||
//#define CONFIG_OTA_HTTPS_URL "https://ota.hendrikschutter.com/hello-world.bin"
|
||||
//#define HTTPS_CLIENT_AUTH "b3RhOnB3" //base64("username:password")
|
||||
#ifndef CONFIG_OTA_HTTPS_URL
|
||||
#define CONFIG_OTA_HTTPS_URL "https://exmaple.com/theImage.bin"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_OTA_HTTPS_SERVER_PORT
|
||||
#define CONFIG_OTA_HTTPS_SERVER_PORT "443"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_OTA_HTTPS_AUTH
|
||||
#define CONFIG_OTA_HTTPS_AUTH "base64(user:password)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_OTA_HTTPS_SERVER_COMMON_NAME
|
||||
#define CONFIG_OTA_HTTPS_SERVER_COMMON_NAME "exmaple.com"
|
||||
#endif
|
||||
|
||||
|
||||
#define HTTPS_CLIENT_OK 0
|
||||
#define HTTPS_CLIENT_ERROR -1
|
||||
|
@ -1,144 +0,0 @@
|
||||
#include "mesh_ota.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote) {
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote) ;
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)) {
|
||||
|
||||
u8Index++;
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote) ;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
esp_err_t errFindImageStart(unsigned char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
{
|
||||
|
||||
*pu32StartOffset = 0U;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
0 = E9
|
||||
48 = erstes Digit
|
||||
|
||||
*/
|
||||
|
||||
uint32_t u32DataIndex = 0;
|
||||
|
||||
uint32_t u32FirstDotOffset = 0;
|
||||
uint32_t u32SecondDotOffset = 0;
|
||||
|
||||
uint8_t u8FirstDotIndex = 0;
|
||||
uint8_t u8SecondDotIndex = 0;
|
||||
|
||||
while((u32DataIndex < *pu32DataLenght) && (*pu32StartOffset == 0))
|
||||
{
|
||||
//search for magic byte
|
||||
u32DataIndex++;
|
||||
if(pu8Data[u32DataIndex] == 0xe9)
|
||||
{
|
||||
//magic byte found
|
||||
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
||||
{
|
||||
//search first dot in version number
|
||||
u8FirstDotIndex++;
|
||||
if((u32DataIndex+49+u8FirstDotIndex) > pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||
{
|
||||
//first do found
|
||||
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
||||
printf("First dot offset: %i\n", u32FirstDotOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((u8SecondtDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
||||
{
|
||||
u8FSecondDotIndex++;
|
||||
//search first dot in version number
|
||||
if((u32FirstDotOffset+(u8FSecondDotIndex+1)) > pu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32FirstDotOffset+(u8FSecondDotIndex+1))] == 0x2e))
|
||||
{
|
||||
//second do found
|
||||
u32SecondDotOffset = (u32FirstDotOffset+(u8FSecondDotIndex+1));
|
||||
printf("Second dot offset: %i\n", u32SecondDotOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
||||
{
|
||||
//image start found based on magic byte and version number systax
|
||||
*pu32StartOffset = u32DataIndex; //store image start offset
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is propably not the magic byte --> reset
|
||||
u32FirstDotOffset = 0;
|
||||
u32SecondDotOffset = 0;
|
||||
|
||||
u8FirstDotIndex = 0;
|
||||
u8SecondDotIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//putchar(pu8Data[i]);
|
||||
printf("%x ", pu8Data[u32DataIndex]);
|
||||
}
|
||||
|
||||
printf("\n END: %i\n", *pu32StartOffset);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t errExtractVersionNumber(unsigned char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
{
|
||||
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
|
||||
|
||||
uint32_t u32StartOffset;
|
||||
|
||||
errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset);
|
||||
|
||||
|
||||
printf("remote version number %s\n", pc8RemoteVersionNumber);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
#include <limits.h>
|
||||
#include "unity.h"
|
||||
|
||||
#include "mesh_ota.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TEST_CASE("Remote got patch", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.2.3"; //current running image
|
||||
|
Reference in New Issue
Block a user