From b0a86eb26ab53dea9971857563cbdd95dabb2c72 Mon Sep 17 00:00:00 2001 From: "Jens B." Date: Wed, 5 Jun 2024 21:57:10 +0200 Subject: [PATCH] allow valve control after user wakeup in low battery state, SDK 2.2.1 --- firmware/CHANGES | 22 +++++++++----- firmware/Makefile | 66 ++++++++++++++++++++++++++--------------- firmware/include/main.h | 4 ++- firmware/user/main.c | 7 +++-- firmware/user/valve.c | 2 +- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/firmware/CHANGES b/firmware/CHANGES index be77d37..c66f812 100644 --- a/firmware/CHANGES +++ b/firmware/CHANGES @@ -143,18 +143,24 @@ CHANGES send RSSI in SleeperRequest message (feature) 0.9.1.2 - 20.04.2018 - double timeout when using DHCP - report valve driver type by appending 'C' (capacitor) or 'H' (H-bridge) to version + double timeout when using DHCP (feature) + report valve driver type by appending 'C' (capacitor) or 'H' (H-bridge) to version (feature) 0.9.2.0 - 27.12.2018 - based on SDK 2.2.2-dev(d5966c3) + based on SDK 2.2.0-dev(d5966c3) (feature) skip parsing activies if program ID is zero or program ID has not changed (bugfix) 0.9.3.0 - 30.12.2018 - permanent deep sleep after low battery detection and reporting - capacitor valve driver: - - monitor valve control voltage to detect wiring errors (e.g. valve not connected, - connector corroded, etc.) and to reduce operating time + permanent deep sleep after low battery detection and reporting (feature) + capacitor valve driver (feature): + - monitor valve control voltage to detect wiring errors (e.g. valve not connected, + connector corroded, etc.) and to reduce operating time - disable remote valve operation after detecting valve operation error - report valve operation error via mode property in server request - - max. valve resistance configurable via server reply + - max. valve resistance configurable via server reply + +0.9.3.1 - 27.01.2019 + allow valve control after user wakeup in low battery state (feature) + +0.9.3.2 - 27.11.2019 + based on Espressif SDK 2.2.1 (feature) diff --git a/firmware/Makefile b/firmware/Makefile index 6c8a798..5adb5dc 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -12,37 +12,43 @@ # # project name -TARGET = sleeper-0.9.3.0 +VERSION = 0.9.3.2 +TARGET = sleeper-${VERSION} # source subdirectories MODULES = user # libraries, mainly provided by the SDK -LIBS = c m gcc hal phy pp net80211 lwip wpa crypto main json +LIBS = c m gcc phy pp net80211 lwip wpa crypto main json # ESP8266 flash parameters (dependent on ESP8266 hardware) -FLASHSIZE = 4m -FLASHPARMS = --flash_freq 40m --flash_mode qio --flash_size ${FLASHSIZE} +#FLASHSIZE = 4m +#FLASHMODE = qio +FLASHSIZE = 8m +#FLASHMODE = dio +#FLASHSIZE = detect +#FLASHPARMS = --flash_freq 40m --flash_mode ${FLASHMODE} --flash_size ${FLASHSIZE} +FLASHPARMS = --flash_size ${FLASHSIZE} # flash tool parameters (dependent on PC UART hardware) ESPPORT = COM5 -ESPBAUD = 74880 +#ESPBAUD = 74880 -# Xtensa LX compiler path +# Xtensa LX compiler path (4.5.0 for SDK < 3.0) XTENSA_TOOLS_ROOT ?= c:/Espressif/xtensa-lx106-elf/bin # Espressif SDK # SDK 1.5.3 - 18.04.2016 -# SDK 2.2.2 - 26.12.2018 -#SDK_BASE ?= C:/Espressif/ESP8266_SDK_153 -SDK_BASE ?= C:/Espressif/ESP8266_SDK_220 -SDK_TOOLS ?= C:/Espressif/utils -ESPTOOL ?= ${SDK_TOOLS}/esptool.exe +# SDK 2.2.0 - 26.12.2018 +# SDK 2.2.1 - 27.11.2019 +SDK_BASE ?= C:/Espressif/ESP8266_NONOS_SDK-2.2.1 +SDK_TOOLS ?= C:/Espressif/utils/ESP8266 +#ESPTOOL ?= ${SDK_TOOLS}/esptool.exe +ESPTOOL ?= python C:/Espressif/esptool/esptool.py #ESPINITDATA = $(SDK_BINDIR)/esp_init_data_default.bin #ESPINITDATA = $(SDK_BINDIR)/esp_init_data_default_v08.bin ESPINITDATA = bin/esp_init_data_setting.bin - # # Normally nothing to configure south of here. # @@ -86,7 +92,7 @@ OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objcopy OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump # setup input and output paths as well as build objects -INCDIR = include +INCDIR = include BUILD_BASE = build FW_BASE = firmware SDK_BINDIR := $(addprefix $(SDK_BASE)/, $(SDK_BINDIR)) @@ -110,7 +116,7 @@ $(APP_AR): $(OBJS) # compile C source files $(BUILD_BASE)/%.o : %.c - $(CC) $(INCDIR) $(MODULE_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $< -o $@ + $(CC) $(INCDIR) $(MODULE_INCDIR) $(SDK_INCDIR) $(CFLAGS) -DSLEEPER_VERSION=\"${VERSION}\" -c $< -o $@ # check required build directories checkdirs: $(BUILD_DIR) @@ -132,32 +138,42 @@ $(TARGET_OUT): $(APP_AR) $(OBJCOPY) --only-section .data --output-target binary $@ eagle.app.v6.data.bin $(OBJCOPY) --only-section .rodata --output-target binary $@ eagle.app.v6.rodata.bin $(OBJCOPY) --only-section .irom0.text --output-target binary $@ eagle.app.v6.irom0text.bin - $(SDK_TOOLS)/gen_appbin.exe $@ 0 0 0 0 + $(SDK_TOOLS)/gen_appbin.exe $@ 0 0 0 0 0 mv eagle.app.flash.bin $(FW_BASE)/eagle.flash.bin mv eagle.app.v6.irom0text.bin $(FW_BASE)/eagle.irom0text.bin rm eagle.app.v6.* flash: all - $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ +# 8Mbit / 1MB + $(ESPTOOL) --port $(ESPPORT) write_flash $(FLASHPARMS) \ 0x00000 $(FW_BASE)/eagle.flash.bin \ 0x10000 $(FW_BASE)/eagle.irom0text.bin +# $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ +# 0x00000 $(FW_BASE)/eagle.flash.bin \ +# 0x10000 $(FW_BASE)/eagle.irom0text.bin flash-init-data: ifeq ($(FLASHSIZE), 4m) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ 0x7C000 $(ESPINITDATA) -else - $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ - 0xFC000 $(ESPINITDATA) +else +# 8Mbit / 1MB + $(ESPTOOL) --port $(ESPPORT) write_flash $(FLASHPARMS) \ + 0xFC000 $(ESPINITDATA) +# $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ +# 0xFC000 $(ESPINITDATA) endif flash-default-params: ifeq ($(FLASHSIZE), 4m) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ 0x7E000 $(SDK_BINDIR)/blank.bin -else - $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ - 0xFE000 $(SDK_BINDIR)/blank.bin +else +# 8Mbit / 1MB + $(ESPTOOL) --port $(ESPPORT) write_flash $(FLASHPARMS) \ + 0xFE000 $(SDK_BINDIR)/blank.bin +# $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(FLASHPARMS) \ +# 0xFE000 $(SDK_BINDIR)/blank.bin endif clean: @@ -168,10 +184,12 @@ clean: rm -rf $(FW_BASE) readFlashId: - $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) flash_id + $(ESPTOOL) --port $(ESPPORT) flash_id +# $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) flash_id readMac: - $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) read_mac + $(ESPTOOL) --port $(ESPPORT) read_mac +# $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) read_mac imageInfo: $(ESPTOOL) image_info $(FW_BASE)/eagle.flash.bin \ No newline at end of file diff --git a/firmware/include/main.h b/firmware/include/main.h index e90bfe6..b0593d7 100644 --- a/firmware/include/main.h +++ b/firmware/include/main.h @@ -123,8 +123,10 @@ typedef struct uint8 timeSynchronized; // bool, current time is synchronized with server } SleeperStateT; - uint64 getTime(); void comProcessing(); +// @see ld/eagle.rom.addr.v6.ld +extern int ets_uart_printf(const char *format, ...); + #endif /* __USER_MAIN_H__ */ diff --git a/firmware/user/main.c b/firmware/user/main.c index 6793bdd..761e747 100644 --- a/firmware/user/main.c +++ b/firmware/user/main.c @@ -64,7 +64,7 @@ #include "valve.h" #include "uplink.h" -#define VERSION "0.9.3.0" +#define VERSION SLEEPER_VERSION // manual start/stop GPIO input #define USER_WAKEUP_GPIO_MUX PERIPHS_IO_MUX_MTMS_U @@ -951,6 +951,7 @@ void ICACHE_FLASH_ATTR user_init() } // check battery voltage + bool userWakeup = isUserWakeup(); state.now = getTime(); if (!state.rtcMem.lowBattery && state.batteryVoltage < MIN_BATTERY_VOLTAGE) { @@ -975,7 +976,7 @@ void ICACHE_FLASH_ATTR user_init() } // enter permanent deep sleep for maximum battery lifetime after reporting duration has expired - if (state.now >= state.rtcMem.lowBatteryTime + LOW_BATTERY_REPORTING_DURATION) + if (!userWakeup && state.now >= state.rtcMem.lowBatteryTime + LOW_BATTERY_REPORTING_DURATION) { ets_uart_printf("WARNING: low battery shutdown\r\n"); @@ -989,7 +990,7 @@ void ICACHE_FLASH_ATTR user_init() } // wakeup caused by user? - if (isUserWakeup()) + if (userWakeup) { ets_uart_printf("wakeup by user\r\n"); diff --git a/firmware/user/valve.c b/firmware/user/valve.c index 743b187..17f186a 100644 --- a/firmware/user/valve.c +++ b/firmware/user/valve.c @@ -190,7 +190,7 @@ LOCAL void ICACHE_FLASH_ATTR valveOpen(SleeperStateT* sleeperState) ets_uart_printf("valve: resistance %u ohm after %lu us\r\n", resistance, duration); } } while (duration < timeout); - ets_uart_printf("valve: charged %u -> %u mV in %lu us\r\n", dischargedVoltage, chargedVoltage, duration); + ets_uart_printf("valve: charged %u -> %u mV @ %s in %lu us\r\n", dischargedVoltage, chargedVoltage, supplyVolage, duration); // disable power to valve and disable generator GPIO_DIS_OUTPUT(OPEN_VALVE_GPIO);