Skip to content

Commit

Permalink
allow valve control after user wakeup in low battery state, SDK 2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsbyr committed Jun 5, 2024
1 parent beb4695 commit b0a86eb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
22 changes: 14 additions & 8 deletions firmware/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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)
66 changes: 42 additions & 24 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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
4 changes: 3 additions & 1 deletion firmware/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
7 changes: 4 additions & 3 deletions firmware/user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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");

Expand All @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion firmware/user/valve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b0a86eb

Please sign in to comment.