12static_assert(__cplusplus >= 201703L,
"**** Please define 'gnu++17' in 'platform.txt' ! ****");
13static_assert(__cplusplus >= 201703L,
"See also : https://github.com/FredM67/PVRouter-3-phase/blob/main/Mk2_3phase_RFdatalog_temp/Readme.md");
79 static uint8_t sample_index{ 0 };
86 ADMUX = bit(REFS0) +
sensorV[1];
93 ADMUX = bit(REFS0) +
sensorI[1];
100 ADMUX = bit(REFS0) +
sensorV[2];
107 ADMUX = bit(REFS0) +
sensorI[2];
114 ADMUX = bit(REFS0) +
sensorV[0];
121 ADMUX = bit(REFS0) +
sensorI[0];
144 static uint8_t previousState{ HIGH };
145 if (previousState != pinState)
147 DBUGLN(!pinState ? F(
"Trigger override!") : F(
"End override!"));
150 previousState = pinState;
155 bOverrideLoad = !pinState;
177 static auto previousState{ HIGH };
178 if (previousState != pinState)
180 DBUGLN(!pinState ? F(
"Trigger diversion OFF!") : F(
"End diversion OFF!"));
183 previousState = pinState;
218 static bool pinOffPeakState{ HIGH };
221 if (pinOffPeakState && !pinNewState)
224 DBUGLN(F(
"Change to off-peak period!"));
235 const auto ulElapsedTime{
static_cast< uint32_t
>(millis() -
ul_TimeOffPeak) };
243 b_overrideLoadOn[
i] = !pinState || (currentTemperature_x100 <= iTemperatureThreshold_x100);
252 if (!pinOffPeakState && pinNewState)
254 DBUGLN(F(
"Change to peak period!"));
257 pinOffPeakState = pinNewState;
259 return (LOW == pinOffPeakState);
280 static uint8_t pinRotationState{ HIGH };
283 if (pinRotationState && !pinNewState)
285 DBUGLN(F(
"Trigger rotation!"));
289 pinRotationState = pinNewState;
307 bOverrideLoad = !pinState;
324 DEBUG_PORT.begin(9600);
342 DBUG(F(
">>free RAM = "));
355 static uint8_t perSecondTimer{ 0 };
356 static bool bOffPeak{
false };
357 static int16_t iTemperature_x100{ 0 };
423 if (8500 == tmp && (abs(tmp -
tx_data.temperature_x100[idx]) > 500))
428 tx_data.temperature_x100[idx] = tmp;
Calibration values definition.
constexpr float f_voltageCal[NO_OF_PHASES]
constexpr float f_powerCal[NO_OF_PHASES]
void proceed_relays() const
Proceed all relays in increasing order (surplus) or decreasing order (import)
static void update_average(int16_t currentPower)
Update the sliding average.
void inc_duration() const
Increment the duration's state of each relay.
constexpr auto get_size() const
Get the number of sensors.
int16_t readTemperature(const uint8_t idx)
Read temperature of a specific device.
void requestTemperatures()
Request temperature for all sensors.
void initTemperatureSensors()
Initialize the Dallas sensors.
Configuration values to be set by the end-user.
constexpr bool RELAY_DIVERSION
constexpr bool OVERRIDE_PIN_PRESENT
constexpr uint8_t dualTariffPin
constexpr TemperatureSensing temperatureSensing
constexpr uint8_t forcePin
constexpr RelayEngine relays
constexpr uint32_t ROTATION_AFTER_CYCLES
constexpr bool DUAL_TARIFF
constexpr uint8_t diversionPin
constexpr bool EMONESP_CONTROL
constexpr uint8_t NO_OF_DUMPLOADS
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
ISR(ADC_vect)
Interrupt Service Routine - Interrupt-Driven Analog Conversion.
void processVoltageRawSample(const uint8_t phase, const int16_t rawSample)
Process the current voltage raw sample for the specific phase.
void processCurrentRawSample(const uint8_t phase, const int16_t rawSample)
Process the calculation for the actual current raw sample for the specific phase.
void checkDiversionOnOff()
Check the diversion state.
void setup()
Called once during startup.
bool forceFullPower()
This function set all 3 loads to full power.
bool proceedLoadPrioritiesAndOverridingDualTariff(const int16_t currentTemperature_x100)
Proceed load priority in combination with dual tariff.
void proceedRotation()
Proceed load priority rotation.
bool proceedLoadPrioritiesAndOverriding(const int16_t currentTemperature_x100)
This function changes the value of the load priorities.
void loop()
Main processor.
void initializeOptionalPins()
Initializes the optional pins.
void initializeProcessing()
Initializes the ports and load states for processing.
Public functions/variables of processing engine.
volatile bool b_reOrderLoads
constexpr uint8_t sensorV[NO_OF_PHASES]
constexpr uint8_t sensorI[NO_OF_PHASES]
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES]
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]
volatile bool b_newMainsCycle
volatile bool b_datalogEventPending
volatile uint32_t absenceOfDivertedEnergyCount
volatile bool b_diversionOff
constexpr uint16_t initialDelay
PayloadTx_struct< NO_OF_PHASES > tx_data
Some basics classes/types.
void printConfiguration()
Print the configuration during start.
int freeRam()
Get the available RAM during setup.
void sendResults(bool bOffPeak)
Prints data logs to the Serial output in text or json format.
void logLoadPriorities()
Prints the load priorities to the Serial output.
constexpr void togglePin(const uint8_t pin)
Toggle the specified pin.
bool getPinState(const uint8_t pin)
Get the Pin State.
Some utility functions for the relay output feature.
constexpr bool TEMP_SENSOR_PRESENT
Compile-time validations.