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{ 3 };
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{ true };
49
50inline constexpr bool WATCHDOG_PIN_PRESENT{ false };
51inline constexpr bool RELAY_DIVERSION{ false };
52inline constexpr bool DUAL_TARIFF{ false };
53inline constexpr bool TEMP_SENSOR_PRESENT{ false };
54
55#include "utils_temp.h"
56
57// ----------- Pinout Assignments -----------
58//
59// ANALOG pins:
60// - All analog pins are reserved and hard-wired on the PCB.
61//
62// DIGITAL pins:
63// - D0 & D1: Reserved for the Serial interface.
64//
65// RFM12B Module (if present):
66// - D2: Used for the RFM12B module.
67// - D10: Used for the RFM12B module.
68// - D11: Used for the RFM12B module.
69// - D12: Used for the RFM12B module.
70// - D13: Used for the RFM12B module.
71//
72// SPI Interface:
73// - D10: Chip Select (CS).
74// - D11: Master Out Slave In (MOSI).
75// - D12: Master In Slave Out (MISO).
76// - D13: Serial Clock (SCK).
77//
78// Expansion Board:
79// Digital Input Pins (D10-D13) are wired to the expansion board and it's intended
80// to configure them as digital inputs
81// They allow external control from Home Assistant for functions such as:
82// * Forced operation mode
83// * Diversion enable/disable
84// * Priority rotation triggering
85// * Manual load control
86//
87// D3 is wired to the expansion board too and is intended for taking control of the temperature sensor.
88//
89// Note: When using these pins for Home Assistant integration, ensure the ESP32
90// counterpart is properly configured to send the appropriate signals.
91
92inline constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]{ 5, 6, 7 };
93inline constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]{ 0, 1, 2 };
94
95// Set the value to 'unused_pin' when the pin is not needed (feature deactivated)
96inline constexpr uint8_t dualTariffPin{ unused_pin };
97inline constexpr uint8_t diversionPin{ unused_pin };
98inline constexpr uint8_t rotationPin{ unused_pin };
99inline constexpr uint8_t watchDogPin{ unused_pin };
100
101//--------------------------------------------------------------------------------------------------
102// EWMA Filter Tuning for Cloud Immunity
103//
104// The RELAY_FILTER_DELAY parameter controls how aggressively the EWMA filter smooths
105// power measurements before making relay decisions. This directly affects cloud immunity vs responsiveness.
106//
107// ๐ŸŒค๏ธ Quick Reference by Climate:
108// - Clear sky regions (desert, dry): 1 minute (fast response, minimal clouds)
109// - Mixed conditions (most locations): 2 minutes (recommended default)
110// - Frequently cloudy (coastal): 3 minutes (enhanced stability)
111// - Very cloudy (mountain, tropical): 4 minutes (maximum stability)
112//
113// ๐Ÿงช Scientific Tuning:
114// Run cloud pattern analysis tests to determine optimal setting for your climate:
115// cd Mk2_3phase_RFdatalog_temp && pio test -e native --filter="test_cloud_patterns" -v
116//
117// ๐Ÿ“– Full guide: docs/Cloud_Pattern_Tuning_Guide.md
118//--------------------------------------------------------------------------------------------------
119inline constexpr uint8_t RELAY_FILTER_DELAY{ 2 };
120
121// Relay configuration with tunable EWMA filter
122// For battery systems, use negative import threshold (turn OFF when surplus < abs(threshold))
123// Examples:
124// Normal installation: { pin, 1000, 200, 5, 5 } // Turn OFF when importing > 200W
125// Battery installation: { pin, 1000, -50, 5, 5 } // Turn OFF when surplus < 50W
127 { { unused_pin, 100, 200, 1, 1 },
128 { unused_pin, 300, 400, 1, 1 },
129 { unused_pin, 500, 600, 1, 1 } } };
130
131#include "utils_override.h"
132
133// This is an example of override pin configuration.
134// You can modify the pin numbers and associated loads/relays as needed.
135// Ensure that the pins used do not conflict with other functionalities in your setup.
136// This example does not make any sense, that's just to show how to use the class OverridePins
137// inline constexpr OverridePins overridePins{ { { 3, { RELAY(1), LOAD(1) } },
138// { 4, ALL_LOADS() },
139// { 11, { 1, LOAD(1), LOAD(2) } },
140// { 12, { RELAY(0), 9, RELAY(2) } },
141// { 13, ALL_LOADS_AND_RELAYS() } } }; /**< list of override pin/loads-relays pairs */
142
143inline constexpr OverridePins overridePins{ { { 4, ALL_LOADS() } } };
144
145inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 };
146inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { -3, 2 } };
147
148inline constexpr int16_t iTemperatureThreshold{ 100 };
149
151 { { 0x28, 0xBE, 0x41, 0x6B, 0x09, 0x00, 0x00, 0xA4 },
152 { 0x28, 0x1B, 0xD7, 0x6A, 0x09, 0x00, 0x00, 0xB7 } } };
153
154inline constexpr uint32_t ROTATION_AFTER_SECONDS{ 8UL * 3600UL };
155
156/* --------------------------------------
157 RF configuration (for the RFM12B module)
158 frequency options are RF12_433MHZ, RF12_868MHZ or RF12_915MHZ
159*/
160#ifdef RF_PRESENT
161
162#define RF69_COMPAT 0 // for the RFM12B
163// #define RF69_COMPAT 1 // for the RF69
164
165#define FREQ RF12_868MHZ
166
167inline constexpr int nodeID{ 10 };
168inline constexpr int networkGroup{ 210 };
169inline constexpr int UNO{ 1 };
170
171#endif // RF_PRESENT
172
173#endif // CONFIG_H
Manages override pins and their associated bitmasks for forced operation.
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:93
constexpr bool RELAY_DIVERSION
Definition config.h:51
constexpr int networkGroup
Definition config.h:168
constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]
Definition config.h:146
constexpr bool OVERRIDE_PIN_PRESENT
Definition config.h:48
constexpr uint32_t ROTATION_AFTER_SECONDS
Definition config.h:154
constexpr uint8_t dualTariffPin
Definition config.h:96
constexpr TemperatureSensing temperatureSensing
Definition config.h:150
constexpr RelayEngine relays
Definition config.h:126
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:92
constexpr uint8_t RELAY_FILTER_DELAY
Definition config.h:119
constexpr int nodeID
Definition config.h:167
constexpr bool DUAL_TARIFF
Definition config.h:52
constexpr uint8_t diversionPin
Definition config.h:97
constexpr OverridePins overridePins
Definition config.h:143
constexpr int UNO
Definition config.h:169
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:145
constexpr bool TEMP_SENSOR_PRESENT
Definition config.h:53
constexpr int16_t iTemperatureThreshold
Definition config.h:148
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:98
constexpr uint8_t watchDogPin
Definition config.h:99
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.
Compile-time utilities for managing override pins and index-to-bitmask mapping.
constexpr uint16_t ALL_LOADS()
Returns a bitmask representing all load pins.
constexpr uint8_t unused_pin
Definition utils_pins.h:17
Some utility functions for the relay output feature.
Provides utilities for managing temperature sensors.