Skip to content

Commit

Permalink
Add a notification callback to sensor nodes to be called when data ha…
Browse files Browse the repository at this point in the history
…s been sent.
  • Loading branch information
luebbe committed Mar 16, 2023
1 parent cdec086 commit a9baff8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SensorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void SensorNode::loop()
{
send();
_lastSendTime = now;
if (_onDataSent != NULL)
{
_onDataSent();
}
}
}
}
10 changes: 10 additions & 0 deletions src/SensorNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

class SensorNode : public BaseNode
{
public:
typedef std::function<void(void)> TOnDataSent;

protected:
static const int READ_INTERVAL = 300 * 1000UL; // 300 seconds
static const int SEND_INTERVAL = 300 * 1000UL;
Expand All @@ -26,6 +29,8 @@ class SensorNode : public BaseNode
const float cMinHumid = 0.0;
const float cMaxHumid = 100.0;

TOnDataSent _onDataSent;

float computeAbsoluteHumidity(float tempCelsius, float percentHumidity);
float computeDewpoint(float tempCelsius, float percentHumidity);

Expand All @@ -42,4 +47,9 @@ class SensorNode : public BaseNode
explicit SensorNode(const char *id, const char *name, const char *type,
const int readInterval = READ_INTERVAL,
const int sendInterval = SEND_INTERVAL);

void SetOnDataSent(TOnDataSent OnDataSent)
{
_onDataSent = OnDataSent;
}
};

0 comments on commit a9baff8

Please sign in to comment.