Skip to content

Commit

Permalink
OTA written and compiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D.Smith committed Dec 17, 2023
1 parent ea6923e commit 68fa8f7
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 263 deletions.
25 changes: 23 additions & 2 deletions esp32/cloudsmets/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,35 @@ menu "CloudSMETS"

menu "OTA"

config CS_OTA_SERVER_URL
config CS_OTA_ENABLED
int "OTA enabled (recommend on!)"
range 0 1
default 1
help
Whether OTA functionality is enabled.

config CS_OTA_DEV_IMAGES
int "Development images permitted"
range 0 1
default 0
help
Whether OTA should consider developmemt images; recommend 'No' (0).

config CS_OTA_REVISION_SERVER_URL
string "OTA latest-revision server URL"
default "https://cloudsmets.azurewebsites.net/api/LatestRevision"
help
Server that identifies the latest suitable CloudSMETS version.

config CS_OTA_IMAGE_SERVER_URL
string "OTA image server URL"
default "https://cloudsmets.blob.core.windows.net/cloudsmets/"
help
Server from which OTA images are downloaded.

config CS_OTA_ACCEPT
int "OTA acceptence period"
int "OTA acceptence period (minutes)"
range 1 720
default 60
help
Time, in minutes, that an image must run before being accepted.
Expand Down
36 changes: 23 additions & 13 deletions esp32/cloudsmets/main/cs_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ const char* TAG = "Cfg";
#define CS_WIFI_AP_CHANNEL CONFIG_CS_WIFI_AP_CHANNEL
#define CS_WIFI_AP_SSID CONFIG_CS_WIFI_AP_SSID
#define CS_WIFI_AP_PWD CONFIG_CS_WIFI_AP_PWD

#define CS_WEB_LISTEN_PORT CONFIG_CS_WEB_LISTEN_PORT

#define CS_OTA_ENABLED CONFIG_CS_OTA_ENABLED
#define CS_OTA_DEV_IMAGES CONFIG_CS_OTA_DEV_IMAGES
#define CS_OTA_REVISION_SERVER_URL CONFIG_CS_OTA_REVISION_SERVER_URL
#define CS_OTA_IMAGE_SERVER_URL CONFIG_CS_OTA_IMAGE_SERVER_URL
#define CS_OTA_ACCEPT CONFIG_CS_OTA_ACCEPT
#define CS_OTA_SERVER_URL CONFIG_CS_OTA_SERVER_URL

/**
* @brief Ethernet event base definition
Expand Down Expand Up @@ -85,11 +90,12 @@ const char cs_cfg_web_pwd[] = "webPwd";
/*
* OTA, Over-the-air upgrade configuration.
*/
const char cs_cfg_ota_func[] = "otaFunc";
const char cs_cfg_ota_image[] = "otaImage";
const char cs_cfg_ota_accept[] = "otaAccept";
const char cs_cfg_ota_url[] = "otaUrl";
const char cs_cfg_ota_ena[] = "otaEna";
const char cs_cfg_ota_dev[] = "otaDev";
const char cs_cfg_ota_rel[] = "otaRel";
const char cs_cfg_ota_rev_url[] = "otaRevUrl";
const char cs_cfg_ota_img_url[] = "otaImgUrl";
const char cs_cfg_ota_accept[] = "otaAccept";

// /*
// * Azure
Expand Down Expand Up @@ -131,9 +137,12 @@ const cs_cfg_definitions_t cs_cfg_web_definitions[] =

const cs_cfg_definitions_t cs_cfg_ota_definitions[] =
{
{ CS_CFG_KEY_OTA_FUNC, NVS_TYPE_U8, -1 },
{ CS_CFG_KEY_OTA_URL, NVS_TYPE_STR, 256 },
{ CS_CFG_KEY_OTA_REL, NVS_TYPE_STR, 16 },
{ CS_CFG_KEY_OTA_ENA, NVS_TYPE_U8, -1 },
{ CS_CFG_KEY_OTA_DEV, NVS_TYPE_U8, -1 },
{ CS_CFG_KEY_OTA_REL, NVS_TYPE_STR, 256 },
{ CS_CFG_KEY_OTA_REV_URL, NVS_TYPE_STR, 256 },
{ CS_CFG_KEY_OTA_IMG_URL, NVS_TYPE_STR, 256 },
{ CS_CFG_KEY_OTA_ACCEPT, NVS_TYPE_U16, -1 },
{ NULL, NVS_TYPE_ANY, -1 }
};

Expand Down Expand Up @@ -305,12 +314,13 @@ static void cs_cfg_default(void)

// OTA.
#define OTA_ENABLED 1
#define OTA_IMAGE_PROD_ONLY 0
cs_cfg_default_uint8(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_FUNC, OTA_ENABLED);
cs_cfg_default_uint8(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_IMAGE, OTA_IMAGE_PROD_ONLY);
cs_cfg_default_uint32(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_ACCEPT, CS_OTA_ACCEPT);
cs_cfg_default_str(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_URL, CS_OTA_SERVER_URL);
#define OTA_IMAGE_PROD_ONLY 1
cs_cfg_default_uint8(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_ENA, CS_OTA_ENABLED);
cs_cfg_default_uint8(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_DEV, CS_OTA_DEV_IMAGES);
cs_cfg_default_str(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_REL, "");
cs_cfg_default_str(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_REV_URL, CS_OTA_REVISION_SERVER_URL);
cs_cfg_default_str(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_IMG_URL, CS_OTA_IMAGE_SERVER_URL);
cs_cfg_default_uint16(CS_CFG_NMSP_OTA, CS_CFG_KEY_OTA_ACCEPT, CS_OTA_ACCEPT);
}

void cs_cfg_init(void)
Expand Down
19 changes: 11 additions & 8 deletions esp32/cloudsmets/main/cs_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ extern const char cs_cfg_web_port[];
// extern const char cfg_log_ip_port[];
// extern const char cfg_log_esp32c3[];
// extern const char cfg_log_tlsr8258[];
extern const char cs_cfg_ota_func[];
extern const char cs_cfg_ota_image[];
extern const char cs_cfg_ota_accept[];
extern const char cs_cfg_ota_url[];
extern const char cs_cfg_ota_ena[];
extern const char cs_cfg_ota_rel[];
extern const char cs_cfg_ota_dev[];
extern const char cs_cfg_ota_rev_url[];
extern const char cs_cfg_ota_img_url[];
extern const char cs_cfg_ota_accept[];
// extern const char cfgAzFunc[];
// extern const char cfgAzIotHub[];
// extern const char cfgAzDevice[];
Expand All @@ -75,11 +76,13 @@ extern const char cs_cfg_ota_rel[];
// #define CS_CFG_KEY_DBG_IP_PORT cfgDbgIpPort
// #define CS_CFG_KEY_DBG_ESP32C3 cfgDbgEsp32c3
// #define CS_CFG_KEY_DBG_TLSR8258 cfgDbgTlsr8258
#define CS_CFG_KEY_OTA_FUNC cs_cfg_ota_func
#define CS_CFG_KEY_OTA_IMAGE cs_cfg_ota_image
#define CS_CFG_KEY_OTA_ACCEPT cs_cfg_ota_accept
#define CS_CFG_KEY_OTA_URL cs_cfg_ota_url
#define CS_CFG_KEY_OTA_ENA cs_cfg_ota_ena
#define CS_CFG_KEY_OTA_DEV cs_cfg_ota_dev
#define CS_CFG_KEY_OTA_REL cs_cfg_ota_rel
#define CS_CFG_KEY_OTA_IMG_URL cs_cfg_ota_img_url
#define CS_CFG_KEY_OTA_REV_URL cs_cfg_ota_rev_url
#define CS_CFG_KEY_OTA_ACCEPT cs_cfg_ota_accept

// #define CS_CFG_KEY_AZURE_FUNC cfgAzFunc
// #define CS_CFG_KEY_AZURE_IOTHUB cfgAzIotHub
// #define CS_CFG_KEY_AZURE_DEVICE cfgAzDevice
Expand Down
Loading

0 comments on commit 68fa8f7

Please sign in to comment.