From 2aa691212c41b82179227d8c1541f2b0b782284a Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 28 Jul 2025 13:47:52 +0200 Subject: [PATCH] add command system/fuse/mfg, board E32V2.2, check systemvolatage >2.6V --- interface/src/app/main/types.ts | 2 +- src/core/analogsensor.cpp | 8 +++---- src/core/helpers.cpp | 7 +++++- src/core/system.cpp | 40 ++++++++++++++++++++++++++++----- src/core/temperaturesensor.cpp | 12 +++++----- src/web/WebSettingsService.cpp | 4 ++-- 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/interface/src/app/main/types.ts b/interface/src/app/main/types.ts index 272228d18..924d57a5a 100644 --- a/interface/src/app/main/types.ts +++ b/interface/src/app/main/types.ts @@ -259,7 +259,7 @@ export const BOARD_PROFILES: BoardProfiles = { S32S3: 'BBQKees Gateway S3', E32: 'BBQKees Gateway E32', E32V2: 'BBQKees Gateway E32 V2', - E32V3: 'BBQKees Gateway E32 V3', + E32V2_2: 'BBQKees Gateway E32 V2.2', NODEMCU: 'NodeMCU 32S', 'MH-ET': 'MH-ET Live D1 Mini', LOLIN: 'Lolin D32', diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 241acf08d..dadebe4e4 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -24,8 +24,8 @@ namespace emsesp { uuid::log::Logger AnalogSensor::logger_{F_(analogsensor), uuid::log::Facility::DAEMON}; void AnalogSensor::start(const bool factory_settings) { - // if (factory_settings && EMSESP::nvs_.getString("boot").equals("E32V3") && EMSESP::nvs_.getString("hwrevision").equals("3.0")) { - if (factory_settings && analogReadMilliVolts(39) > 800) { // core voltage > 3V + // if (factory_settings && EMSESP::nvs_.getString("boot").equals("E32V2_2") && EMSESP::nvs_.getString("hwrevision").equals("3.0")) { + if (factory_settings && analogReadMilliVolts(39) > 700) { // core voltage > 2.6V EMSESP::webCustomizationService.update([&](WebCustomization & settings) { auto newSensor = AnalogCustomization(); newSensor.gpio = 39; @@ -35,8 +35,8 @@ void AnalogSensor::start(const bool factory_settings) { newSensor.uom = DeviceValueUOM::VOLTS; newSensor.type = AnalogType::ADC; settings.analogCustomizations.push_back(newSensor); - newSensor.gpio = 36; - newSensor.name = "supply_voltage"; + newSensor.gpio = 36; + newSensor.name = "supply_voltage"; newSensor.factor = 0.017; // Divider 24k - 1,5k settings.analogCustomizations.push_back(newSensor); return StateUpdateResult::CHANGED; // persist the change diff --git a/src/core/helpers.cpp b/src/core/helpers.cpp index 685181bce..911ca5876 100644 --- a/src/core/helpers.cpp +++ b/src/core/helpers.cpp @@ -524,7 +524,12 @@ bool Helpers::value2number(const char * value, int & value_i, const int min, con return false; } - value_i = atoi(value); + if (strlen(value) > 2 && value[0] == '0' && value[1] == 'x') { + value_i = hextoint(value); + } else { + value_i = atoi(value); + } + if (value_i >= min && value_i <= max) { return true; } diff --git a/src/core/system.cpp b/src/core/system.cpp index 5a4186d57..4797b2d5e 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -50,6 +50,8 @@ #include +#include "esp_efuse.h" + namespace emsesp { // Languages supported. Note: the order is important @@ -1423,6 +1425,13 @@ bool System::command_service(const char * cmd, const char * value) { ok = true; } } + int n; + if (!ok && Helpers::value2number(value, n)) { + if (!strcmp(cmd, "fuse/mfg")) { // && esp_efuse_read_reg(EFUSE_BLK3, 0) == 0) { + ok = esp_efuse_write_reg(EFUSE_BLK3, 0, (uint32_t)n) == ESP_OK; + LOG_INFO("fuse programed with value '%X': %s", n, ok ? "successful" : "failed"); + } + } if (ok) { LOG_INFO("System command '%s' with value '%s'", cmd, value); @@ -1877,8 +1886,8 @@ bool System::load_board_profile(std::vector & data, const std::string & data = {2, 4, 5, 17, 33, PHY_type::PHY_TYPE_LAN8720, 16, 1, 0, 0}; // BBQKees Gateway E32 } else if (board_profile == "E32V2") { data = {2, 14, 4, 5, 34, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1, 0}; // BBQKees Gateway E32 V2 - } else if (board_profile == "E32V3") { - data = {32, 14, 4, 5, 34, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1, 1}; // BBQKees Gateway E32 V3 + } else if (board_profile == "E32V2_2") { + data = {32, 14, 4, 5, 34, PHY_type::PHY_TYPE_LAN8720, 15, 0, 1, 1}; // BBQKees Gateway E32 V2.2, rgb led } else if (board_profile == "MH-ET") { data = {2, 18, 23, 5, 0, PHY_type::PHY_TYPE_NONE, 0, 0, 0, 0}; // MH-ET Live D1 Mini } else if (board_profile == "NODEMCU") { @@ -2029,6 +2038,7 @@ bool System::ntp_connected() { // see if its a BBQKees Gateway by checking the nvs values String System::getBBQKeesGatewayDetails() { #ifndef EMSESP_STANDALONE + /* if (!EMSESP::nvs_.isKey("mfg")) { return ""; } @@ -2042,6 +2052,26 @@ String System::getBBQKeesGatewayDetails() { } return "BBQKees Gateway Model " + EMSESP::nvs_.getString("model") + " v" + EMSESP::nvs_.getString("hwrevision") + "/" + EMSESP::nvs_.getString("batch"); +*/ + union { + struct { + uint32_t no : 4; + uint32_t month : 4; + uint32_t year : 8; + uint32_t rev_minor : 4; + uint32_t rev_major : 4; + uint32_t model : 4; + uint32_t mfg : 4; + }; + uint32_t reg; + } gw; + gw.reg = esp_efuse_read_reg(EFUSE_BLK3, 0); + const char * mfg[] = {"unknown", "BBQKees Electronics", "", "", "", "", "", ""}; + const char * model[] = {"unknown", "S3", "E32V2", "E32V2.2", "S32", "E32", "", "", ""}; + + return gw.reg ? String(mfg[gw.mfg]) + " " + String(model[gw.model]) + " rev." + String(gw.rev_major) + "." + String(gw.rev_minor) + "/" + + String(2000 + gw.year) + "-" + String(gw.month) + "-" + String(gw.no) + " (fuse 0x" + String(gw.reg, 16) + ")" + : ""; #else return ""; #endif @@ -2160,7 +2190,7 @@ bool System::readCommand(const char * data) { // first check deviceID if ((p = strtok(data_args, " ,"))) { // delimiter comma or space - strlcpy(value, p, 10); // get string + strlcpy(value, p, sizeof(value)); // get string device_id = (uint8_t)Helpers::hextoint(value); // convert hex to int if (!EMSESP::valid_device(device_id)) { LOG_ERROR("Invalid device ID (0x%02X) in read command", device_id); @@ -2171,8 +2201,8 @@ bool System::readCommand(const char * data) { // iterate until end uint8_t num_args = 0; while (p != 0) { - if ((p = strtok(nullptr, " ,"))) { // delimiter comma or space - strlcpy(value, p, 10); // get string + if ((p = strtok(nullptr, " ,"))) { // delimiter comma or space + strlcpy(value, p, sizeof(value)); // get string if (num_args == 0) { type_id = (uint16_t)Helpers::hextoint(value); // convert hex to int } else if (num_args == 1) { diff --git a/src/core/temperaturesensor.cpp b/src/core/temperaturesensor.cpp index a567e8aa9..af03f2831 100644 --- a/src/core/temperaturesensor.cpp +++ b/src/core/temperaturesensor.cpp @@ -33,8 +33,8 @@ uuid::log::Logger TemperatureSensor::logger_{F_(temperaturesensor), uuid::log::F // start the 1-wire void TemperatureSensor::start(const bool factory_settings) { - // set_internal_ = factory_settings && EMSESP::nvs_.getString("boot").equals("E32V3") && EMSESP::nvs_.getString("hwrevision").equals("3.0"); - set_internal_ = factory_settings && analogReadMilliVolts(39) > 800; // core voltage > 3V + // set_internal_ = factory_settings && EMSESP::nvs_.getString("boot").equals("E32V2_2") && EMSESP::nvs_.getString("hwrevision").equals("3.0"); + set_internal_ = factory_settings && analogReadMilliVolts(39) > 700; // core voltage > 2.6V reload(); if (!dallas_gpio_) { @@ -205,9 +205,11 @@ void TemperatureSensor::loop() { set_internal_ = false; Sensor * s = &sensors_[0]; if (firstscan_ > 1) { - for (auto s1 : sensors_) { - if (EMSESP::nvs_.getString("intTemp").equals(s1.id().c_str())) { - s = &s1; + std::string s_nvs = EMSESP::nvs_.getString("intTemp").c_str(); + for (uint8_t i = 0; i < firstscan_; i++) { + if (s_nvs == sensors_[i].id()) { + s = &sensors_[i]; + break; } } } diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index c23852482..849484949 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -180,8 +180,8 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) { if (ETH.begin(ETH_PHY_LAN8720, 0, 23, 18, 15, ETH_CLOCK_GPIO0_OUT)) { #endif - if (analogReadMilliVolts(39) > 800) { // core voltage > 3V - settings.board_profile = "E32V3"; // Ethernet, PSRAM, internal sensors + if (analogReadMilliVolts(39) > 700) { // core voltage > 2.6V + settings.board_profile = "E32V2_2"; // Ethernet, PSRAM, internal sensors } else { settings.board_profile = "E32V2"; // Ethernet and PSRAM }