3-phase PV router
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
20
21#ifndef CONFIG_H
22#define CONFIG_H
23
24//--------------------------------------------------------------------------------------------------
25//#define RF_PRESENT /**< this line must be commented out if the RFM12B module is not present */
26#define ENABLE_DEBUG
27//--------------------------------------------------------------------------------------------------
28
29#include "config_system.h"
30#include "debug.h"
31#include "types.h"
32
33#include "utils_dualtariff.h"
34#include "utils_relay.h"
35
36// Serial output type - Human readable for initial setup and commissioning
38
39//--------------------------------------------------------------------------------------------------
40// Basic Configuration
41//
42inline constexpr uint8_t NO_OF_DUMPLOADS{ 2 };
43
44// Feature toggles - Basic setup without advanced features
45inline constexpr bool EMONESP_CONTROL{ false };
46inline constexpr bool DIVERSION_PIN_PRESENT{ false };
47inline constexpr RotationModes PRIORITY_ROTATION{ RotationModes::OFF };
48inline constexpr bool OVERRIDE_PIN_PRESENT{ false };
49
50inline constexpr bool WATCHDOG_PIN_PRESENT{ false };
51inline constexpr bool RELAY_DIVERSION{ false };
52
53//--------------------------------------------------------------------------------------------------
54// EWMA Filter Tuning for Cloud Immunity
55//
56// The RELAY_FILTER_DELAY parameter controls how aggressively the EWMA filter smooths
57// power measurements before making relay decisions. This directly affects cloud immunity vs responsiveness.
58//
59// ๐ŸŒค๏ธ Quick Reference by Climate:
60// - Clear sky regions (desert, dry): 1 minute (fast response, minimal clouds)
61// - Mixed conditions (most locations): 2 minutes (recommended default)
62// - Frequently cloudy (coastal): 3 minutes (enhanced stability)
63// - Very cloudy (mountain, tropical): 4 minutes (maximum stability)
64//
65// ๐Ÿงช Scientific Tuning:
66// Run cloud pattern analysis tests to determine optimal setting for your climate:
67// cd Mk2_3phase_RFdatalog_temp && pio test -e native --filter="test_cloud_patterns" -v
68//
69// ๐Ÿ“– Full guide: docs/Cloud_Pattern_Tuning_Guide.md
70//--------------------------------------------------------------------------------------------------
71inline constexpr uint8_t RELAY_FILTER_DELAY{ 2 };
72
73inline constexpr bool DUAL_TARIFF{ false };
74inline constexpr bool TEMP_SENSOR_PRESENT{ false };
75
76#include "utils_temp.h"
77
78// ----------- Pinout Assignments -----------
79//
80// ANALOG pins:
81// - All analog pins are reserved and hard-wired on the PCB.
82//
83// DIGITAL pins:
84// - D0 & D1: Reserved for the Serial interface.
85//
86// RFM12B Module (if present):
87// - D2: Used for the RFM12B module.
88// - D10: Used for the RFM12B module.
89// - D11: Used for the RFM12B module.
90// - D12: Used for the RFM12B module.
91// - D13: Used for the RFM12B module.
92//
93// SPI Interface:
94// - D10: Chip Select (CS).
95// - D11: Master Out Slave In (MOSI).
96// - D12: Master In Slave Out (MISO).
97// - D13: Serial Clock (SCK).
98//
99// Expansion Board:
100// Digital Input Pins (D10-D13) are wired to the expansion board and it's intended
101// to configure them as digital inputs
102// They allow external control from Home Assistant for functions such as:
103// * Forced operation mode
104// * Diversion enable/disable
105// * Priority rotation triggering
106// * Manual load control
107//
108// D3 is wired to the expansion board too and is intended for taking control of the temperature sensor.
109//
110// Note: When using these pins for Home Assistant integration, ensure the ESP32
111// counterpart is properly configured to send the appropriate signals.
112
113inline constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]{ 5, 7 };
114inline constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]{ 0, 1 };
115
116// Set the value to 'unused_pin' when the pin is not needed (feature deactivated)
117inline constexpr uint8_t dualTariffPin{ unused_pin };
118inline constexpr uint8_t diversionPin{ unused_pin };
119inline constexpr uint8_t rotationPin{ unused_pin };
120inline constexpr uint8_t forcePin{ unused_pin };
121inline constexpr uint8_t watchDogPin{ unused_pin };
122
123// Relay configuration with tunable EWMA filter
124// For battery systems, use negative import threshold (turn OFF when surplus < abs(threshold))
125// Examples:
126// Normal installation: { pin, 1000, 200, 5, 5 } // Turn OFF when importing > 200W
127// Battery installation: { pin, 1000, -50, 5, 5 } // Turn OFF when surplus < 50W
128inline constexpr RelayEngine relays{ MINUTES(RELAY_FILTER_DELAY), { { unused_pin, 1000, 200, 1, 1 } } };
129
130inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 };
131inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { -3, 2 } };
132
133inline constexpr int16_t iTemperatureThreshold{ 100 };
134
136 { { 0x28, 0xBE, 0x41, 0x6B, 0x09, 0x00, 0x00, 0xA4 },
137 { 0x28, 0xED, 0x5B, 0x6A, 0x09, 0x00, 0x00, 0x9D },
138 { 0x28, 0xDB, 0x6D, 0x6A, 0x09, 0x00, 0x00, 0xDA },
139 { 0x28, 0x59, 0x1F, 0x6A, 0x09, 0x00, 0x00, 0xB0 },
140 { 0x28, 0x1B, 0xD7, 0x6A, 0x09, 0x00, 0x00, 0xB7 } } };
141
142inline constexpr uint32_t ROTATION_AFTER_SECONDS{ 8UL * 3600UL };
143
144/* --------------------------------------
145 RF configuration (for the RFM12B module)
146 frequency options are RF12_433MHZ, RF12_868MHZ or RF12_915MHZ
147*/
148#ifdef RF_PRESENT
149
150#define RF69_COMPAT 0 // for the RFM12B
151// #define RF69_COMPAT 1 // for the RF69
152
153#define FREQ RF12_868MHZ
154
155inline constexpr int nodeID{ 10 };
156inline constexpr int networkGroup{ 210 };
157inline constexpr int UNO{ 1 };
158
159#endif // RF_PRESENT
160
161#endif // CONFIG_H
Manages a collection of relays and their behavior based on surplus and import thresholds.
Implements temperature sensing functionality for multiple sensors.
Definition utils_temp.h:112
Config parameters for overriding a load.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:114
constexpr bool RELAY_DIVERSION
Definition config.h:51
constexpr int networkGroup
Definition config.h:156
constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]
Definition config.h:131
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:48
constexpr uint32_t ROTATION_AFTER_SECONDS
Definition config.h:142
constexpr uint8_t dualTariffPin
Definition config.h:117
constexpr TemperatureSensing temperatureSensing
Definition config.h:135
constexpr uint8_t forcePin
Definition config.h:120
constexpr RelayEngine relays
Definition config.h:128
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:113
constexpr uint8_t RELAY_FILTER_DELAY
Definition config.h:71
constexpr int nodeID
Definition config.h:155
constexpr bool DUAL_TARIFF
Definition config.h:73
constexpr uint8_t diversionPin
Definition config.h:118
constexpr int UNO
Definition config.h:157
constexpr SerialOutputType SERIAL_OUTPUT_TYPE
Definition config.h:37
constexpr bool EMONESP_CONTROL
Definition config.h:45
constexpr uint8_t NO_OF_DUMPLOADS
Definition config.h:42
constexpr uint8_t ul_OFF_PEAK_DURATION
Definition config.h:130
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:74
constexpr int16_t iTemperatureThreshold
Definition config.h:133
constexpr bool WATCHDOG_PIN_PRESENT
Definition config.h:50
constexpr bool DIVERSION_PIN_PRESENT
Definition config.h:46
constexpr uint8_t rotationPin
Definition config.h:119
constexpr uint8_t watchDogPin
Definition config.h:121
Basic configuration values to be set by the end-user.
Some macro for the Serial Output and Debugging.
Some basics classes/types.
RotationModes
Definition types.h:60
#define MINUTES(value)
Macro to convert compile-time constant to integral_constant.
Definition types.h:127
SerialOutputType
Definition types.h:27
Some utility functions for dual tariff feature.
constexpr uint8_t unused_pin
Definition utils_pins.h:17
Some utility functions for the relay output feature.
Provides utilities for managing temperature sensors.