Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phantom data from flow meter #301

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main/kernel/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Tag {
static constexpr const char* PM = "farmhub:pm";
static constexpr const char* RTC = "farmhub:rtc";
static constexpr const char* WIFI = "farmhub:wifi";

class Peripheral {
public:
static constexpr const char* FLOW_METER = "farmhub:perip:flow-meter";
};
};

#define LOGTE(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
Expand Down Expand Up @@ -85,6 +90,8 @@ class Log {
Tag::PM,
Tag::RTC,
Tag::WIFI,

Tag::Peripheral::FLOW_METER,
};
};

Expand Down
4 changes: 2 additions & 2 deletions main/peripherals/flow_meter/FlowMeterComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FlowMeterComponent
: Component(name, mqttRoot)
, qFactor(qFactor) {

LOGI("Initializing flow meter on pin %s with Q = %.2f",
LOGTI(Tag::Peripheral::FLOW_METER, "Initializing flow meter on pin %s with Q = %.2f",
pin->getName().c_str(), qFactor);

pcntUnit = pcnt.registerUnit(pin);
Expand All @@ -52,7 +52,7 @@ class FlowMeterComponent
if (pulses > 0) {
Lock lock(updateMutex);
double currentVolume = pulses / this->qFactor / 60.0f;
LOGV("Counted %d pulses, %.2f l/min, %.2f l",
LOGTV(Tag::Peripheral::FLOW_METER, "Counted %d pulses, %.2f l/min, %.2f l",
pulses, currentVolume / (elapsed.count() / 1000.0f / 60.0f), currentVolume);
volume += currentVolume;
lastSeenFlow = now;
Expand Down
13 changes: 11 additions & 2 deletions wokwi/diagram.flow-control-mk6.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"id": "battery",
"top": -106.9,
"left": 9.4,
"attrs": { "value": "950" }
"attrs": { "value": "1000" }
},
{
"type": "wokwi-resistor",
Expand Down Expand Up @@ -120,6 +120,13 @@
"top": 169.4,
"left": 153.6,
"attrs": { "color": "green", "label": "Flash", "bounce": "0" }
},
{
"type": "wokwi-pushbutton",
"id": "btn2",
"top": -22.6,
"left": -115.2,
"attrs": { "color": "green", "label": "Flow", "bounce": "1", "key": "m" }
}
],
"connections": [
Expand Down Expand Up @@ -150,7 +157,9 @@
[ "nsleepLed:C", "r4:2", "green", [ "h-18.8", "v28.8" ] ],
[ "r4:1", "esp:GND.1", "black", [ "v0" ] ],
[ "esp:GND.4", "btn1:2.l", "black", [ "h0" ] ],
[ "esp:0", "btn1:1.l", "green", [ "h0" ] ]
[ "esp:0", "btn1:1.l", "green", [ "h0" ] ],
[ "btn2:2.r", "esp:6", "green", [ "h9.8", "v67.4" ] ],
[ "esp:GND.2", "btn2:1.r", "black", [ "v0" ] ]
],
"dependencies": {}
}
Loading