Skip to content
Snippets Groups Projects
shepherd_sniff.c 2.23 KiB
Newer Older
Dorababu A's avatar
Dorababu A committed
#include "shepherd_sniff.h"

#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_flash_encrypt.h"
Dorababu A's avatar
Dorababu A committed
#include "esp_freertos_hooks.h"
#include "esp_wifi.h"
Dorababu A's avatar
Dorababu A committed
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include <inttypes.h>
// Shepehrd task to print metrics
Dorababu A's avatar
Dorababu A committed
static void shepherd_task(void *args) {
  while (1) {
    printf("\n---------Shepherd Chibby-----------\n");
    // get chip info
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);
Dorababu A's avatar
Dorababu A committed
    printf("ESP32 features, %d CPU cores, WiFi%s%s, \n", chip_info.cores,
           (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
           (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
    printf("silicon revision %d, \n", chip_info.revision);
    // get flash size
    uint32_t flash_size;
    if (esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
      printf("Get flash size failed");
    }
    printf("%" PRIu32 "MB %s flash\n", flash_size / (1024 * 1024),
           (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded"
                                                         : "external");
    // get flash encryptio status
    esp_flash_enc_mode_t mode = esp_get_flash_encryption_mode();
    if (mode == ESP_FLASH_ENC_MODE_DISABLED) {
      printf("Flash encryption feature is disabled\n");
    } else {
      printf("Flash encryption feature is enabled in %s mode\n",
             mode == ESP_FLASH_ENC_MODE_DEVELOPMENT ? "DEVELOPMENT"
                                                    : "RELEASE");
    }
    // wifi connection status
Dorababu A's avatar
Dorababu A committed
    wifi_mode_t wifi_mode;
    if (esp_wifi_get_mode(&wifi_mode) == ESP_ERR_WIFI_NOT_INIT) {
      printf("WiFI Status : disabled \n");
    } else
      printf("WiFi Status : Enabled \n");
    // Runtime Stats
    /*
    char pbuf[100];
    vTaskGetRunTimeStats(pbuf);
    printf("Run Time stats \n%s/r/n", pbuf);
    */
    printf("-----------------------------------------\n");
Dorababu A's avatar
Dorababu A committed
    vTaskDelay(15000 / portTICK_PERIOD_MS);
Dorababu A's avatar
Dorababu A committed
    // get memory usage
    printf("Memory usage : %d bytes \n", (2048-uxTaskGetStackHighWaterMark(NULL))); 
Dorababu A's avatar
Dorababu A committed
  }
  vTaskDelete(NULL);
}

esp_err_t shepherd_sniff() {
  // TODO calculate optimal stack size
  xTaskCreate(shepherd_task, "shepherd_task", 2048, NULL, 4, NULL);
Dorababu A's avatar
Dorababu A committed
  return ESP_OK;
}