Skip to content

Commit

Permalink
Save some space.
Browse files Browse the repository at this point in the history
  • Loading branch information
bullestock committed Jul 4, 2024
1 parent 2e7fdfd commit 13f360e
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 63 deletions.
14 changes: 7 additions & 7 deletions frontend/esp32/main/cardcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@ void Card_cache::thread_body()
if (code != 200)
{
ESP_LOGE(TAG, "Error: Unexpected response from /v2/permissions: %d", code);
Logger::instance().log(format("Error: Unexpected response from /v2/permissions: %d", code));
//Logger::instance().log(format("Error: Unexpected response from /v2/permissions: %d", code));
continue;
}
auto root = cJSON_Parse(buffer.get());
cJSON_wrapper jw(root);
if (!root)
{
ESP_LOGE(TAG, "Error: Bad JSON from /v2/permissions: %s", buffer.get());
Logger::instance().log(format("Error: Bad JSON from /v2/permissions"));
//Logger::instance().log(format("Error: Bad JSON from /v2/permissions"));
continue;
}
if (!cJSON_IsArray(root))
{
ESP_LOGE(TAG, "Error: Response from /v2/permissions is not an array");
Logger::instance().log("Error: Response from /v2/permissions is not an array");
//Logger::instance().log("Error: Response from /v2/permissions is not an array");
continue;
}
// Create new cache
Expand All @@ -137,28 +137,28 @@ void Card_cache::thread_body()
if (!cJSON_IsObject(it))
{
ESP_LOGE(TAG, "Error: Item from /v2/permissions is not an object");
Logger::instance().log("Error: Item from /v2/permissions is not an object");
//Logger::instance().log("Error: Item from /v2/permissions is not an object");
continue;
}
auto card_id_node = cJSON_GetObjectItem(it, "card_id");
if (!cJSON_IsString(card_id_node))
{
ESP_LOGE(TAG, "Error: Item from /v2/permissions has no card_id");
Logger::instance().log("Error: Item from /v2/permissions has no card_id");
//Logger::instance().log("Error: Item from /v2/permissions has no card_id");
continue;
}
auto id_node = cJSON_GetObjectItem(it, "id");
if (!cJSON_IsNumber(id_node))
{
ESP_LOGE(TAG, "Error: Item from /v2/permissions has no id");
Logger::instance().log("Error: Item from /v2/permissions has no id");
//Logger::instance().log("Error: Item from /v2/permissions has no id");
continue;
}
auto int_id_node = cJSON_GetObjectItem(it, "int_id");
if (!cJSON_IsNumber(int_id_node))
{
ESP_LOGE(TAG, "Error: Item from /v2/permissions has no int_id");
Logger::instance().log("Error: Item from /v2/permissions has no int_id");
//Logger::instance().log("Error: Item from /v2/permissions has no int_id");
continue;
}
const auto card_id = get_id_from_string(card_id_node->valuestring);
Expand Down
22 changes: 11 additions & 11 deletions frontend/esp32/main/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static void on_got_ip(void* arg, esp_event_base_t event_base,
{
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
if (!is_our_netif(TAG, event->esp_netif)) {
ESP_LOGW(TAG, "Got IPv4 from another interface \"%s\": ignored", esp_netif_get_desc(event->esp_netif));
//ESP_LOGW(TAG, "Got IPv4 from another interface \"%s\": ignored", esp_netif_get_desc(event->esp_netif));
return;
}
ESP_LOGI(TAG, "Got IPv4 event: Interface \"%s\" address: " IPSTR, esp_netif_get_desc(event->esp_netif), IP2STR(&event->ip_info.ip));
//ESP_LOGI(TAG, "Got IPv4 event: Interface \"%s\" address: " IPSTR, esp_netif_get_desc(event->esp_netif), IP2STR(&event->ip_info.ip));
memcpy(&s_ip_addr, &event->ip_info.ip, sizeof(s_ip_addr));
xSemaphoreGive(s_semph_get_ip_addrs);
}
Expand All @@ -68,30 +68,30 @@ bool connect(const wifi_creds_t& creds)
int index = 0;
s_esp_netif = wifi_start(creds[index].first, creds[index].second);
ESP_ERROR_CHECK(esp_register_shutdown_handler(&wifi_stop));
ESP_LOGI(TAG, "Waiting for IP");
//ESP_LOGI(TAG, "Waiting for IP");
while (!xSemaphoreTake(s_semph_get_ip_addrs, 10000/portTICK_PERIOD_MS))
{
ESP_LOGI(TAG, "Failed to connect");
//ESP_LOGI(TAG, "Failed to connect");
wifi_stop();
++index;
if (index >= creds.size())
return false;
ESP_LOGI(TAG, "Trying next SSID");
//ESP_LOGI(TAG, "Trying next SSID");
s_esp_netif = wifi_start(creds[index].first, creds[index].second);
}
ESP_LOGI(TAG, "Got IP(s)");
//ESP_LOGI(TAG, "Got IP(s)");
// iterate over active interfaces, and print out IPs of "our" netifs
esp_netif_t* netif = nullptr;
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i)
{
netif = esp_netif_next_unsafe(netif);
if (is_our_netif(TAG, netif))
{
ESP_LOGI(TAG, "Connected to %s", esp_netif_get_desc(netif));
//ESP_LOGI(TAG, "Connected to %s", esp_netif_get_desc(netif));
esp_netif_ip_info_t ip;
ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip));

ESP_LOGI(TAG, "- IPv4 address: " IPSTR, IP2STR(&ip.ip));
//ESP_LOGI(TAG, "- IPv4 address: " IPSTR, IP2STR(&ip.ip));
}
}
return true;
Expand All @@ -111,8 +111,8 @@ esp_err_t disconnect()
static void on_wifi_disconnect(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
ESP_LOGI(TAG, "on_wifi_disconnect: %d", (int) event_id);
ESP_LOGI(TAG, "Wi-Fi disconnected, trying to reconnect...");
//ESP_LOGI(TAG, "on_wifi_disconnect: %d", (int) event_id);
//ESP_LOGI(TAG, "Wi-Fi disconnected, trying to reconnect...");
esp_err_t err = esp_wifi_connect();
if (err == ESP_ERR_WIFI_NOT_STARTED)
return;
Expand Down Expand Up @@ -147,7 +147,7 @@ static esp_netif_t* wifi_start(const std::string& ssid, const std::string& passw
strncpy((char*) wifi_config.sta.password, password.c_str(), sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "Connecting to %s", wifi_config.sta.ssid);
//ESP_LOGI(TAG, "Connecting to %s", wifi_config.sta.ssid);
esp_wifi_connect();
return netif;
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/esp32/main/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ static constexpr const int GFXFF = 1;
#include <linenoise/linenoise.h>
#include <argtable3/argtable3.h>

#ifdef HW_TEST

static int toggle_relay(int, char**)
{
for (int n = 0; n < 10; ++n)
Expand Down Expand Up @@ -168,6 +170,8 @@ static int test_reader(int, char**)
return 0;
}

#endif

struct
{
struct arg_str* ssid;
Expand Down Expand Up @@ -493,6 +497,8 @@ void run_console()

esp_console_register_help_command();

#ifdef HW_TEST

const esp_console_cmd_t toggle_relay_cmd = {
.command = "relay",
.help = "Toggle relay",
Expand Down Expand Up @@ -565,6 +571,8 @@ void run_console()
};
ESP_ERROR_CHECK(esp_console_cmd_register(&test_reader_cmd));

#endif // HW_TEST

add_wifi_credentials_args.ssid = arg_str1(NULL, NULL, "<ssid>", "SSID");
add_wifi_credentials_args.password = arg_strn(NULL, NULL, "<password>", 0, 1, "Password");
add_wifi_credentials_args.end = arg_end(2);
Expand Down
1 change: 0 additions & 1 deletion frontend/esp32/main/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void Display::set_status(const std::string& status, uint16_t colour,
{
if (status != last_status)
{
printf("set_status: new %s\n", status.c_str());
clear_status_area();
last_status = status;
last_status_colour = colour;
Expand Down
4 changes: 1 addition & 3 deletions frontend/esp32/main/foreninglet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ void ForeningLet::thread_body()
esp_http_client_set_post_field(client, data, strlen(data));
esp_err_t err = esp_http_client_perform(client);

if (err == ESP_OK)
ESP_LOGI(TAG, "foreninglet: HTTP %d", esp_http_client_get_status_code(client));
else
if (err != ESP_OK)
ESP_LOGE(TAG, "foreninglet: error %s", esp_err_to_name(err));
}
}
Expand Down
11 changes: 3 additions & 8 deletions frontend/esp32/main/gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ bool Gateway::post_status()
esp_err_t err = esp_http_client_perform(client);

const bool ok = err == ESP_OK;
if (ok)
ESP_LOGI(TAG, "GW post_status: HTTP %d", esp_http_client_get_status_code(client));
else
if (!ok)
ESP_LOGE(TAG, "GW: post_status: error %s", esp_err_to_name(err));

return ok;
Expand Down Expand Up @@ -200,10 +198,7 @@ void Gateway::check_action()
}
auto allow_open_node = cJSON_GetObjectItem(root, "allow_open");
if (allow_open_node && cJSON_IsBool(allow_open_node))
{
allow_open = cJSON_IsTrue(allow_open_node);
ESP_LOGI(TAG, "GW allow_open = %d", allow_open);
}
}
}

Expand All @@ -227,13 +222,13 @@ bool Gateway::upload_coredump(Display& display)
NULL);
if (!p)
{
printf("No coredump partition found\n");
printf("No coredump partition\n");
return false;
}
char stamp[Logger::TIMESTAMP_SIZE];
Logger::make_timestamp(stamp);

printf("Coredump partition size %ld bytes\n", (long) p->size);
//printf("Coredump partition size %ld bytes\n", (long) p->size);
time_t start;
time(&start);
constexpr size_t BUF_SIZE = 768*8*2;
Expand Down
12 changes: 6 additions & 6 deletions frontend/esp32/main/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ esp_err_t http_event_handler(esp_http_client_event_t* evt)
switch (evt->event_id)
{
case HTTP_EVENT_ERROR:
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
//ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
break;
case HTTP_EVENT_ON_CONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
//ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
break;
case HTTP_EVENT_HEADER_SENT:
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
//ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
break;
case HTTP_EVENT_ON_HEADER:
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
//ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
break;
case HTTP_EVENT_ON_DATA:
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
//ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
if (!esp_http_client_is_chunked_response(evt->client))
{
if (evt->user_data)
Expand All @@ -44,7 +44,7 @@ esp_err_t http_event_handler(esp_http_client_event_t* evt)
}
break;
case HTTP_EVENT_ON_FINISH:
ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
//ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
break;
case HTTP_EVENT_REDIRECT:
break;
Expand Down
Loading

0 comments on commit 13f360e

Please sign in to comment.