Skip to content

Commit

Permalink
Make remote update URL a config entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAbata committed Jun 22, 2023
1 parent 591db31 commit 77f53e8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
11 changes: 10 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {
#define CONFIG_PATH_MAX 64

// This is just a default, others can be loaded after boot.
#define CONFIG_FILENAME "/config.json"
static const char* CONFIG_FILENAME = "/config.json";

// String Lengths
#define WIFI_SSID_MAX_LEN 64
Expand All @@ -23,6 +23,10 @@ extern "C" {
// #define EOM_BETA 1
#define I18N_USE_CJSON_DICT 1

// System Defaults
static const char* REMOTE_UPDATE_URL =
"http://us-central1-maustec-io.cloudfunctions.net/gh-release-embedded-bridge";

// Vibration Modes
// See vibration_mode_controller.h for more.

Expand Down Expand Up @@ -136,6 +140,11 @@ struct config {
bool edge_menu_lock;
// Deny access to menu starting after orgasm detected
bool post_orgasm_menu_lock;

//= Internal System Configuration (Update only if you know what you're doing)

// Remote update server URL. You may change this to OTA update other versions.
char* remote_update_url;
};

typedef struct config config_t;
Expand Down
28 changes: 28 additions & 0 deletions include/config_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ enum _config_def_operation {
} \
}

#define CFG_STRING_PTR(name, default) \
{ \
if (root != NULL) { \
if (operation == CFG_SET || operation == CFG_MERGE) { \
cJSON* item = cJSON_GetObjectItem(root, #name); \
if (item != NULL || operation == CFG_SET) { \
/* intentional cstring pointer comparison */ \
if (cfg->name != default) free(cfg->name); \
asiprintf(&cfg->name, "%s", item == NULL ? default : item->valuestring); \
} \
} else { \
cJSON_AddStringToObject(root, #name, cfg->name); \
} \
} else if (key != NULL && !strcasecmp(key, #name)) { \
if (operation == CFG_GET) { \
if (out_val != NULL) strlcpy(out_val, cfg->name, len); \
return true; \
} else { \
if (in_val != NULL) { \
/* intentional cstring pointer comparison */ \
if (cfg->name != default) free(cfg->name); \
asiprintf(&cfg->name, "%s", in_val); \
} \
return true; \
} \
} \
}

#define CFG_NUMBER(name, default) \
{ \
if (root != NULL) { \
Expand Down
4 changes: 0 additions & 4 deletions include/update_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ extern "C" {
#include "esp_err.h"
#include "semver.h"

#define REMOTE_UPDATE_URL \
"http://us-central1-maustec-io.cloudfunctions.net/gh-release-embedded-bridge"
#define UPDATE_FILENAME "update.bin"

enum um_update_status {
UM_UPDATE_NOT_CHECKED,
UM_UPDATE_AVAILABLE,
Expand Down
3 changes: 3 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ CONFIG_DEFS {
CFG_BOOL(edge_menu_lock, false);
CFG_NUMBER(max_clench_duration, 100);

// Internal system things, only edit if you know what you're doing.
CFG_STRING_PTR(remote_update_url, REMOTE_UPDATE_URL)

// Please just leave this here and don't ask questions.
return false;
}
10 changes: 7 additions & 3 deletions src/update_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ esp_err_t update_manager_update_from_web(um_progress_callback_t* progress_cb, vo
};

esp_http_client_config_t data_config = {
.url = REMOTE_UPDATE_URL,
.url = Config.remote_update_url,
.event_handler = _http_event_handler,
.user_data = &callback_data,
};
Expand Down Expand Up @@ -324,17 +324,21 @@ esp_err_t update_manager_check_latest_version(semver_t* version) {
.size = &size,
};

char* url = NULL;
asiprintf(&url, "%s/%s", Config.remote_update_url, "version.txt");

esp_http_client_config_t config = {
.url = REMOTE_UPDATE_URL "/version.txt",
.url = url,
.user_data = &callback_data,
.event_handler = _http_event_handler,
};

ESP_LOGI(TAG, "Checking for OTA updates: %s", REMOTE_UPDATE_URL "/version.txt");
ESP_LOGI(TAG, "Checking for OTA updates: %s", config.url);

esp_http_client_handle_t client = esp_http_client_init(&config);

esp_err_t err = esp_http_client_perform(client);
free(url);

if (err != ESP_OK) {
ESP_LOGE(TAG, "HTTP GET failed: %s", esp_err_to_name(err));
Expand Down

0 comments on commit 77f53e8

Please sign in to comment.