24static_assert(__cplusplus >= 201703L,
"**** Please define 'gnu++17' in 'platform.txt' ! ****");
25static_assert(__cplusplus >= 201703L,
"See also : https://github.com/FredM67/PVRouter-3-phase/blob/main/Mk2_3phase_RFdatalog_temp/Readme.md");
73 static bool pinOffPeakState{
HIGH };
77 if (pinOffPeakState || pinNewState)
83 const auto ulElapsedTime{
static_cast< uint32_t
>(millis() -
ul_TimeOffPeak) };
85 uint16_t forcingBitmask = 0;
97 if (currentTemperature_x100 <= iTemperatureThreshold_x100)
103 return forcingBitmask;
127 uint16_t overrideBitmask = 0;
152 return overrideBitmask;
176 static auto previousState{
HIGH };
177 if (previousState != pinState)
179 DBUGLN(!pinState ? F(
"Trigger diversion OFF!") : F(
"End diversion OFF!"));
182 previousState = pinState;
235 static bool pinOffPeakState{
HIGH };
238 if (pinOffPeakState && !pinNewState)
241 DBUGLN(F(
"Change to off-peak period!"));
252 if (!pinOffPeakState && pinNewState)
254 DBUGLN(F(
"Change to peak period!"));
257 pinOffPeakState = pinNewState;
259 return (
LOW == pinOffPeakState);
284 (void)currentTemperature_x100;
293 static uint8_t pinRotationState{
HIGH };
296 if (pinRotationState && !pinNewState)
298 DBUGLN(F(
"Trigger rotation!"));
302 pinRotationState = pinNewState;
338 DEBUG_PORT.begin(9600);
354 DBUG(F(
">>free RAM = "));
419 if (8500 == tmp && (abs(tmp -
tx_data.temperature_x100[idx]) > 500))
424 tx_data.temperature_x100[idx] = tmp;
464 relays.proceed_relays(privateOverrideBitmask);
494 static uint8_t perSecondTimer{ 0 };
495 static bool bOffPeak{
false };
496 static int16_t iTemperature_x100{ 0 };
Calibration values definition.
constexpr float f_voltageCal[NO_OF_PHASES]
constexpr float f_powerCal[NO_OF_PHASES]
Standard three-phase PVRouter setup with 2 dump loads.
constexpr bool RELAY_DIVERSION
constexpr bool OVERRIDE_PIN_PRESENT
constexpr uint32_t ROTATION_AFTER_SECONDS
constexpr uint8_t dualTariffPin
constexpr TemperatureSensing temperatureSensing
constexpr RelayEngine relays
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
constexpr bool DUAL_TARIFF
constexpr uint8_t diversionPin
constexpr OverridePins overridePins
constexpr SerialOutputType SERIAL_OUTPUT_TYPE
constexpr bool EMONESP_CONTROL
constexpr uint8_t NO_OF_DUMPLOADS
constexpr bool TEMP_SENSOR_PRESENT
constexpr int16_t iTemperatureThreshold
constexpr bool WATCHDOG_PIN_PRESENT
constexpr bool DIVERSION_PIN_PRESENT
constexpr uint8_t rotationPin
constexpr uint8_t watchDogPin
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint8_t NO_OF_PHASES
constexpr uint8_t SUPPLY_FREQUENCY
constexpr int16_t DEVICE_DISCONNECTED_RAW
constexpr auto rg_OffsetForce
uint16_t getDualTariffForcingBitmask(const int16_t currentTemperature_x100)
Calculates the dual tariff forcing bitmask based on current conditions.
void updatePowerAndVoltageData()
Updates power and voltage data for all phases.
void handlePerSecondTasks(bool &bOffPeak, int16_t &iTemperature_x100)
Handles tasks that need to be executed every second.
void checkDiversionOnOff()
Checks and updates the diversion state based on the diversion pin.
bool proceedDualTariffLogic()
Handles dual tariff state transitions and priority rotation during off-peak periods.
bool proceedLoadPriorities(const int16_t ¤tTemperature_x100)
Handles load priority rotation and dual tariff state transitions.
uint16_t getOverrideBitmask(const int16_t currentTemperature_x100)
Gets the combined bitmask of all active override pins and dual tariff forcing.
void proceedRotation()
Proceeds with load priority rotation.
void sendResults(bool bOffPeak)
Prints or sends telemetry data logs based on the selected output format.
void logLoadPriorities()
Prints the load priorities to the Serial output.
void loop()
Main processor loop.
void setup()
Called once during startup.
void printConfiguration()
Print the configuration during startup.
void initializeProcessing()
Initializes the processing engine, including ports, load states, and ADC setup.
void processTemperatureData()
Processes temperature data from DS18B20 sensors.
Header file for the main application.
volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES]
volatile uint16_t overrideBitmask
volatile bool b_datalogEventPending
volatile bool b_reOrderLoads
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
volatile uint16_t absenceOfDivertedEnergyCountInSeconds
volatile bool b_newMainsCycle
volatile bool b_diversionEnabled
Public functions/variables of processing engine.
constexpr uint16_t initialDelay
PayloadTx_struct< NO_OF_PHASES > tx_data
Some basics classes/types.
int freeRam()
Get the available RAM during setup.
constexpr void bit_set(T &_dest, const uint8_t bit)
Set the specified bit to 1.
constexpr bool getPinState(uint8_t pin)
Get the Pin State.
constexpr void togglePin(uint8_t pin)
Toggle the specified pin.
Some utility functions for the relay output feature.
Compile-time validations.