Hi all,
I wrote a code for esphome, but I got that if I add other lines of code when I flash the board something does not work…
at the end of the flash operation the board goes in a continuos reset… and I get this log:
[00:18:21]load:0x3fff0018,len:4
[00:18:21]load:0x3fff001c,len:1044
[00:18:21]load:0x40078000,len:8896
[00:18:21]load:0x40080400,len:5828
[00:18:21]entry 0x400806ac
[00:18:21]ets Jun 8 2016 00:22:57
[00:18:21]
[00:18:21]rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[00:18:21]configsip: 0, SPIWP:0xee
[00:18:21]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[00:18:21]mode:DIO, clock div:2
[00:18:21]load:0x3fff0018,len:4
[00:18:21]load:0x3fff001c,len:1044
[00:18:21]load:0x40078000,len:8896
[00:18:21]load:0x40080400,len:5828
[00:18:21]entry 0x400806ac
I’ve this occupation of resources
RAM: [== ] 16.7% (used 54652 bytes from 327680 bytes)
Flash: [========= ] 89.6% (used 1644658 bytes from 1835008 bytes)
following the board informations :
Chip Info:
- Chip Family: ESP32
- Chip Model: ESP32D0WDQ6 (revision 1)
- Number of Cores: 2
- Max CPU Frequency: 240MHz
- Has Bluetooth: YES
- Has Embedded Flash: NO
- Has Factory-Calibrated ADC: YES
- MAC Address: AC:67:B2:3F:51:F8
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
- Flash Size: 4MB
- Flash Mode: dio
- Flash Frequency: 40MHz
This is my code:
################################################################################
# SPRINKLER #
#Pinout: https://circuits4you.com/wp-content/uploads/2018/12/ESP32-Pinout.jpg #
#Solenoid: Bistable 9v
# #
################################################################################
substitutions:
green_button: GPIO12
red_button: GPIO13
pin_sprinkler_on: GPIO23
pin_sprinkler_off: GPIO22
battery_acquisition: GPIO39
battery_acquisition_switch: GPIO25
default_deep_sleep_duration: 1min
default_run_duration: 120min
globals:
- id: default_irrigation_time #Used instead of irrigation_time when it result not a number
type: double
restore_value: no
initial_value: '10'
esphome:
name: irrigatore
platform: ESP32
board: esp-wrover-kit
# board_flash_mode: qio
on_boot:
priority: -100
then:
- logger.log: "Hello word!" #Just to test the on boot feature - I would perform on boot the battery voltage prior to open the solenoid
###############################################################
# WIFI - OTA and static IP management #
###############################################################
wifi:
networks:
- ssid: xxx
password: xxx
- ssid: xxx
password: xxx
# Static IP
manual_ip:
static_ip: 192.168.1.30
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Sprinkler Fallback Hotspot"
password: "xxx"
ota:
web_server:
port: 80
captive_portal:
###############################################################
# LOGGER MANAGEMENT #
###############################################################
# Enable logging
logger:
###############################################################
# HOME ASSISTANT #
###############################################################
# Enable Home Assistant API
api:
#This service will allow you to set the duration_of_irrigation variable via mqtt - the duration_of_irrigation variable will be used to define the irrigation time (remember the solenoid is a bistable one)
#To use this service the device must be awake
services:
- service: set_irrigation_time
variables:
duration_of_irrigation: float
then:
- lambda: |-
id(irrigation_time).state = duration_of_irrigation;
###############################################################
# MQTT Configuration #
###############################################################
mqtt:
broker: 192.168.1.20
port: 1883
username: xxx
password: xxx
on_message:
- topic: irrigatore/ota_mode #to avoid the deep sleep in to be able to perfom the OTA as soon as the device wakes up - example on ESPHOME web site
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_23
- topic: irrigatore/sleep_mode #to force the deep sleep - example on ESPHOME web site
payload: 'ON'
then:
- deep_sleep.enter: deep_sleep_23
###############################################################
# Bluetooth configuration #
###############################################################
esp32_ble_tracker:
###############################################################
# SWITCH #
###############################################################
switch:
- platform: restart
name: "Restart"
#######################################################################################################
# #
# .-'''-. .-------. .-------. .-./`) ,---. .--..--. .--. .---. .-''-. .-------. #
# / _ \\ _(`)_ \| _ _ \ \ .-.')| \ | || | _/ / | ,_| .'_ _ \ | _ _ \ #
# (`' )/`--'| (_ o._)|| ( ' ) | / `-' \| , \ | || (`' ) / ,-./ ) / ( ` ) '| ( ' ) | #
#(_ o _). | (_,_) /|(_ o _) / `-'`"`| |\_ \| ||(_ ()_) \ '_ '`) . (_ o _) ||(_ o _) / #
# (_,_). '. | '-.-' | (_,_).' __ .---. | _( )_\ || (_,_) __ > (_) ) | (_,_)___|| (_,_).' __ #
#.---. \ :| | | |\ \ | || | | (_ o _) || |\ \ | |( . .-' ' \ .---.| |\ \ | | #
#\ `-' || | | | \ `' /| | | (_,_)\ || | \ `' / `-'`-'|___\ `-' /| | \ `' / #
# \ / / ) | | \ / | | | | | || | \ / | \\ / | | \ / #
# `-...-' `---' ''-' `'-' '---' '--' '--'`--' `'-' `--------` `'-..-' ''-' `'-' #
# #
#######################################################################################################
#############################################################################
# SPRINKLER MANAGEMENT #
#note: #
#To open the solenoid is enough one pulse (500ms) - negative voltage #
#To close the solenoide are needed more than one pulse - positive voltage #
#The solenoid is the one got from the acquauno device #
#############################################################################
###############################################################
# IRRIGATION START MANAGEMENT #
###############################################################
#switch:
- platform: gpio
pin: $pin_sprinkler_on
id: switch1
- platform: template
name: "inizia irrigazione"
id: watering_start
icon: "mdi:sprinkler"
turn_on_action:
- logger.log: "Action: Watering begins"
#Lambda filter checks if the sleep time is "not a number" if it is, the sleep duration will be setted to a default value
- lambda: |-
if(isnan(id(irrigation_time).state))
{
ESP_LOGD("Mymodule", "********* Error: Default irrigation time - The irrigation will last %.1f second ********", id(default_irrigation_time));
id(deep_sleep_23).set_sleep_duration(id(default_irrigation_time)*1000);
}
else
{
ESP_LOGD("Mymodule", "great! we are in the else branch!!!");
id(deep_sleep_23).set_sleep_duration(id(irrigation_time).state*1000);
}
#Start irrigation
- switch.turn_on: switch1 # _
- delay: 500ms #negative pulse duration # _| |_ -7v
- switch.turn_off: switch1
# Send the ESP32 in deep sleep for the duration of irrigation
- logger.log:
format: "the irrigation it will last %.1f seconds " #---------- to be converted in minutes
args: [ id(irrigation_time).state ]
###############################################################
# IRRIGATION ENDS MANAGEMENT #
###############################################################
- platform: gpio
pin: $pin_sprinkler_off
id: switch2
- platform: template
name: "termina irrigazione"
id: watering_stop
icon: "mdi:flower-outline"
turn_on_action:
# - logger.log: "Action:Irrigation ends "
- switch.turn_on: switch2
- delay: 500ms
- switch.turn_off: switch2
- delay: 500ms
- switch.turn_on: switch2
- delay: 500ms
# _ _ _
#three positive pulse to close the solenoid - duration 500 ms x 3 # _| |__| |_ _| |_ +7v
# - logger.log:
# format: "The sprinkler is going to sleep for %.1f seconds " #To be converted in minutes
# args: [ id(irrigation_time).state ]
# - deep_sleep.enter:
# id: deep_sleep_23
# sleep_duration: 20min
# #********************************#
#Switch controllo sensori
# - platform: gpio
# pin: GPIO15
# id: power_moisture_sensor
# name: "Moisture sensor"
# icon: "mdi:toggle-switch"
#Switch controllo sensori
# - platform: gpio
# pin: $battery_acquisition_switch
# id: power_supply_battery_sensor
# name: "supply battery sensor"
# icon: "mdi:toggle-switch"
###############################################################
# GESTIONE MANUALE DELL'IRRIGAZIONE #
###############################################################
binary_sensor:
#Green button watering start
- platform: gpio
pin:
number: $green_button
mode: INPUT_PULLDOWN
inverted: False
filters:
- delayed_on: 10ms
name: "button start sprinkler"
on_press:
- switch.toggle: watering_start
- logger.log: "button start sprinkler pressed"
#Red button watering stop
- platform: gpio
pin:
number: $red_button
mode: INPUT_PULLDOWN
inverted: False
filters:
- delayed_on: 10ms
name: "button stop sprinkler"
on_press:
- switch.toggle: watering_stop
- logger.log: "button stop sprrinkler pressed"#
#################################################
# SENSOR #
#################################################
sensor:
- platform: homeassistant
name: "irrigation_time"
entity_id: sensor.irrigation_time
id: irrigation_time
#ADC
#Acquisition of battery voltage - needed to check the residual charge
# - platform: adc
# pin: $battery_acquisition
# name: "Voltage supply battery"
# id: V_bat
# attenuation: 11db
# update_interval: 1s
# filters:
# - calibrate_linear:
# - 0.0 -> 0.0
# - 2.49 -> 2.74
# - 2.99 -> 2.68
# - 3.04 -> 2.71
# - 3.08 -> 2.74
# - 3.85 -> 3.14
# - median:
# window_size: 3
# send_every: 4
# send_first_at: 3
# icon: "mdi:battery-medium"
#Acquisition of capacitive moisture sensor
# - platform: adc
# pin: GPIO34
# attenuation: 11db
##The goal of this filter is convert the measured value in a percentage value were
## x is the value got from the ADC during the operation, 2.84 is the value got from the ADC when the sensor is immersed in water (full wet) and 1.67 is the value got from the ADC when the sensor in full dry
# filters:
# - lambda: |-
# if (x > 2.84) {
# return 0;
# } else if (x < 1.67) {
# return 100;
# } else {
# return (2.84-x) / (2.84-1.67) * 100.0;
# }
# - median:
# window_size: 7
# send_every: 4
# send_first_at: 3
# name: "Soil Moisture Level"
# update_interval: 1s
# icon: "mdi:water-percent"
# unit_of_measurement: "%"
#Gateway Plant sensors Xiaomi
- platform: xiaomi_hhccjcy01
mac_address: 'C4:7C:8D:6C:14:F9'
temperature:
name: "Temperatura camelia"
moisture:
name: "Umidità camelia"
illuminance:
name: "Luminosità camelia"
conductivity:
name: "Conduttività camelia"
#Wi-Fi signal strength
- platform: wifi_signal
name: sprinkler wifi signal power
id: wifi_signal_db
update_interval: 60s
# on_raw_value:
# then:
# - text_sensor.template.publish:
# id: wifi_signal_power_percentage
# state: !lambda |-
# int power = round(100*(1-((0-id(wifi_signal_db).raw_state)/(100))));
# return (
# (String(power) + " %")
# ).c_str();
#Uptime sensor
#This sensor is useful during the development to check immediately if something strange happened but will be removed in the final firmware
- platform: uptime
name: Uptime Sensor
id: uptime_sensor
update_interval: 10s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
#This sensor is used during the development
#The status change from 1 to 0 is intercepted by an automation in "home assistant" who send me a message via telegram to inform that the board had a reset
- platform: template
name: status
update_interval: 10s
id: status
lambda: !lambda |-
if(id(uptime_sensor).state >15){
return 1;
}
else
{
return 0;
}
# makes more easy to read the uptime sensor - example from ESPHOME web site
text_sensor:
- platform: template
name: Uptime Human Readable
id: uptime_human
icon: mdi:clock-start
# - platform: template
# name: Wifi signal level (%)
# id: wifi_signal_power_percentage
# icon: mdi:Wifi
# Deep Sleep Feature.
deep_sleep:
run_duration: $default_run_duration
sleep_duration: $default_deep_sleep_duration
id: deep_sleep_23
Do you know what is happening? and how I can fix this?