SolarEnergy/esp32_device/main/main.c

58 lines
1.2 KiB
C
Executable File

#include <stdio.h>
#include "esp_system.h"
#include "esp_log.h"
#include "dev_name.h"
#include "storage.h"
#include "system.h"
#include "crypto.h"
#include "unsecure_api.h"
#include "ethernet.h"
static const char *TAG = "main";
void app_main(void)
{
esp_log_level_set("*", ESP_LOG_VERBOSE);
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
if (storage_init() == false)
{
ESP_LOGE(TAG, "Failed to init storage!\n");
reboot();
}
if (dev_generate_name())
{
ESP_LOGI(TAG, "Generated a new device name\n");
}
char *name = dev_name();
ESP_LOGI(TAG, "Dev name: %s\n", name);
free(name);
if (crypto_gen_priv_key())
{
ESP_LOGI(TAG, "Generated device private key!\n");
}
ESP_LOGI(TAG, "Device private key:\n");
crypto_print_priv_key();
char *csr = crypto_get_csr();
ESP_LOGI(TAG, "Current CSR:\n%s\n", csr);
free(csr);
ESP_LOGI(TAG, "Initialize network\n");
ethernet_init();
ESP_LOGI(TAG, "Check secure origin\n");
char *sec_orig = unsecure_api_get_secure_origin();
assert(sec_orig != NULL);
printf("Res = %s\n", sec_orig);
system_sleep(20);
reboot();
}