it looks like esp_random() still tries to get random numbers from the WiFi subsystem after doing an esp_restart() but before initializing the WiFi again.
I suspect the RNG configuration is not set to weak random number generation while/after calling esp_restart().
Here is a test code:
Code: Select all
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "os.h"
#define TMP_LEN 8
esp_err_t event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
void app_reset(void *ctx) {
ESP_LOGI("RAND", "Scheduling esp_restart()...");
vTaskDelay(5000 / portTICK_RATE_MS);
ESP_LOGI("RAND", "ESP RESTART...");
esp_restart();
}
void app_main(void)
{
nvs_flash_init();
tcpip_adapter_init();
ESP_LOGI("RAND", "Random Number Generator Test");
vTaskDelay(1000 / portTICK_RATE_MS);
xTaskCreate( app_reset, "app_reset", 2048, 0, 9, NULL );
ESP_LOGI("RAND", "Generating random numbers...");
uint32_t tmp[TMP_LEN];
ESP_LOGI("rand", "looping...");
for(int i=0; i<TMP_LEN; i++)
tmp[i] = esp_random();
vTaskDelay(50 / portTICK_RATE_MS);
for (int i=0; i<TMP_LEN; i++)
ESP_LOGI("RAND", "tmp[%.2d] = %.8x", i, tmp[i]);
vTaskDelay(2000 / portTICK_RATE_MS);
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_start() );
wifi_config_t sta_config = {
.sta = {
.ssid = "access_point_name",
.password = "password",
.bssid_set = false
}
};
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
ESP_ERROR_CHECK( esp_wifi_start() );
ESP_ERROR_CHECK( esp_wifi_connect() );
}
Best,
Malte