sailingYOLO - Hi guys.This code works well ex...

Hi guys. This code works well except it doesn't send value every 11 seconds. If the value has changed or not it should send it, right? What do I need to do different? The only time a value is sent is when the value change on pin 4 OR the ESP restarts. If I have a value in the SK-server and then restart the SK-server the SK-path goes away and does not appear until I restart the ESP or change the value on pin 4 (trigger/untrigger the sensor). How can I make it repeat every 11 seconds, as I thought I was doing?
c++
// Bilge Monitor //

const uint8_t kDigitalInputBilgePin = 4;
const unsigned int kDigitalInputBilgeInterval = 11000;

// Configure the pin. Replace this with your custom library initialization
// code!
pinMode(kDigitalInputBilgePin, INPUT_PULLUP);

SKMetadata* Bilgemetadata = new SKMetadata();
Bilgemetadata->description_ = "Bilge Sensor";
Bilgemetadata->display_name_ = "Bilge Sensor";
Bilgemetadata->short_name_ = "Bil Sen";

auto* bilge_input = new RepeatSensor<bool>(
kDigitalInputBilgeInterval,
[kDigitalInputBilgePin]() { return digitalRead(kDigitalInputBilgePin); });

bilge_input->connect_to(new DebounceBool(10000,"/bilge/debounce"))
->connect_to(new LambdaTransform<bool, String>([](bool input) ->String {
if (input == 1) {return "Liquid detected in bilge!";}
else {return "Bilge is clear";}}))
->connect_to(new SKOutputString("environment.bilge.liquid",Bilgemetadata));
c++
// Bilge Monitor //

const uint8_t kDigitalInputBilgePin = 4;
const unsigned int kDigitalInputBilgeInterval = 11000;

// Configure the pin. Replace this with your custom library initialization
// code!
pinMode(kDigitalInputBilgePin, INPUT_PULLUP);

SKMetadata* Bilgemetadata = new SKMetadata();
Bilgemetadata->description_ = "Bilge Sensor";
Bilgemetadata->display_name_ = "Bilge Sensor";
Bilgemetadata->short_name_ = "Bil Sen";

auto* bilge_input = new RepeatSensor<bool>(
kDigitalInputBilgeInterval,
[kDigitalInputBilgePin]() { return digitalRead(kDigitalInputBilgePin); });

bilge_input->connect_to(new DebounceBool(10000,"/bilge/debounce"))
->connect_to(new LambdaTransform<bool, String>([](bool input) ->String {
if (input == 1) {return "Liquid detected in bilge!";}
else {return "Bilge is clear";}}))
->connect_to(new SKOutputString("environment.bilge.liquid",Bilgemetadata));
1 Reply
sailingYOLO
sailingYOLOOP2w ago
When i removed the debounce it works. When reading the docs it states that no results are sent if no change in the digitalRead in this case. So there isn't any other way to "debounce" and still send the last debonced state? I built my own threshold function, works great now. If anyone else is struggeling, this is how I did it:
c++
// Bilge Monitor //

const uint8_t kDigitalInputBilgePin = 4;
const unsigned int kDigitalInputBilgeInterval = 1000;

pinMode(kDigitalInputBilgePin, INPUT_PULLUP);

SKMetadata* Bilgemetadata = new SKMetadata();
Bilgemetadata->description_ = "Bilge Sensor";
Bilgemetadata->display_name_ = "Bilge Sensor";
Bilgemetadata->short_name_ = "Bil Sen";

auto* bilge_input = new RepeatSensor<bool>(
kDigitalInputBilgeInterval,
[kDigitalInputBilgePin]() { return gBoolLiquidInBilge; });

bilge_input->connect_to(new LambdaTransform<bool, String>([](bool input) ->String {
if (input == 1) {return "Liquid detected in bilge!";}
else {return "Bilge is clear";}}))
->connect_to(new SKOutputString("environment.bilge.liquid",Bilgemetadata));

bilge_input->connect_to(new SKOutputBool("environment.bilge.liquidBool"));

event_loop()->onRepeat(kDigitalInputBilgeInterval, []() {
bool bilge = digitalRead(kDigitalInputBilgePin);
//ESP_LOGD(__FILENAME__, "********Bilge bilge=%d count=%d ", (int)bilge, gIntBilgeCount);
if (bilge){
gIntBilgeCount++;
if (gIntBilgeCount > 11){gIntBilgeCount = 11;} // Prevents overflow
if (gIntBilgeCount > 10 and gBoolLiquidInBilge == false){
gBoolLiquidInBilge = true;
updateDisplay();
}
} else {
gIntBilgeCount--;
if (gIntBilgeCount < 0){gIntBilgeCount = 0;} // Prevents overflow
if (gIntBilgeCount < 1 and gBoolLiquidInBilge == true){
gBoolLiquidInBilge = false;
updateDisplay();
gIntBilgeCount = 0;
}
}
});
c++
// Bilge Monitor //

const uint8_t kDigitalInputBilgePin = 4;
const unsigned int kDigitalInputBilgeInterval = 1000;

pinMode(kDigitalInputBilgePin, INPUT_PULLUP);

SKMetadata* Bilgemetadata = new SKMetadata();
Bilgemetadata->description_ = "Bilge Sensor";
Bilgemetadata->display_name_ = "Bilge Sensor";
Bilgemetadata->short_name_ = "Bil Sen";

auto* bilge_input = new RepeatSensor<bool>(
kDigitalInputBilgeInterval,
[kDigitalInputBilgePin]() { return gBoolLiquidInBilge; });

bilge_input->connect_to(new LambdaTransform<bool, String>([](bool input) ->String {
if (input == 1) {return "Liquid detected in bilge!";}
else {return "Bilge is clear";}}))
->connect_to(new SKOutputString("environment.bilge.liquid",Bilgemetadata));

bilge_input->connect_to(new SKOutputBool("environment.bilge.liquidBool"));

event_loop()->onRepeat(kDigitalInputBilgeInterval, []() {
bool bilge = digitalRead(kDigitalInputBilgePin);
//ESP_LOGD(__FILENAME__, "********Bilge bilge=%d count=%d ", (int)bilge, gIntBilgeCount);
if (bilge){
gIntBilgeCount++;
if (gIntBilgeCount > 11){gIntBilgeCount = 11;} // Prevents overflow
if (gIntBilgeCount > 10 and gBoolLiquidInBilge == false){
gBoolLiquidInBilge = true;
updateDisplay();
}
} else {
gIntBilgeCount--;
if (gIntBilgeCount < 0){gIntBilgeCount = 0;} // Prevents overflow
if (gIntBilgeCount < 1 and gBoolLiquidInBilge == true){
gBoolLiquidInBilge = false;
updateDisplay();
gIntBilgeCount = 0;
}
}
});

Did you find this page helpful?