SolarEnergy/esp32_device/main/main.c

58 lines
1.2 KiB
C
Raw Normal View History

2024-07-16 19:05:20 +00:00
#include <stdio.h>
#include "esp_system.h"
2024-08-17 15:19:47 +00:00
#include "esp_log.h"
2024-07-16 19:05:20 +00:00
2024-07-27 13:31:17 +00:00
#include "dev_name.h"
#include "storage.h"
2024-07-27 14:15:35 +00:00
#include "system.h"
2024-07-27 14:34:41 +00:00
#include "crypto.h"
2024-08-17 11:49:55 +00:00
#include "unsecure_api.h"
2024-08-17 15:19:47 +00:00
#include "ethernet.h"
static const char *TAG = "main";
2024-07-27 13:31:17 +00:00
2024-07-16 19:05:20 +00:00
void app_main(void)
{
2024-08-17 15:19:47 +00:00
esp_log_level_set("*", ESP_LOG_VERBOSE);
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
2024-07-27 13:31:17 +00:00
if (storage_init() == false)
{
2024-08-17 15:19:47 +00:00
ESP_LOGE(TAG, "Failed to init storage!\n");
2024-07-27 14:15:35 +00:00
reboot();
2024-07-27 13:31:17 +00:00
}
2024-07-27 14:15:35 +00:00
if (dev_generate_name())
2024-07-27 13:31:17 +00:00
{
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Generated a new device name\n");
2024-07-27 13:31:17 +00:00
}
2024-07-27 14:34:41 +00:00
char *name = dev_name();
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Dev name: %s\n", name);
2024-07-27 14:34:41 +00:00
free(name);
2024-07-27 14:15:35 +00:00
if (crypto_gen_priv_key())
{
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Generated device private key!\n");
2024-07-27 14:15:35 +00:00
}
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Device private key:\n");
2024-08-15 11:32:01 +00:00
crypto_print_priv_key();
2024-07-27 14:15:35 +00:00
2024-08-16 09:51:33 +00:00
char *csr = crypto_get_csr();
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Current CSR:\n%s\n", csr);
2024-08-16 09:51:33 +00:00
free(csr);
2024-08-17 15:19:47 +00:00
ESP_LOGI(TAG, "Initialize network\n");
ethernet_init();
ESP_LOGI(TAG, "Check secure origin\n");
2024-08-17 11:49:55 +00:00
char *sec_orig = unsecure_api_get_secure_origin();
assert(sec_orig != NULL);
printf("Res = %s\n", sec_orig);
2024-08-17 15:19:47 +00:00
system_sleep(20);
2024-07-27 14:34:41 +00:00
reboot();
2024-07-16 19:05:20 +00:00
}