Skip to content

Commit

Permalink
experiment(parser): provide likely water consumption counter
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Aug 16, 2024
1 parent bf873b6 commit a89d77d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions AquaMQTT/include/message/MainEnergyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MainEnergyMessage

uint16_t powerOverall();

uint16_t totalWaterConsumption();

void compareWith(uint8_t* data);

bool totalHeatpumpHoursChanged() const;
Expand All @@ -44,6 +46,8 @@ class MainEnergyMessage

bool powerOverallChanged() const;

bool totalWaterConsumptionChanged() const;

private:
uint8_t* mData;

Expand All @@ -54,6 +58,7 @@ class MainEnergyMessage
bool mTotalHeatElementHoursChanged;
bool mTotalHoursChanged;
bool mTotalEnergyChanged;
bool mTotalWaterConsumptionChanged;
};

} // namespace message
Expand Down
1 change: 1 addition & 0 deletions AquaMQTT/include/mqtt/MQTTDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ constexpr char ENERGY_TOTAL_ENERGY_WH[] = { "totalEnergyWh" };
constexpr char ENERGY_POWER_TOTAL[] = { "powerTotal" };
constexpr char ENERGY_POWER_HEAT_ELEMENT[] = { "powerHeatingElem" };
constexpr char ENERGY_POWER_HEATPUMP[] = { "powerHeatpump" };
constexpr char ENERGY_TOTAL_WATER_CONSUMPTION[] = { "waterConsumption" };

constexpr char ERROR_ERROR_NUMBER[] = { "errorNumber" };

Expand Down
4 changes: 2 additions & 2 deletions AquaMQTT/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ framework = arduino
test_framework = googletest
build_flags = -std=c++11
# uncomment the below lines to use over the air update
#upload_protocol = espota
#upload_port = 192.168.188.62
upload_protocol = espota
upload_port = 192.168.188.62
lib_deps =
locoduino/RingBuffer
FrankBoesing/FastCRC
Expand Down
16 changes: 16 additions & 0 deletions AquaMQTT/src/message/MainEnergyMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ uint16_t MainEnergyMessage::powerOverall()
{
return ((uint16_t) mData[8] << 8) | (uint16_t) mData[7];
}

uint16_t MainEnergyMessage::totalWaterConsumption()
{
return ((uint16_t) mData[10] << 8) | (uint16_t) mData[9];
}

void MainEnergyMessage::compareWith(uint8_t* data)
{
if (data == nullptr)
Expand All @@ -51,6 +57,7 @@ void MainEnergyMessage::compareWith(uint8_t* data)
mTotalHeatElementHoursChanged = true;
mTotalHoursChanged = true;
mTotalEnergyChanged = true;
mTotalWaterConsumptionChanged = true;
return;
}

Expand All @@ -76,6 +83,10 @@ void MainEnergyMessage::compareWith(uint8_t* data)
case 8:
mPowerOverallChanged = true;
break;
case 9:
case 10:
mTotalWaterConsumptionChanged = true;
break;
case 11:
case 12:
case 13:
Expand Down Expand Up @@ -118,6 +129,7 @@ MainEnergyMessage::MainEnergyMessage(uint8_t* data)
, mTotalHeatElementHoursChanged(false)
, mTotalHoursChanged(false)
, mTotalEnergyChanged(false)
, mTotalWaterConsumptionChanged(false)
{
}
bool MainEnergyMessage::totalHeatpumpHoursChanged() const
Expand Down Expand Up @@ -148,6 +160,10 @@ bool MainEnergyMessage::powerOverallChanged() const
{
return mPowerOverallChanged;
}
bool MainEnergyMessage::totalWaterConsumptionChanged() const
{
return mTotalWaterConsumptionChanged;
}

} // namespace message
} // namespace aquamqtt
4 changes: 4 additions & 0 deletions AquaMQTT/src/task/MQTTTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ void MQTTTask::updateEnergyStats(bool fullUpdate)
publishul(ENERGY_SUBTOPIC, ENERGY_POWER_TOTAL, message.powerOverall());
}

if(message.totalWaterConsumptionChanged()) {
publishul(ENERGY_SUBTOPIC, ENERGY_TOTAL_WATER_CONSUMPTION, message.totalWaterConsumption());
}

if (config::DEBUG_RAW_SERIAL_MESSAGES)
{
sprintf(reinterpret_cast<char*>(mTopicBuffer),
Expand Down

0 comments on commit a89d77d

Please sign in to comment.