diff --git a/code/components/jomjol_flowcontroll/MainFlowControl.cpp b/code/components/jomjol_flowcontroll/MainFlowControl.cpp index 281aea769..6dba52557 100644 --- a/code/components/jomjol_flowcontroll/MainFlowControl.cpp +++ b/code/components/jomjol_flowcontroll/MainFlowControl.cpp @@ -10,6 +10,7 @@ #include "../../include/defines.h" #include "Helper.h" +#include "system_info.h" #include "statusled.h" #include "esp_camera.h" diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index f0fcae020..667ccb293 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -23,155 +23,16 @@ extern "C" { #include #include -#include #include #include "../../include/defines.h" - - #include "ClassLogFile.h" -#include "esp_vfs_fat.h" static const char* TAG = "HELPER"; -unsigned int systemStatus = 0; - -sdmmc_cid_t SDCardCid; -sdmmc_csd_t SDCardCsd; - // #define DEBUG_DETAIL_ON -///////////////////////////////////////////////////////////////////////////////////////////// -std::string getESPHeapInfo(){ - std::string espInfoResultStr = ""; - char aMsgBuf[80]; - - size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); - - size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - - size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - size_t aHeapIntLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - - size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); - size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); - - - sprintf(aMsgBuf,"Heap Total: %ld", (long) aFreeHeapSize); - espInfoResultStr += std::string(aMsgBuf); - - sprintf(aMsgBuf," | SPI Free: %ld", (long) aFreeSPIHeapSize); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf," | SPI Large Block: %ld", (long) aHeapLargestFreeBlockSize); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf," | SPI Min Free: %ld", (long) aMinFreeHeapSize); - espInfoResultStr += std::string(aMsgBuf); - - sprintf(aMsgBuf," | Int Free: %ld", (long) (aFreeInternalHeapSize)); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf," | Int Large Block: %ld", (long) aHeapIntLargestFreeBlockSize); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf," | Int Min Free: %ld", (long) (aMinFreeInternalHeapSize)); - espInfoResultStr += std::string(aMsgBuf); - - return espInfoResultStr; -} - - -size_t getESPHeapSize() -{ - return heap_caps_get_free_size(MALLOC_CAP_8BIT); -} - - -size_t getInternalESPHeapSize() -{ - return heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); -} - - -std::string getSDCardPartitionSize(){ - FATFS *fs; - uint32_t fre_clust, tot_sect; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - - //ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize); - - return std::to_string(tot_sect); -} - - -std::string getSDCardFreePartitionSpace(){ - FATFS *fs; - uint32_t fre_clust, fre_sect; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - - //ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize); - - return std::to_string(fre_sect); -} - - -std::string getSDCardPartitionAllocationSize(){ - FATFS *fs; - uint32_t fre_clust, allocation_size; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - allocation_size = fs->ssize; - - //ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size); - - return std::to_string(allocation_size); -} - - -void SaveSDCardInfo(sdmmc_card_t* card) { - SDCardCid = card->cid; - SDCardCsd = card->csd; -} - - -std::string getSDCardManufacturer(){ - std::string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); - //ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); - - return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); -} - - -std::string getSDCardName(){ - char *SDCardName = SDCardCid.name; - //ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); - - return std::string(SDCardName); -} - - -std::string getSDCardCapacity(){ - int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - //ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); - - return std::to_string(SDCardCapacity); -} - - -std::string getSDCardSectorSize(){ - int SDCardSectorSize = SDCardCsd.sector_size; - //ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); - - return std::to_string(SDCardSectorSize); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) { @@ -487,7 +348,6 @@ long getFileSize(std::string filename) } - /* recursive mkdir */ int mkdir_r(const char *dir, const mode_t mode) { char tmp[FILE_PATH_MAX]; @@ -564,14 +424,6 @@ std::string toLower(std::string in) } -// CPU Temp -extern "C" uint8_t temprature_sens_read(); -float temperatureRead() -{ - return (temprature_sens_read() - 32) / 1.8; -} - - time_t addDays(time_t startTime, int days) { struct tm* tm = localtime(&startTime); tm->tm_mday += days; @@ -681,144 +533,6 @@ std::string ReplaceString(std::string subject, const std::string& search, } -/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ -/* SD Card Manufacturer Database */ -struct SDCard_Manufacturer_database { - std::string type; - int id; - std::string manufacturer; -}; - - -/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ -/* SD Card Manufacturer Database */ -struct SDCard_Manufacturer_database database[] = { - { - .type = "sd", - .id = 0x01, - .manufacturer = "Panasonic", - }, - { - .type = "sd", - .id = 0x02, - .manufacturer = "Toshiba/Kingston/Viking", - }, - { - .type = "sd", - .id = 0x03, - .manufacturer = "SanDisk", - }, - { - .type = "sd", - .id = 0x08, - .manufacturer = "Silicon Power", - }, - { - .type = "sd", - .id = 0x18, - .manufacturer = "Infineon", - }, - { - .type = "sd", - .id = 0x1b, - .manufacturer = "Transcend/Samsung", - }, - { - .type = "sd", - .id = 0x1c, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x1d, - .manufacturer = "Corsair/AData", - }, - { - .type = "sd", - .id = 0x1e, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x1f, - .manufacturer = "Kingston", - }, - { - .type = "sd", - .id = 0x27, - .manufacturer = "Delkin/Phison", - }, - { - .type = "sd", - .id = 0x28, - .manufacturer = "Lexar", - }, - { - .type = "sd", - .id = 0x30, - .manufacturer = "SanDisk", - }, - { - .type = "sd", - .id = 0x31, - .manufacturer = "Silicon Power", - }, - { - .type = "sd", - .id = 0x33, - .manufacturer = "STMicroelectronics", - }, - { - .type = "sd", - .id = 0x41, - .manufacturer = "Kingston", - }, - { - .type = "sd", - .id = 0x6f, - .manufacturer = "STMicroelectronics", - }, - { - .type = "sd", - .id = 0x74, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x76, - .manufacturer = "Patriot", - }, - { - .type = "sd", - .id = 0x82, - .manufacturer = "Gobe/Sony", - }, - { - .type = "sd", - .id = 0x89, - .manufacturer = "Unknown", - } -}; - - -/* Parse SD Card Manufacturer Database */ -std::string SDCardParseManufacturerIDs(int id) -{ - unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); - std::string ret_val = ""; - - for (int i = 0; i < id_cnt; i++) { - if (database[i].id == id) { - return database[i].manufacturer; - } - else { - ret_val = "ID unknown (not in DB)"; - } - } - return ret_val; -} - - std::string to_stringWithPrecision(const double _value, int _decPlace = 6) { std::ostringstream out; @@ -832,90 +546,13 @@ std::string to_stringWithPrecision(const double _value, int _decPlace = 6) } -std::string getMac(void) -{ - uint8_t macInt[6]; - char macFormated[6*2 + 5 + 1]; // AA:BB:CC:DD:EE:FF - - esp_read_mac(macInt, ESP_MAC_WIFI_STA); - sprintf(macFormated, "%02X:%02X:%02X:%02X:%02X:%02X", macInt[0], macInt[1], macInt[2], macInt[3], macInt[4], macInt[5]); - - return macFormated; -} - - -void setSystemStatusFlag(SystemStatusFlag_t flag) -{ - systemStatus = systemStatus | flag; // set bit - - char buf[20]; - snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "System status code: " + std::string(buf)); -} - - -void clearSystemStatusFlag(SystemStatusFlag_t flag) -{ - systemStatus = systemStatus | ~flag; // clear bit - - char buf[20]; - snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); - LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "System status code: " + std::string(buf)); -} - - -int getSystemStatus(void) -{ - return systemStatus; -} - - -bool isSetSystemStatusFlag(SystemStatusFlag_t flag) -{ - //ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag)); - - if ((systemStatus & flag) == flag) { - return true; - } - else { - return false; - } -} - - time_t getUpTime(void) { return (uint32_t)(esp_timer_get_time()/1000/1000); // in seconds } -std::string getResetReason(void) -{ - std::string reasonText; - - switch(esp_reset_reason()) { - case ESP_RST_POWERON: reasonText = "Power-on event (or reset button)"; break; //!< Reset due to power-on event - case ESP_RST_EXT: reasonText = "External pin"; break; //!< Reset by external pin (not applicable for ESP32) - case ESP_RST_SW: reasonText = "Via esp_restart"; break; //!< Software reset via esp_restart - case ESP_RST_PANIC: reasonText = "Exception/panic"; break; //!< Software reset due to exception/panic - case ESP_RST_INT_WDT: reasonText = "Interrupt watchdog"; break; //!< Reset (software or hardware) due to interrupt watchdog - case ESP_RST_TASK_WDT: reasonText = "Task watchdog"; break; //!< Reset due to task watchdog - case ESP_RST_WDT: reasonText = "Other watchdogs"; break; //!< Reset due to other watchdogs - case ESP_RST_DEEPSLEEP: reasonText = "Exiting deep sleep mode"; break; //!< Reset after exiting deep sleep mode - case ESP_RST_BROWNOUT: reasonText = "Brownout"; break; //!< Brownout reset (software or hardware) - case ESP_RST_SDIO: reasonText = "SDIO"; break; //!< Reset over SDIO - - case ESP_RST_UNKNOWN: //!< Reset reason can not be determined - default: - reasonText = "Unknown"; - } - return reasonText; -} - - -/** - * Returns the current uptime formated ad xxf xxh xxm [xxs] - */ +// Returns the current uptime formated ad xxf xxh xxm [xxs] std::string getFormatedUptime(bool compact) { char buf[20]; @@ -1021,4 +658,4 @@ std::string intToHexString(int _valueInt) char valueHex[33]; sprintf(valueHex,"0x%02x", _valueInt); return std::string(valueHex); -} \ No newline at end of file +} diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 6aeebd1d6..a2299f275 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -6,7 +6,6 @@ #include #include #include -#include "sdmmc_cmd.h" std::string FormatFileName(std::string input); std::size_t file_size(const std::string& file_name); @@ -18,7 +17,6 @@ bool RenameFile(std::string from, std::string to); bool MakeDir(std::string _what); bool FileExists(std::string filename); - std::string to_stringWithPrecision(const double _value, int _decPlace); size_t findDelimiterPos(std::string input, std::string delimiter); @@ -45,49 +43,7 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size); std::vector HelperZerlegeZeile(std::string input, std::string _delimiter); std::vector ZerlegeZeile(std::string input, std::string delimiter = " =, \t"); -/////////////////////////// -size_t getInternalESPHeapSize(); -size_t getESPHeapSize(); -std::string getESPHeapInfo(); - -///////////////////////////// -std::string getSDCardPartitionSize(); -std::string getSDCardFreePartitionSpace(); -std::string getSDCardPartitionAllocationSize(); - -void SaveSDCardInfo(sdmmc_card_t* card); -std::string SDCardParseManufacturerIDs(int); -std::string getSDCardManufacturer(); -std::string getSDCardName(); -std::string getSDCardCapacity(); -std::string getSDCardSectorSize(); - -std::string getMac(void); - - -/* Error bit fields - One bit per error - Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */ -enum SystemStatusFlag_t { // One bit per error - // First Byte - SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error - SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error - SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error - SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error - SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error - - // Second Byte - SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work - SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong -}; - -void setSystemStatusFlag(SystemStatusFlag_t flag); -void clearSystemStatusFlag(SystemStatusFlag_t flag); -int getSystemStatus(void); -bool isSetSystemStatusFlag(SystemStatusFlag_t flag); - time_t getUpTime(void); -std::string getResetReason(void); std::string getFormatedUptime(bool compact); const char* get404(void); diff --git a/code/components/jomjol_helper/esp_sys.cpp b/code/components/jomjol_helper/esp_sys.cpp deleted file mode 100644 index 8df251cbe..000000000 --- a/code/components/jomjol_helper/esp_sys.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "../../include/defines.h" - -#ifdef DEBUG_ENABLE_SYSINFO - -#include "esp_sys.h" -#include "esp_chip_info.h" - -#include - - -#include "esp_chip_info.h" - - -void Restart() { - esp_restart(); -} - -//source : https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv416esp_chip_model_t - -//https://github.com/espressif/esp-idf/blob/8464186e67e34b417621df6b6f1f289a6c60b859/components/esp_hw_support/include/esp_chip_info.h -/* -typedef enum { - CHIP_ESP32 = 1, //!< ESP32 - CHIP_ESP32S2 = 2, //!< ESP32-S2 - CHIP_ESP32S3 = 9, //!< ESP32-S3 - CHIP_ESP32C3 = 5, //!< ESP32-C3 - CHIP_ESP32H4 = 6, //!< ESP32-H4 - CHIP_ESP32C2 = 12, //!< ESP32-C2 - CHIP_ESP32C6 = 13, //!< ESP32-C6 - CHIP_ESP32H2 = 16, //!< ESP32-H2 - CHIP_POSIX_LINUX = 999, //!< The code is running on POSIX/Linux simulator -} esp_chip_model_t; -*/ - -char* GetChipModel(){ - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - switch((int)chipInfo.model) { - case 0 : return (char*)"ESP8266"; - case (int)esp_chip_model_t::CHIP_ESP32 : return (char*)"ESP32"; -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) - case (int)esp_chip_model_t::CHIP_ESP32S2 : return (char*)"ESP32-S2"; - case (int)esp_chip_model_t::CHIP_ESP32S3 : return (char*)"ESP32-S3"; - case (int)esp_chip_model_t::CHIP_ESP32C3 : return (char*)"ESP32-C3"; - case 6 : return (char*)"ESP32-H4"; - case 12 : return (char*)"ESP32-C2"; - case 13 : return (char*)"ESP32-C6"; - //case (int)esp_chip_model_t::CHIP_ESP32H4 : return (char*)"ESP32-H4"; - //case (int)esp_chip_model_t::CHIP_ESP32C2 : return (char*)"ESP32-C2"; - //case (int)esp_chip_model_t::CHIP_ESP32C6 : return (char*)"ESP32-C6"; - //case (int)esp_chip_model_t::CHIP_ESP32H2 : return (char*)"ESP32-H2"; - case 16 : return (char*)"ESP32-H2"; - //case (int)esp_chip_model_t::CHIP_POSIX_LINUX : return (char*)"CHIP_POSIX_LINUX"; - -#endif - } - return (char*)"Chip Unknown"; -} - -uint8_t GetChipCoreCount() { - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - return chipInfo.cores; -} - -uint16_t GetChipRevision() { - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - return chipInfo.revision; -} - -uint32_t GetChipfeatures() { - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - return chipInfo.features; -} - - -uint32_t GetFreeHeap() { - return esp_get_free_heap_size(); -} - -uint32_t GetLeastHeapFreeSinceBoot() { - return esp_get_minimum_free_heap_size(); -} - - -std::string get_device_info() -{ - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - - std::string espInfoResultStr = ""; - char aMsgBuf[40]; - - espInfoResultStr += "Device Info:"; - espInfoResultStr += "---------------\n"; - espInfoResultStr += "Chip Model: " + std::string(GetChipModel()) +"\n"; - sprintf(aMsgBuf,"Chip Revision: %d\n", chip_info.revision); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf,"CPU Cores: %d\n", chip_info.cores); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf,"Flash Memory: %dMB\n", spi_flash_get_chip_size()/(1024*1024)); - espInfoResultStr += std::string(aMsgBuf); - if(chip_info.features & CHIP_FEATURE_WIFI_BGN) - //espInfoResultStr += "Base MAC: " + std::string(getMac()) +"\n"; - espInfoResultStr += "ESP-IDF version: " + std::string(esp_get_idf_version()) +"\n"; - if((chip_info.features & CHIP_FEATURE_WIFI_BGN) || (chip_info.features & CHIP_FEATURE_BT) || - (chip_info.features & CHIP_FEATURE_BLE) || (chip_info.features & CHIP_FEATURE_EMB_FLASH)) - { - espInfoResultStr += "Characteristics:\n"; - if(chip_info.features & CHIP_FEATURE_WIFI_BGN) - espInfoResultStr += " WiFi 2.4GHz\n"; - if(chip_info.features & CHIP_FEATURE_BT) - espInfoResultStr += " Bluetooth Classic\n"; - if(chip_info.features & CHIP_FEATURE_BLE) - espInfoResultStr += " Bluetooth Low Energy\n"; - if(chip_info.features & CHIP_FEATURE_EMB_FLASH) - espInfoResultStr += " Embedded Flash memory\n"; - else - espInfoResultStr += " External Flash memory\n"; - } - - #ifdef USE_HIMEM_IF_AVAILABLE - sprintf(aMsgBuf,"spiram size %u\n", esp_psram_get_size()); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf,"himem free %u\n", esp_himem_get_free_size()); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf,"himem phys %u\n", esp_himem_get_phys_size()); - espInfoResultStr += std::string(aMsgBuf); - sprintf(aMsgBuf,"himem reserved %u\n", esp_himem_reserved_area_size()); - espInfoResultStr += std::string(aMsgBuf); - #endif - - return espInfoResultStr; -} - - -size_t getFreeMemoryInternal(){ //Current Free Memory - return heap_caps_get_free_size(MALLOC_CAP_8BIT) - heap_caps_get_free_size(MALLOC_CAP_SPIRAM); -} - -size_t getFreeMemorySPIRAM(){ //Current Free Memory - return heap_caps_get_free_size(MALLOC_CAP_SPIRAM); -} - - -size_t getLargestFreeBlockInternal(){ //Largest Free Block - return heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); -} - -size_t getLargestFreeBlockSPIRAM(){ //Largest Free Block - return heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); -} - - -size_t getMinEverFreeMemInternal(){ //Min. Ever Free Size - return heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); -} - -size_t getMinEverFreeMemSPIRAM(){ //Min. Ever Free Size - return heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM); -} - -#ifdef USE_HIMEM_IF_AVAILABLE - size_t getHimemTotSpace(){ - return esp_himem_get_phys_size(); - } - - size_t getHimemFreeSpace(){ - return esp_himem_get_free_size(); - } - - size_t getHimemReservedArea(){ - return esp_himem_reserved_area_size(); - } -#endif - -#endif //DEBUG_ENABLE_SYSINFO diff --git a/code/components/jomjol_helper/esp_sys.h b/code/components/jomjol_helper/esp_sys.h deleted file mode 100644 index addd59208..000000000 --- a/code/components/jomjol_helper/esp_sys.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "../../include/defines.h" - -#ifdef DEBUG_ENABLE_SYSINFO - -#ifndef ESP_SYS_H -#define ESP_SYS_H - - -#include - - -// Device libraries (ESP-IDF) -#include -#include -#include - -// for esp_psram_get_size -extern "C" { - #include "esp_psram.h" - #ifdef USE_HIMEM_IF_AVAILABLE - #include - #endif -} - - - - void Restart(); - char *GetChipModel(); - uint8_t GetChipCoreCount(); - uint16_t GetChipRevision(); - uint32_t GetChipfeatures(); - uint32_t GetFreeHeap(); - uint32_t GetLeastHeapFreeSinceBoot(); - - std::string get_device_info(); - - size_t getFreeMemoryInternal(); - size_t getFreeMemorySPIRAM(); - size_t getLargestFreeBlockInternal(); - size_t getLargestFreeBlockSPIRAM(); - size_t getMinEverFreeMemInternal(); - size_t getMinEverFreeMemSPIRAM(); - #ifdef USE_HIMEM_IF_AVAILABLE - size_t getHimemTotSpace(); - size_t getHimemFreeSpace(); - size_t getHimemReservedArea(); - #endif - - -#endif //ESP_SYS_H - -#endif // DEBUG_ENABLE_SYSINFO diff --git a/code/components/jomjol_helper/system_info.cpp b/code/components/jomjol_helper/system_info.cpp new file mode 100644 index 000000000..69e333e5e --- /dev/null +++ b/code/components/jomjol_helper/system_info.cpp @@ -0,0 +1,514 @@ +#include "system_info.h" + +#include "esp_chip_info.h" +#include "esp_vfs_fat.h" + +#include "Helper.h" +#include "ClassLogFile.h" + +static const char* TAG = "SYSINFO"; + +unsigned int systemStatus = 0; + +sdmmc_cid_t SDCardCid; +sdmmc_csd_t SDCardCsd; + + +std::string getChipModel(void) +{ + esp_chip_info_t chipInfo; + esp_chip_info(&chipInfo); + + switch((int)chipInfo.model) { + case 0 : return (char*)"ESP8266"; + case (int)esp_chip_model_t::CHIP_ESP32 : return std::string("ESP32"); + case (int)esp_chip_model_t::CHIP_ESP32S2 : return std::string("ESP32-S2"); + case (int)esp_chip_model_t::CHIP_ESP32S3 : return std::string("ESP32-S3"); + case (int)esp_chip_model_t::CHIP_ESP32C3 : return std::string("ESP32-C3"); + case 6 : return std::string("ESP32-H4"); + case 12 : return std::string("ESP32-C2"); + case 13 : return std::string("ESP32-C6"); + //case (int)esp_chip_model_t::CHIP_ESP32H4 : return std::string("ESP32-H4"); + //case (int)esp_chip_model_t::CHIP_ESP32C2 : return std::string("ESP32-C2"); + //case (int)esp_chip_model_t::CHIP_ESP32C6 : return std::string("ESP32-C6"); + //case (int)esp_chip_model_t::CHIP_ESP32H2 : return std::string("ESP32-H2"); + case 16 : return std::string("ESP32-H2"); + //case (int)esp_chip_model_t::CHIP_POSIX_LINUX : return std::string("CHIP_POSIX_LINUX"); + } + return std::string("Chip unknown"); +} + + +int getChipCoreCount(void) +{ + esp_chip_info_t chipInfo; + esp_chip_info(&chipInfo); + return (int)chipInfo.cores; +} + + +std::string getChipRevision(void) +{ + esp_chip_info_t chipInfo; + esp_chip_info(&chipInfo); + return to_stringWithPrecision(chipInfo.revision / 100.0, 2); +} + + +void printDeviceInfo(void) +{ + esp_chip_info_t chipInfo; + esp_chip_info(&chipInfo); + + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Device info: Model: " + getChipModel() + + ", Cores: " + std::to_string(chipInfo.cores) + + ", Revision: " + getChipRevision()); +} + + +/*std::string get_device_info() +{ + esp_chip_info_t chip_info; + esp_chip_info(&chip_info); + + std::string espInfoResultStr = ""; + char aMsgBuf[40]; + + espInfoResultStr += "Device Info:"; + espInfoResultStr += "---------------\n"; + espInfoResultStr += "Chip Model: " + std::string(GetChipModel()) +"\n"; + sprintf(aMsgBuf,"Chip Revision: %d\n", chip_info.revision); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf,"CPU Cores: %d\n", chip_info.cores); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf,"Flash Memory: %dMB\n", spi_flash_get_chip_size()/(1024*1024)); + espInfoResultStr += std::string(aMsgBuf); + if(chip_info.features & CHIP_FEATURE_WIFI_BGN) + //espInfoResultStr += "Base MAC: " + std::string(getMac()) +"\n"; + espInfoResultStr += "ESP-IDF version: " + std::string(esp_get_idf_version()) +"\n"; + if((chip_info.features & CHIP_FEATURE_WIFI_BGN) || (chip_info.features & CHIP_FEATURE_BT) || + (chip_info.features & CHIP_FEATURE_BLE) || (chip_info.features & CHIP_FEATURE_EMB_FLASH)) + { + espInfoResultStr += "Characteristics:\n"; + if(chip_info.features & CHIP_FEATURE_WIFI_BGN) + espInfoResultStr += " WiFi 2.4GHz\n"; + if(chip_info.features & CHIP_FEATURE_BT) + espInfoResultStr += " Bluetooth Classic\n"; + if(chip_info.features & CHIP_FEATURE_BLE) + espInfoResultStr += " Bluetooth Low Energy\n"; + if(chip_info.features & CHIP_FEATURE_EMB_FLASH) + espInfoResultStr += " Embedded Flash memory\n"; + else + espInfoResultStr += " External Flash memory\n"; + } + + #ifdef USE_HIMEM_IF_AVAILABLE + sprintf(aMsgBuf,"spiram size %u\n", esp_psram_get_size()); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf,"himem free %u\n", esp_himem_get_free_size()); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf,"himem phys %u\n", esp_himem_get_phys_size()); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf,"himem reserved %u\n", esp_himem_reserved_area_size()); + espInfoResultStr += std::string(aMsgBuf); + #endif + + return espInfoResultStr; +}*/ + + +///////////////////////////////////////////////////////////////////////////////////////////// +std::string getIDFVersion(void) +{ + return std::string(esp_get_idf_version()); +} + + +///////////////////////////////////////////////////////////////////////////////////////////// +// CPU Temp +extern "C" uint8_t temprature_sens_read(); +float temperatureRead() +{ + return (temprature_sens_read() - 32) / 1.8; +} + + +///////////////////////////////////////////////////////////////////////////////////////////// +std::string getESPHeapInfo(){ + std::string espInfoResultStr = ""; + char aMsgBuf[80]; + + size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); + + size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aHeapIntLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + + sprintf(aMsgBuf,"Heap Total: %ld", (long) aFreeHeapSize); + espInfoResultStr += std::string(aMsgBuf); + + sprintf(aMsgBuf," | SPI Free: %ld", (long) aFreeSPIHeapSize); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf," | SPI Large Block: %ld", (long) aHeapLargestFreeBlockSize); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf," | SPI Min Free: %ld", (long) aMinFreeHeapSize); + espInfoResultStr += std::string(aMsgBuf); + + sprintf(aMsgBuf," | Int Free: %ld", (long) (aFreeInternalHeapSize)); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf," | Int Large Block: %ld", (long) aHeapIntLargestFreeBlockSize); + espInfoResultStr += std::string(aMsgBuf); + sprintf(aMsgBuf," | Int Min Free: %ld", (long) (aMinFreeInternalHeapSize)); + espInfoResultStr += std::string(aMsgBuf); + + return espInfoResultStr; +} + + +size_t getESPHeapSizeTotal() +{ + return heap_caps_get_free_size(MALLOC_CAP_8BIT); +} + + +size_t getESPHeapSizeInternal() +{ + return heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); +} + + +size_t getESPHeapSizeInternalLargestFree() +{ + return heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); +} + + +size_t getESPHeapSizeInternalMinFree() +{ + return heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); +} + + +size_t getESPHeapSizeSPIRAM() +{ + return heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM); +} + + +size_t getESPHeapSizeSPIRAMLargestFree() +{ + return heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +} + + +size_t getESPHeapSizeSPIRAMMinFree() +{ + return heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); +} + + +#ifdef USE_HIMEM_IF_AVAILABLE +size_t getESPHimemTotal() +{ + return esp_himem_get_phys_size(); +} + +size_t getESPHimemFree() +{ + return esp_himem_get_free_size(); +} + +size_t getESPHimemReservedArea() +{ + return esp_himem_reserved_area_size(); +} +#endif + + +///////////////////////////////////////////////////////////////////////////////////////////// +void setSystemStatusFlag(SystemStatusFlag_t flag) +{ + systemStatus = systemStatus | flag; // set bit + + char buf[20]; + snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "System status code: " + std::string(buf)); +} + + +void clearSystemStatusFlag(SystemStatusFlag_t flag) +{ + systemStatus = systemStatus | ~flag; // clear bit + + char buf[20]; + snprintf(buf, sizeof(buf), "0x%08X", getSystemStatus()); + LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "System status code: " + std::string(buf)); +} + + +int getSystemStatus(void) +{ + return systemStatus; +} + + +bool isSetSystemStatusFlag(SystemStatusFlag_t flag) +{ + //ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag)); + + if ((systemStatus & flag) == flag) { + return true; + } + else { + return false; + } +} + + +std::string getResetReason(void) +{ + std::string reasonText; + + switch(esp_reset_reason()) { + case ESP_RST_POWERON: reasonText = "Power-on event (or reset button)"; break; //!< Reset due to power-on event + case ESP_RST_EXT: reasonText = "External pin"; break; //!< Reset by external pin (not applicable for ESP32) + case ESP_RST_SW: reasonText = "Via esp_restart"; break; //!< Software reset via esp_restart + case ESP_RST_PANIC: reasonText = "Exception/panic"; break; //!< Software reset due to exception/panic + case ESP_RST_INT_WDT: reasonText = "Interrupt watchdog"; break; //!< Reset (software or hardware) due to interrupt watchdog + case ESP_RST_TASK_WDT: reasonText = "Task watchdog"; break; //!< Reset due to task watchdog + case ESP_RST_WDT: reasonText = "Other watchdogs"; break; //!< Reset due to other watchdogs + case ESP_RST_DEEPSLEEP: reasonText = "Exiting deep sleep mode"; break; //!< Reset after exiting deep sleep mode + case ESP_RST_BROWNOUT: reasonText = "Brownout"; break; //!< Brownout reset (software or hardware) + case ESP_RST_SDIO: reasonText = "SDIO"; break; //!< Reset over SDIO + + case ESP_RST_UNKNOWN: //!< Reset reason can not be determined + default: + reasonText = "Unknown"; + } + return reasonText; +} + + +///////////////////////////////////////////////////////////////////////////////////////////// +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database { + std::string type; + int id; + std::string manufacturer; +}; + + +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database database[] = { + { + .type = "sd", + .id = 0x01, + .manufacturer = "Panasonic", + }, + { + .type = "sd", + .id = 0x02, + .manufacturer = "Toshiba/Kingston/Viking", + }, + { + .type = "sd", + .id = 0x03, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x08, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x18, + .manufacturer = "Infineon", + }, + { + .type = "sd", + .id = 0x1b, + .manufacturer = "Transcend/Samsung", + }, + { + .type = "sd", + .id = 0x1c, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1d, + .manufacturer = "Corsair/AData", + }, + { + .type = "sd", + .id = 0x1e, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1f, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x27, + .manufacturer = "Delkin/Phison", + }, + { + .type = "sd", + .id = 0x28, + .manufacturer = "Lexar", + }, + { + .type = "sd", + .id = 0x30, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x31, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x33, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x41, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x6f, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x74, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x76, + .manufacturer = "Patriot", + }, + { + .type = "sd", + .id = 0x82, + .manufacturer = "Gobe/Sony", + }, + { + .type = "sd", + .id = 0x89, + .manufacturer = "Unknown", + } +}; + + +/* Parse SD Card Manufacturer Database */ +std::string SDCardParseManufacturerIDs(int id) +{ + unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); + std::string ret_val = ""; + + for (int i = 0; i < id_cnt; i++) { + if (database[i].id == id) { + return database[i].manufacturer; + } + else { + ret_val = "ID unknown (not in DB)"; + } + } + return ret_val; +} + + +std::string getSDCardPartitionSize(){ + FATFS *fs; + uint32_t fre_clust, tot_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + //ESP_LOGD(TAG, "%d MB total drive space (Sector size [bytes]: %d)", (int)tot_sect, (int)fs->ssize); + + return std::to_string(tot_sect); +} + + +std::string getSDCardFreePartitionSpace(){ + FATFS *fs; + uint32_t fre_clust, fre_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + //ESP_LOGD(TAG, "%d MB free drive space (Sector size [bytes]: %d)", (int)fre_sect, (int)fs->ssize); + + return std::to_string(fre_sect); +} + + +std::string getSDCardPartitionAllocationSize(){ + FATFS *fs; + uint32_t fre_clust, allocation_size; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + allocation_size = fs->ssize; + + //ESP_LOGD(TAG, "SD Card Partition Allocation Size: %d bytes", allocation_size); + + return std::to_string(allocation_size); +} + + +void SaveSDCardInfo(sdmmc_card_t* card) { + SDCardCid = card->cid; + SDCardCsd = card->csd; +} + + +std::string getSDCardManufacturer(){ + std::string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); + //ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); + + return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); +} + + +std::string getSDCardName(){ + char *SDCardName = SDCardCid.name; + //ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); + + return std::string(SDCardName); +} + + +std::string getSDCardCapacity(){ + int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + //ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); + + return std::to_string(SDCardCapacity); +} + + +std::string getSDCardSectorSize(){ + int SDCardSectorSize = SDCardCsd.sector_size; + //ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); + + return std::to_string(SDCardSectorSize); +} \ No newline at end of file diff --git a/code/components/jomjol_helper/system_info.h b/code/components/jomjol_helper/system_info.h new file mode 100644 index 000000000..7462bd37c --- /dev/null +++ b/code/components/jomjol_helper/system_info.h @@ -0,0 +1,67 @@ +#pragma once + +#ifndef ESP_SYSTEM_INFO_H +#define ESP_SYSTEM_INFO_H + +#include "sdmmc_cmd.h" + +#include + + +std::string getChipModel(void); +int getChipCoreCount(void); +std::string getChipRevision(void); +void printDeviceInfo(void); +//std::string get_device_info(void); + +std::string getIDFVersion(void); + +std::string getESPHeapInfo(void); +size_t getESPHeapSizeTotal(void); +size_t getESPHeapSizeInternal(void); +size_t getESPHeapSizeInternalLargestFree(void); +size_t getESPHeapSizeInternalMinFree(void); +size_t getESPHeapSizeSPIRAM(void); +size_t getESPHeapSizeSPIRAMLargestFree(void); +size_t getESPHeapSizeSPIRAMMinFree(void); + +#ifdef USE_HIMEM_IF_AVAILABLE +size_t getESPHimemTotal(void); +size_t getESPHimemFree(void); +size_t getESPHimemReservedArea(void); +#endif + +/* Error bit fields + One bit per error + Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */ +enum SystemStatusFlag_t { // One bit per error + // First Byte + SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error + SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error + SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error + SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error + SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error + + // Second Byte + SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work + SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong +}; + +void setSystemStatusFlag(SystemStatusFlag_t flag); +void clearSystemStatusFlag(SystemStatusFlag_t flag); +int getSystemStatus(void); +bool isSetSystemStatusFlag(SystemStatusFlag_t flag); + +std::string getResetReason(void); + +void SaveSDCardInfo(sdmmc_card_t* card); +std::string getSDCardPartitionSize(void); +std::string getSDCardFreePartitionSpace(void); +std::string getSDCardPartitionAllocationSize(void); +std::string SDCardParseManufacturerIDs(int); +std::string getSDCardManufacturer(void); +std::string getSDCardName(void); +std::string getSDCardCapacity(void); +std::string getSDCardSectorSize(void); + +#endif //ESP_SYSTEM_INFO_H diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 07ac06b86..409924929 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -15,6 +15,7 @@ extern "C" { #endif #include "Helper.h" +#include "system_info.h" #include "time_sntp.h" #include "../../include/defines.h" diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index 715cc51cd..1ae4e14f9 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -12,6 +12,7 @@ #include "interface_mqtt.h" #include "time_sntp.h" #include "Helper.h" +#include "system_info.h" #include "../../include/defines.h" @@ -218,7 +219,7 @@ bool publishSystemData(int qos) sprintf(tmp_char, "%ld", (long)getUpTime()); allSendsSuccessed |= MQTTPublish(maintopic + "/" + "uptime", std::string(tmp_char), qos, retainFlag); - sprintf(tmp_char, "%lu", (long) getESPHeapSize()); + sprintf(tmp_char, "%lu", (long) getESPHeapSizeTotal()); allSendsSuccessed |= MQTTPublish(maintopic + "/" + "freeMem", std::string(tmp_char), qos, retainFlag); sprintf(tmp_char, "%d", get_WIFI_RSSI()); diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 814286328..02e06d4ef 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -423,6 +423,18 @@ void wifiRoamByScanning(void) #endif // WLAN_USE_ROAMING_BY_SCANNING +std::string getMac() +{ + uint8_t macInt[6]; + char macFormated[6*2 + 5 + 1]; // AA:BB:CC:DD:EE:FF + + esp_read_mac(macInt, ESP_MAC_WIFI_STA); + sprintf(macFormated, "%02X:%02X:%02X:%02X:%02X:%02X", macInt[0], macInt[1], macInt[2], macInt[3], macInt[4], macInt[5]); + + return macFormated; +} + + std::string getIPAddress() { return wlan_config.ipaddress; diff --git a/code/components/jomjol_wlan/connect_wlan.h b/code/components/jomjol_wlan/connect_wlan.h index 28980e295..01d971607 100644 --- a/code/components/jomjol_wlan/connect_wlan.h +++ b/code/components/jomjol_wlan/connect_wlan.h @@ -6,6 +6,7 @@ #include int wifi_init_sta(void); +std::string getMac(void); std::string getIPAddress(); std::string getSSID(); int get_WIFI_RSSI(); diff --git a/code/include/defines.h b/code/include/defines.h index 3c8073b18..e0a1f442b 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -12,7 +12,6 @@ //#define DEBUG_DETAIL_ON //#define DEBUG_DISABLE_BROWNOUT_DETECTOR - //#define DEBUG_ENABLE_SYSINFO //#define DEBUG_ENABLE_PERFMON //#define DEBUG_HIMEM_MEMORY_CHECK // need [env:esp32cam-dev-himem] diff --git a/code/main/main.cpp b/code/main/main.cpp index b5f70773a..de32263d9 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -11,7 +11,6 @@ //#include "sdkconfig.h" #include "esp_psram.h" #include "esp_pm.h" -#include "esp_chip_info.h" // SD-Card //////////////////// @@ -41,6 +40,7 @@ #include "server_mqtt.h" #endif //ENABLE_MQTT #include "Helper.h" +#include "system_info.h" #include "statusled.h" #include "sdcard_check.h" @@ -372,7 +372,7 @@ extern "C" void app_main(void) StatusLED(PSRAM_INIT, 2, true); } else { // PSRAM size OK --> continue to check heap size - size_t _hsize = getESPHeapSize(); + size_t _hsize = getESPHeapSizeTotal(); LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Total heap: " + std::to_string(_hsize) + " byte"); // Check heap memory @@ -403,18 +403,7 @@ extern "C" void app_main(void) // Print Device info // ******************************************** - #ifdef DEBUG_ENABLE_SYSINFO - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL( 4, 0, 0 ) - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Device Info : " + get_device_info() ); - ESP_LOGD(TAG, "Device infos %s", get_device_info().c_str()); - #endif - #else - esp_chip_info_t chipInfo; - esp_chip_info(&chipInfo); - - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Device info: CPU cores: " + std::to_string(chipInfo.cores) + - ", Chip revision: " + std::to_string(chipInfo.revision/100)); - #endif //DEBUG_ENABLE_SYSINFO + printDeviceInfo(); // Print SD-Card info // ******************************************** diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index f6dadbae6..97dd89972 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -21,6 +21,7 @@ #include #include "Helper.h" +#include "system_info.h" httpd_handle_t server = NULL; std::string starttime = ""; @@ -340,7 +341,7 @@ esp_err_t sysinfo_handler(httpd_req_t *req) std::string gitrevision = libfive_git_revision(); std::string htmlversion = getHTMLversion(); char freeheapmem[11]; - sprintf(freeheapmem, "%lu", (long) getESPHeapSize()); + sprintf(freeheapmem, "%lu", (long) getESPHeapSizeTotal()); zw = std::string("[{") + "\"firmware\": \"" + gitversion + "\"," + diff --git a/code/platformio.ini b/code/platformio.ini index 6731f5fd8..493cfb87f 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -84,7 +84,6 @@ build_flags = ; ### Debug options : -D DEBUG_DETAIL_ON ;-D DEBUG_DISABLE_BROWNOUT_DETECTOR - -D DEBUG_ENABLE_SYSINFO -D DEBUG_ENABLE_PERFMON ;-D DEBUG_HIMEM_MEMORY_CHECK ;-D USE_HIMEM_IF_AVAILABLE