add command system/fuse/mfg, board E32V2.2, check systemvolatage >2.6V

This commit is contained in:
MichaelDvP
2025-07-28 13:47:52 +02:00
parent c27134f185
commit 2aa691212c
6 changed files with 55 additions and 18 deletions

View File

@@ -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',

View File

@@ -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

View File

@@ -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;
}

View File

@@ -50,6 +50,8 @@
#include <HTTPClient.h>
#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<int8_t> & 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) {

View File

@@ -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;
}
}
}

View File

@@ -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
}