Merged master into ollo-dev

This commit is contained in:
Ollo 2023-03-10 20:06:05 +01:00
commit 712ef73a30
43 changed files with 13018 additions and 103 deletions

View File

@ -0,0 +1,3 @@
EESchema-DOCLIB Version 2.0
#
#End Doc Library

View File

@ -0,0 +1,77 @@
{
"board": {
"active_layer": 0,
"active_layer_preset": "",
"auto_track_width": true,
"hidden_nets": [],
"high_contrast_mode": 0,
"net_color_mode": 1,
"opacity": {
"pads": 1.0,
"tracks": 1.0,
"vias": 1.0,
"zones": 0.6
},
"ratsnest_display_mode": 0,
"selection_filter": {
"dimensions": true,
"footprints": true,
"graphics": true,
"keepouts": true,
"lockedItems": true,
"otherItems": true,
"pads": true,
"text": true,
"tracks": true,
"vias": true,
"zones": true
},
"visible_items": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
32,
33,
34,
35,
36
],
"visible_layers": "fffffff_ffffffff",
"zone_display_mode": 0
},
"meta": {
"filename": "PlantCtrlESP32.kicad_prl",
"version": 3
},
"project": {
"files": []
}
}

View File

@ -0,0 +1,493 @@
{
"board": {
"design_settings": {
"defaults": {
"board_outline_line_width": 0.049999999999999996,
"copper_line_width": 0.19999999999999998,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.049999999999999996,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.09999999999999999,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.09999999999999999,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.762,
"height": 1.524,
"width": 1.524
},
"silk_line_width": 0.12,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"45_degree_only": false,
"min_clearance": 0.508
}
},
"diff_pair_dimensions": [],
"drc_exclusions": [],
"meta": {
"filename": "board_design_settings.json",
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"copper_edge_clearance": "error",
"courtyards_overlap": "error",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint_type_mismatch": "error",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "error",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zone_has_empty_net": "error",
"zones_intersect": "error"
},
"rule_severitieslegacy_courtyards_overlap": true,
"rule_severitieslegacy_no_courtyard_defined": false,
"rules": {
"allow_blind_buried_vias": false,
"allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.0,
"min_copper_edge_clearance": 0.024999999999999998,
"min_hole_clearance": 0.25,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_silk_clearance": 0.0,
"min_through_hole_diameter": 0.3,
"min_track_width": 0.19999999999999998,
"min_via_annular_width": 0.049999999999999996,
"min_via_diameter": 0.39999999999999997,
"use_height_for_length_calcs": true
},
"track_widths": [
0.0,
0.2,
0.5,
1.0
],
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
},
{
"diameter": 1.2,
"drill": 0.8
},
{
"diameter": 4.0,
"drill": 3.0
}
],
"zones_allow_external_fillets": false,
"zones_use_no_outline": true
},
"layer_presets": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_label_syntax": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "warning",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "PlantCtrlESP32.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 1.2,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
},
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "5V",
"nets": [],
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 1.4,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
},
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Mini",
"nets": [],
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 1.0,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
},
{
"bus_width": 12.0,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Power",
"nets": [],
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 1.7,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
}
],
"meta": {
"version": 2
},
"net_colors": null
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "PlantCtrlESP32.net",
"specctra_dsn": "",
"step": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"drawing": {
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.25,
"pin_symbol_size": 0.0,
"text_offset_ratio": 0.08
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "Pcbnew",
"ngspice": {
"fix_include_paths": true,
"fix_passive_vals": false,
"meta": {
"version": 0
},
"model_mode": 0,
"workbook_filename": ""
},
"page_layout_descr_file": "",
"plot_directory": "/tmp/",
"spice_adjust_passive_values": false,
"spice_external_command": "spice \"%I\"",
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"c26e8d55-0b6e-4c4e-b7c8-b1fed973201c",
""
]
],
"text_variables": {}
}

10699
board/PlantCtrlESP32.kicad_sch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
(sym_lib_table
(lib (name LP38690DT-3.3)(type Legacy)(uri ${KIPRJMOD}/kicad-stuff/LP38690DT-3.3.lib)(options "")(descr ""))
(lib (name ESP32-DEVKITC-32D)(type Legacy)(uri ${KIPRJMOD}/kicad-stuff/ESP32/ESP32-DEVKITC-32D.lib)(options "")(descr ""))
(lib (name DW01)(type Legacy)(uri ${KIPRJMOD}/kicad-stuff/DW01.lib)(options "")(descr ""))
(lib (name SX1308)(type Legacy)(uri ${KIPRJMOD}/kicad-stuff/SX1308.lib)(options "")(descr ""))
(lib (name ds2438)(type Legacy)(uri ${KIPRJMOD}/kicad-stuff/ds2438.lib)(options "")(descr ""))
(lib (name "LP38690DT-3.3")(type "Legacy")(uri "${KIPRJMOD}/kicad-stuff/LP38690DT-3.3.lib")(options "")(descr ""))
(lib (name "ESP32-DEVKITC-32D")(type "Legacy")(uri "${KIPRJMOD}/kicad-stuff/ESP32/ESP32-DEVKITC-32D.lib")(options "")(descr ""))
(lib (name "DW01")(type "Legacy")(uri "${KIPRJMOD}/kicad-stuff/DW01.lib")(options "")(descr ""))
(lib (name "SX1308")(type "Legacy")(uri "${KIPRJMOD}/kicad-stuff/SX1308.lib")(options "")(descr ""))
(lib (name "ds2438")(type "Legacy")(uri "${KIPRJMOD}/kicad-stuff/ds2438.lib")(options "")(descr ""))
(lib (name "PlantCtrlESP32-rescue")(type "Legacy")(uri "${KIPRJMOD}/PlantCtrlESP32-rescue.lib")(options "")(descr ""))
)

3
esp32/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32)

View File

@ -1,7 +1,8 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x300000,
app1, app, ota_1, 0x310000,0x300000,
spiffs, data, spiffs, 0x610000,0x17000,
#https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xD000, 0x2000
phy_init, data, phy, 0xF000, 0x1000
factory, app, factory, 0x10000, 0x140000
ota_0, app, ota_0, 0x150000, 0x140000
ota_1, app, ota_1, 0x290000, 0x140000
spiffs, data, spiffs, 0x3D0000, 0x30000
1 # Name, Type, SubType, Offset, Size, Flags # Name, Type, SubType, Offset, Size, Flags
2 nvs, data, nvs, 0x9000, 0x5000, nvs, data, nvs, 0x9000, 0x4000
3 otadata, data, ota, 0xe000, 0x2000, otadata, data, ota, 0xD000, 0x2000
4 app0, app, ota_0, 0x10000, 0x300000, phy_init, data, phy, 0xF000, 0x1000
5 app1, app, ota_1, 0x310000,0x300000, factory, app, factory, 0x10000, 0x140000
6 spiffs, data, spiffs, 0x610000,0x17000, ota_0, app, ota_0, 0x150000, 0x140000
7 #https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html ota_1, app, ota_1, 0x290000, 0x140000
8 spiffs, data, spiffs, 0x3D0000, 0x30000

View File

@ -98,7 +98,7 @@
#define MOIST_SENSOR_MIN_FRQ 500 // 0.5kHz (500Hz margin)
#define ANALOG_SENSOR_MAX_MV 1300 //successive approximation of good range
#define ANALOG_SENSOR_MIN_MV 300 //successive approximation of good range
#define ANALOG_SENSOR_MIN_MV 100 //successive approximation of good range
#define SOLAR_VOLT_FACTOR 11
#define BATTSENSOR_INDEX_SOLAR 0

View File

@ -21,7 +21,7 @@
#define FOREACH_SENSOR(SENSOR) \
SENSOR(NONE) \
SENSOR(CAPACITIVE_FREQUENCY) \
SENSOR(FREQUENCY_MOD_RESISTANCE_PROBE) \
SENSOR(ANALOG_RESISTANCE_PROBE)
/**

View File

@ -1,4 +1,5 @@
#pragma once
#ifndef LOG_DEFINES_H
#define LOG_DEFINES_H
#define LOG_LEVEL_ERROR 0
#define LOG_LEVEL_WARN 1
@ -29,6 +30,9 @@
#define LOG_PUMP_AND_DOWNLOADMODE "Download mode, ignoring pump request"
#define LOG_PUMP_AND_DOWNLOADMODE_CODE 2
#define LOG_VERY_COLD_WATER "Water potentially frozen, ignoring pump request"
#define LOG_VERY_COLD_WATER_CODE -7
//msg is dynamic defined
#define LOG_PUMP_INEFFECTIVE -4
#define LOG_PUMP_STARTED_CODE 10
@ -38,4 +42,5 @@
#define LOG_SLEEP_CYCLE 102
#define LOG_MISSING_PUMP -4
#define LOG_BOOT_ERROR_DETECTION 10000
#define LOG_SOLAR_CHARGER_MISSING 300
#define LOG_SOLAR_CHARGER_MISSING 300
#endif

View File

@ -19,7 +19,6 @@
#include "MathUtils.h"
#include "MQTTUtils.h"
#include "LogDefines.h"
#include "SHT2x.h"
#define ANALOG_REREADS 5
#define MOISTURE_MEASUREMENT_DURATION 400 /** ms */
@ -39,7 +38,6 @@ private:
bool mConnected = false;
int mPlantId = -1;
SENSOR_MODE mSensorMode;
SHT2x sht20;
public:
@ -134,8 +132,8 @@ public:
{
case NONE:
return DEACTIVATED_PLANT;
case CAPACITIVE_FREQUENCY:
return mapf(mMoisture_raw.getMedian(), MOIST_SENSOR_MAX_FRQ, MOIST_SENSOR_MIN_FRQ, 0, 100);
case FREQUENCY_MOD_RESISTANCE_PROBE:
return mapf(mMoisture_raw.getMedian(), MOIST_SENSOR_MIN_FRQ, MOIST_SENSOR_MAX_FRQ, 0, 100);
case ANALOG_RESISTANCE_PROBE:
return mapf(mMoisture_raw.getMedian(), ANALOG_SENSOR_MAX_MV, ANALOG_SENSOR_MIN_MV, 0, 100);
}
@ -144,7 +142,7 @@ public:
float getCurrentMoistureRaw()
{
if (getSensorMode() == CAPACITIVE_FREQUENCY)
if (getSensorMode() == FREQUENCY_MOD_RESISTANCE_PROBE)
{
if (mMoisture_raw.getMedian() < MOIST_SENSOR_MIN_FRQ)
{

View File

@ -101,17 +101,6 @@ static inline uint16_t ulp_internal_data_read(size_t offset)
return RTC_SLOW_MEM[offset] & 0xffff;
}
static inline uint32_t rtc_io_number_get(gpio_num_t gpio_num)
{
assert(rtc_gpio_is_valid_gpio(gpio_num) && "Invalid GPIO for RTC");
uint32_t bit = rtc_bit[gpio_num];
Serial.print("Resolved GPIO ");
Serial.print(gpio_num);
Serial.print(" to rtc bit ");
Serial.println(bit);
return bit;
}
void ulp_internal_start(void)
{
rtc_gpio_init(PIN);

View File

@ -9,27 +9,28 @@
; https://docs.platformio.org/page/projectconf.html
[env:esp32doit-devkit-v1]
platform = espressif32
platform = espressif32@4.2.0
board = esp32doit-devkit-v1
framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-DPLANT0_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT1_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT2_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT3_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT4_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT5_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT6_SENSORTYPE=ANALOG_RESISTANCE_PROBE
-DPLANT0_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT1_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT2_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT3_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT4_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT5_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
-DPLANT6_SENSORTYPE=FREQUENCY_MOD_RESISTANCE_PROBE
board_build.partitions = defaultWithSmallerSpiffs.csv
;#https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = ArduinoJson@6.16.1
OneWire
DallasTemperature
pololu/VL53L0X
lib_deps = bblanchon/ArduinoJson@^6.20.1
paulstoffregen/OneWire@^2.3.6
milesburton/DallasTemperature@^3.11.0
pololu/VL53L0X@^1.3.1
https://github.com/homieiot/homie-esp8266.git#develop
robtillaart/SHT2x@^0.1.3
[platformio]

File diff suppressed because it is too large Load Diff

6
esp32/src/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})

View File

@ -23,7 +23,6 @@ Plant::Plant(int pinSensor, int pinPump, int plantId, HomieNode *plant, PlantSet
this->mSetting = setting;
this->mPlantId = plantId;
this->mSensorMode = mode;
this->sht20 = SHT2x();
}
void Plant::init(void)
@ -65,7 +64,7 @@ void Plant::initSensors(void)
{
switch (getSensorMode())
{
case CAPACITIVE_FREQUENCY:
case FREQUENCY_MOD_RESISTANCE_PROBE:
{
pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_0 + this->mPlantId);
@ -112,7 +111,7 @@ void Plant::blockingMoistureMeasurement(void)
}
break;
}
case CAPACITIVE_FREQUENCY:
case FREQUENCY_MOD_RESISTANCE_PROBE:
case NONE:
{
// nothing to do here
@ -125,7 +124,7 @@ void Plant::startMoistureMeasurement(void)
{
switch (getSensorMode())
{
case CAPACITIVE_FREQUENCY:
case FREQUENCY_MOD_RESISTANCE_PROBE:
{
pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_0 + this->mPlantId);
pcnt_counter_resume(unit);
@ -143,7 +142,7 @@ void Plant::stopMoistureMeasurement(void)
{
switch (getSensorMode())
{
case CAPACITIVE_FREQUENCY:
case FREQUENCY_MOD_RESISTANCE_PROBE:
{
int16_t pulses;
pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_0 + this->mPlantId);
@ -269,9 +268,9 @@ void Plant::advertise(void)
{
// Advertise topics
mPump = this->mPlant->advertise("switch").setName("Pump").setDatatype("Boolean");
this->mPlant->advertise("lastPump").setName("lastPump").setDatatype("Integer").setUnit("unixtime");
this->mPlant->advertise("moist").setName("Percent").setDatatype("Float").setUnit("%");
this->mPlant->advertise("moistraw").setName("adc").setDatatype("Float").setUnit("3.3/4096V");
this->mPlant->advertise("state").setName("state").setDatatype("String");
this->mPlant->advertise("lastPump").setName("lastPump").setDatatype("Integer").setUnit("unixtime").setRetained(true);
this->mPlant->advertise("moist").setName("Percent").setDatatype("Float").setUnit("%").setRetained(true);
this->mPlant->advertise("moistraw").setName("frequency").setDatatype("Float").setUnit("hz").setRetained(true);
this->mPlant->advertise("state").setName("state").setDatatype("String").setRetained(true);
}

View File

@ -90,6 +90,8 @@ long lastSendPumpUpdate = 0;
long pumpTargetMl = -1;
#endif
float waterTemp = 30;
/*************************** Hardware abstraction *****************************/
OneWire oneWire(SENSOR_ONEWIRE);
@ -218,7 +220,6 @@ void readOneWireSensors()
for (uint8_t i = 0; i < sensors.getDeviceCount(); i++)
{
uint8_t ds18b20Address[8];
bool valid = false;
float temp = -127;
for (int retry = 0; retry < AMOUNT_SENOR_QUERYS && !valid; retry++)
@ -242,9 +243,8 @@ void readOneWireSensors()
{
// wrong family or crc errors on each retry
continue;
}
char buf[(sizeof(ds18b20Address) * 2) + 1]; /* additional byte for trailing terminator */
}
char buf[(sizeof(ds18b20Address) * 2) + 1]; /* additional byte for trailing terminator */
snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",
ds18b20Address[0],
ds18b20Address[1],
@ -254,8 +254,7 @@ void readOneWireSensors()
ds18b20Address[5],
ds18b20Address[6],
ds18b20Address[7]);
if (valid)
if (valid)
{
Serial << "DS18S20 Temperatur " << String(buf) << " : " << temp << " °C " << endl;
if (strcmp(lipoSensorAddr.get(), buf) == 0)
@ -267,6 +266,7 @@ void readOneWireSensors()
{
mqttWrite(&sensorTemp, TEMPERATUR_SENSOR_WATER, String(temp));
Serial << "Water Temperatur " << temp << " °C " << endl;
waterTemp = temp;
}
/* Always send the sensor address with the temperatur value */
mqttWrite(&sensorTemp, String(buf), String(temp));
@ -315,19 +315,17 @@ void readPowerSwitchedSensors()
Plant plant = mPlants[i];
switch (plant.getSensorMode())
{
case CAPACITIVE_FREQUENCY:
{
Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " hz " << mPlants[i].getCurrentMoisturePCT() << "%" << endl;
break;
}
case ANALOG_RESISTANCE_PROBE:
{
Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " mV " << mPlants[i].getCurrentMoisturePCT() << "%" << endl;
break;
}
case NONE:
{
}
case FREQUENCY_MOD_RESISTANCE_PROBE: {
Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " hz " << mPlants[i].getCurrentMoisturePCT() << "%" << endl;
break;
}
case ANALOG_RESISTANCE_PROBE : {
Serial << "Plant " << i << " measurement: " << mPlants[i].getCurrentMoistureRaw() << " mV " << mPlants[i].getCurrentMoisturePCT() << "%" << endl;
break;
}
case NONE : {
}
}
}
@ -354,8 +352,7 @@ void readPowerSwitchedSensors()
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
tankSensor.setMeasurementTimingBudget(200000);
for (int readCnt = 0; readCnt < 5; readCnt++)
for (int readCnt = 0; readCnt < 5; readCnt++)
{
if (!tankSensor.timeoutOccurred())
{
@ -633,11 +630,12 @@ void initPumpLogic()
#endif
pumpStartTime = millis();
pumpTarget = millis() + (mPlants[pumpToRun].getPumpDuration() * 1000);
#ifdef FLOWMETER_PIN
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s or " + String(pumpTargetMl) + "ml", LOG_PUMP_STARTED_CODE);
#else
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE);
#endif
#ifdef FLOWMETER_PIN
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s or " + String(pumpTargetMl) + "ml", LOG_PUMP_STARTED_CODE);
#else
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE);
#endif
// enable power
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
@ -722,9 +720,6 @@ void pumpActiveLoop()
void safeSetup()
{
/* reduce power consumption */
setCpuFrequencyMhz(80);
Serial.begin(115200);
Serial << "Wifi mode set to " << WIFI_OFF << " to allow analog2 useage " << endl;
@ -807,13 +802,11 @@ void safeSetup()
{
mPlants[i].initSensors();
}
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL);
readPowerSwitchedSensors();
Homie.setup();
Wire = TwoWire(0);
Wire.setPins(SENSOR_TANK_SDA, SENSOR_TANK_SCL);
Wire.begin();
/************************* Start One-Wire bus ***************/
int tempInitStartTime = millis();
@ -833,7 +826,7 @@ void safeSetup()
/* Measure temperature TODO idea: move this into setup */
if (sensorCount > 0)
{
// sensors.setResolution(DS18B20_RESOLUTION);
sensors.setResolution(DS18B20_RESOLUTION);
sensors.requestTemperatures();
}
@ -921,6 +914,11 @@ void safeSetup()
*/
void setup()
{
Serial.begin(115200);
Serial << "First init" << endl;
Serial.flush();
try
{
safeSetup();
@ -1076,38 +1074,43 @@ void plantcontrol()
Serial.flush();
}
bool isLowLight = mSolarVoltage <= 9;
#if defined(TIMED_LIGHT_PIN)
bool isLowLight = mSolarVoltage <= 9;
bool shouldLight = determineTimedLightState(isLowLight);
if (shouldLight)
{
if(shouldLight){
ulp_pwm_set_level(timedLightPowerLevel.get());
}
else
{
}else {
ulp_pwm_set_level(0);
}
#endif // TIMED_LIGHT_PIN
bool isLiquid = waterTemp > 5;
bool hasWater = true; // FIXME remaining > waterLevelMin.get();
// FIXME no water warning message
pumpToRun = determineNextPump(isLowLight);
// early aborts
if (pumpToRun != -1)
{
if (hasWater)
{
if (mDownloadMode)
if(isLiquid){
if (hasWater)
{
log(LOG_LEVEL_INFO, LOG_PUMP_AND_DOWNLOADMODE, LOG_PUMP_AND_DOWNLOADMODE_CODE);
if (mDownloadMode)
{
log(LOG_LEVEL_INFO, LOG_PUMP_AND_DOWNLOADMODE, LOG_PUMP_AND_DOWNLOADMODE_CODE);
pumpToRun = -1;
}
}
else
{
log(LOG_LEVEL_ERROR, LOG_PUMP_BUTNOTANK_MESSAGE, LOG_PUMP_BUTNOTANK_CODE);
pumpToRun = -1;
}
}
else
{
log(LOG_LEVEL_ERROR, LOG_PUMP_BUTNOTANK_MESSAGE, LOG_PUMP_BUTNOTANK_CODE);
pumpToRun = -1;
else{
log(LOG_LEVEL_ERROR, LOG_VERY_COLD_WATER, LOG_VERY_COLD_WATER_CODE);
pumpToRun = -1;
}
}

View File

@ -12,7 +12,6 @@
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps = OneWire
DallasTemperature
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DBOOTLOADER_LOG_LEVEL_VERBOSE -DLOG_DEFAULT_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=5