Skip to content

Commit

Permalink
Fighting the restarts :-|
Browse files Browse the repository at this point in the history
- Add many compiler attributes to avoid missaligned memory. Not sure, if all are necessary. But still restarts happen
- putting gas reading into RTC memory (because of restarts). But if too many restarts, value is not accurate
- correct boiler variable assignments
- correct boiler "changed" checking
- moved UART ISR into IRAM
- enabled settings write if Gas Reading will be changed
- correct text for IRT telegram-ID 0x07
- enabled VCC-measurement for analog input
- increased max telegram length to be sure that enough space if read errors occur
  • Loading branch information
harrymayr committed Dec 28, 2022
1 parent b2e554c commit 4e878d6
Show file tree
Hide file tree
Showing 34 changed files with 313 additions and 252 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ emsesp
/interface/.eslintcache
src/pid.cpp
src/pid.h
interface/.idea/inspectionProfiles/Project_Default.xml
interface/.idea/vcs.xml
interface/.idea/workspace.xml
8 changes: 4 additions & 4 deletions interface/src/project/EMSESPSettingsController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
margin="normal"
/>
<TextValidator
validators={['isNumber', 'minNumber:0', 'maxNumber:99999']}
errorMessages={["Must be a number", "Must be 0 or higher", "Max value is 99999 (99999 m³)"]}
validators={['required','isNumber', 'minNumber:0', 'maxNumber:99999']}
errorMessages={['Value is required',"Must be a number", "Must be 0 or higher", "Max value is 99999 (99999 m³)"]}
name="gas_meter_reading"
label="Gas meter reading (m³, 0=not set)"
fullWidth
Expand All @@ -365,8 +365,8 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
margin="normal"
/>
<TextValidator
validators={['isNumber', 'minNumber:0', 'maxNumber:12000']}
errorMessages={["Must be a number", "Must be 0 or higher", "Max value is 12000"]}
validators={['required','isNumber', 'minNumber:0', 'maxNumber:12000']}
errorMessages={['Value is required',"Must be a number", "Must be 0 or higher", "Max value is 12000"]}
name="conv_factor"
label="Conversion factor m³<-> Wh"
fullWidth
Expand Down
50 changes: 30 additions & 20 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
; PlatformIO Project Configuration File for EMS-ESP
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = esp8266

# override any settings with your own local ones in pio_local.ini
; override any settings with your own local ones in pio_local.ini
extra_configs =
factory_settings.ini
pio_local.ini
Expand Down Expand Up @@ -31,49 +39,51 @@ build_flags =
-D ARDUINOJSON_ENABLE_STD_STRING=1
-D PROGMEM_WWW
-D CORS_ORIGIN=\"http://localhost:3000\"
; -D CONFIG_UART_ISR_IN_IRAM
-D CONFIG_UART_ISR_IN_IRAM

[env]
framework = arduino
monitor_speed = 115200
upload_speed = 921600
build_type = release
lib_ldf_mode = chain+

check_tool = cppcheck, clangtidy
check_severity = high, medium
check_flags =
cppcheck: --std=c++11 -v
clangtidy: --checks=-*,clang-analyzer-*,performance-*

; build for GitHub Actions CI
[env:ci]
extra_scripts =
scripts/main_script.py
scripts/rename_fw.py
scripts/main_script.py
scripts/rename_fw.py
board = esp12e
platform = espressif8266
board_build.filesystem = littlefs
board_build.f_cpu = 160000000L
build_flags = ${common.build_flags}
lib_deps = fabianoriccardi/RTCMemory@^2.0.0

[env:esp8266]
extra_scripts =
pre:scripts/build_interface.py
scripts/main_script.py
scripts/rename_fw.py
board = esp12e ; https://github.com/platformio/platform-espressif8266/tree/master/boards
platform = espressif8266 ; https://github.com/platformio/platform-espressif8266/releases
extra_scripts =
pre:scripts/build_interface.py
scripts/main_script.py
scripts/rename_fw.py
;monitor_filters = esp8266_exception_decoder, default
board = esp12e
platform = espressif8266
board_build.filesystem = littlefs
board_build.f_cpu = 160000000L ; 160MHz
; eagle.flash.4m1m.ld = 1019 KB sketch, 1000 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 2052 KB OTA & buffer
; eagle.flash.4m2m.ld = 1019 KB sketch, 2024 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 1028 KB OTA & buffer
; board_build.ldscript = eagle.flash.4m2m.ld
build_flags = ${common.build_flags} ${common.debug_flags}
;-D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
;-D MMU_IRAM_SIZE=0xC000
;-D MMU_ICACHE_SIZE=0x4000
;-D MMU_IRAM_HEAP
-D FLASH_MAP_SUPPORT=1
lib_ignore =
AsyncTCP
; -D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
; -D MMU_IRAM_SIZE=0xC000
; -D MMU_ICACHE_SIZE=0x4000
; -D MMU_IRAM_HEAP
-D FLASH_MAP_SUPPORT=1
lib_ignore =
AsyncTCP
lib_deps = fabianoriccardi/RTCMemory@^2.0.0

4 changes: 2 additions & 2 deletions src/WebSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
// iRT
snprintf_P(&crc_before[0],
crc_before.capacity() + 1,
PSTR("%d%s%d%d"),
PSTR("%d%s%d%d%d%d"),
settings.usr_brand,
settings.usr_type.c_str(),
settings.min_boiler_wh,
Expand All @@ -154,7 +154,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)

snprintf_P(&crc_after[0],
crc_after.capacity() + 1,
PSTR("%d%s%d%d"),
PSTR("%d%s%d%d%d%d"),
settings.usr_brand,
settings.usr_type.c_str(),
settings.min_boiler_wh,
Expand Down
8 changes: 4 additions & 4 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ void EMSESPShell::add_console_commands() {
flash_string_vector{F_(deviceid_mandatory), F_(typeid_mandatory), F_(offset_optional)},
[=](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments) {
uint8_t device_id = Helpers::hextoint(arguments.front().c_str());
uint16_t type_id = Helpers::hextoint(arguments[1].c_str());
uint16_t type_id __attribute__ ((aligned (4))) = Helpers::hextoint(arguments[1].c_str());
EMSESP::set_read_id(type_id);
if (arguments.size() == 3) {
uint16_t offset = Helpers::hextoint(arguments.back().c_str());
uint16_t offset __attribute__ ((aligned (4))) = Helpers::hextoint(arguments.back().c_str());
EMSESP::send_read_request(type_id, device_id, offset);
} else {
EMSESP::send_read_request(type_id, device_id);
Expand Down Expand Up @@ -297,7 +297,7 @@ void EMSESPShell::add_console_commands() {
flash_string_vector{F_(set), F_(timeout)},
flash_string_vector{F_(n_mandatory)},
[](Shell & shell, const std::vector<std::string> & arguments) {
uint16_t value = Helpers::atoint(arguments.front().c_str());
uint16_t value __attribute__ ((aligned (4))) = Helpers::atoint(arguments.front().c_str());
telnet_.initial_idle_timeout(value * 60);
shell.printfln(F("Telnet timeout is %d minutes"), value);
});
Expand All @@ -308,7 +308,7 @@ void EMSESPShell::add_console_commands() {
flash_string_vector{F_(watch)},
flash_string_vector{F_(watch_format_optional), F_(watchid_optional)},
[](Shell & shell, const std::vector<std::string> & arguments) {
uint16_t watch_id = WATCH_ID_NONE;
uint16_t watch_id __attribute__ ((aligned (4))) = WATCH_ID_NONE;

if (!arguments.empty()) {
// get raw/pretty
Expand Down
4 changes: 2 additions & 2 deletions src/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class EMSESPStreamConsole : public uuid::console::StreamConsole, public EMSESPSh

std::string name_;
size_t pty_;
IPAddress addr_;
uint16_t port_;
IPAddress addr_ __attribute__ ((aligned (4)));
uint16_t port_ __attribute__ ((aligned (4)));
};

class Console {
Expand Down
6 changes: 3 additions & 3 deletions src/dallassensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void DallasSensor::reload() {

void DallasSensor::loop() {
#ifndef EMSESP_STANDALONE
uint32_t time_now = uuid::get_uptime();
uint32_t time_now __attribute__ ((aligned (4))) = uuid::get_uptime();

if (state_ == State::IDLE) {
if (time_now - last_activity_ >= READ_INTERVAL_MS) {
Expand Down Expand Up @@ -116,7 +116,7 @@ void DallasSensor::loop() {
case TYPE_DS18S20:
case TYPE_DS1822:
case TYPE_DS1825:
int16_t t;
int16_t t __attribute__ ((aligned (4)));
t = get_temperature_c(addr);
if ((t >= -550) && (t <= 1250)) {
// check if we have this sensor already
Expand Down Expand Up @@ -228,7 +228,7 @@ int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
return EMS_VALUE_SHORT_NOTSET;
}

int16_t raw_value = ((int16_t)scratchpad[SCRATCHPAD_TEMP_MSB] << 8) | scratchpad[SCRATCHPAD_TEMP_LSB];
int16_t raw_value __attribute__ ((aligned (4))) = ((int16_t)scratchpad[SCRATCHPAD_TEMP_MSB] << 8) | scratchpad[SCRATCHPAD_TEMP_LSB];

if (addr[0] == TYPE_DS18S20) {
raw_value = (raw_value << 3) + 12 - scratchpad[SCRATCHPAD_CNT_REM];
Expand Down
18 changes: 9 additions & 9 deletions src/dallassensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class DallasSensor {
uint64_t id() const;
std::string to_string() const;

int16_t temperature_c = EMS_VALUE_SHORT_NOTSET;
int16_t temperature_c __attribute__ ((aligned (4))) = EMS_VALUE_SHORT_NOTSET;
bool read = false;

private:
const uint64_t id_;
const uint64_t id_ __attribute__ ((aligned (4)));
};

DallasSensor() = default;
Expand Down Expand Up @@ -87,10 +87,10 @@ class DallasSensor {
static constexpr uint8_t TYPE_DS1822 = 0x22;
static constexpr uint8_t TYPE_DS1825 = 0x3B; // also DS1826

static constexpr uint32_t READ_INTERVAL_MS = 5000; // 5 seconds
static constexpr uint32_t CONVERSION_MS = 1000; // 1 seconds
static constexpr uint32_t READ_TIMEOUT_MS = 2000; // 2 seconds
static constexpr uint32_t SCAN_TIMEOUT_MS = 3000; // 3 seconds
static constexpr uint32_t READ_INTERVAL_MS __attribute__ ((aligned (4))) = 5000; // 5 seconds
static constexpr uint32_t CONVERSION_MS __attribute__ ((aligned (4))) = 1000; // 1 seconds
static constexpr uint32_t READ_TIMEOUT_MS __attribute__ ((aligned (4))) = 2000; // 2 seconds
static constexpr uint32_t SCAN_TIMEOUT_MS __attribute__ ((aligned (4))) = 3000; // 3 seconds

static constexpr uint8_t CMD_CONVERT_TEMP = 0x44;
static constexpr uint8_t CMD_READ_SCRATCHPAD = 0xBE;
Expand All @@ -111,8 +111,8 @@ class DallasSensor {
bool command_info(const char * value, const int8_t id, JsonObject & json);
bool export_values(JsonObject & doc);

uint32_t last_activity_ = uuid::get_uptime();
uint32_t last_publish_ = uuid::get_uptime();
uint32_t last_activity_ __attribute__ ((aligned (4))) = uuid::get_uptime();
uint32_t last_publish_ __attribute__ ((aligned (4))) = uuid::get_uptime();
State state_ = State::IDLE;
std::vector<Sensor> sensors_;

Expand All @@ -124,7 +124,7 @@ class DallasSensor {
uint8_t dallas_gpio_ = 0;
bool parasite_ = false;
bool changed_ = false;
uint32_t sensorfails_ = 0;
uint32_t sensorfails_ __attribute__ ((aligned (4))) = 0;
};

} // namespace emsesp
Expand Down
Loading

0 comments on commit 4e878d6

Please sign in to comment.