Custom sensor 'no matching function for call' error

Hi. I am new in c++, and I try to create custom sensor for my boiler. I’m using OpenTherm Arduino/ESP8266 Library

My .h file:

#include "esphome.h"
#include "OpenTherm.h"

class OpenThermSensor : public PollingComponent, public Sensor
{
public:
    const int inPin = 4;
    const int outPin = 5;

    OpenTherm ot = OpenTherm(inPin, outPin);

    OpenThermSensor() : PollingComponent(1000) {}

    void setup() override
    {
        ot.begin(handleInterrupt);
    }

    void update() override
    {
        publish_state(ot.getBoilerTemperature());
    }

    void handleInterrupt()
    {
        ot.handleInterrupt();
    }
};

But on compile error:

In file included from src/main.cpp:12:0:
src/esp_opentherm.h: In member function 'virtual void OpenThermSensor::setup()':
src/esp_opentherm.h:16:33: error: no matching function for call to 'OpenTherm::begin(<unresolved overloaded function type>)'
         ot.begin(handleInterrupt);
                                 ^
src/esp_opentherm.h:16:33: note: candidates are:
In file included from src/esp_opentherm.h:2:0,
                 from src/main.cpp:12:
/data/heater/.piolibdeps/heater/OpenTherm Library/src/OpenTherm.h:118:7: note: void OpenTherm::begin(void (*)())
  void begin(void(*handleInterruptCallback)(void));
       ^
/data/heater/.piolibdeps/heater/OpenTherm Library/src/OpenTherm.h:118:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'void (*)()'
/data/heater/.piolibdeps/heater/OpenTherm Library/src/OpenTherm.h:119:7: note: void OpenTherm::begin(void (*)(), void (*)(long unsigned int, OpenThermResponseStatus))
  void begin(void(*handleInterruptCallback)(void), void(*processResponseCallback)(unsigned long, OpenThermResponseStatus));
       ^
/data/heater/.piolibdeps/heater/OpenTherm Library/src/OpenTherm.h:119:7: note:   candidate expects 2 arguments, 1 provided
*** [/data/heater/.pioenvs/heater/src/main.cpp.o] Error 1

Why? I can’t understand…

upd: in arduaino scetch it builds, why not builds in ESPHome?

Out of my depth here. But maybe order. Try to put the handleInterrupt() function higher up above the setup function.

The arduino i think is very generous about the declaration order. handleInterrupt() is not part of any h file. So maybe order comes to play here.
Maybe worth a try at least.

/Mattias

I tried to do this, it doesn’t help…

I think that the problem is another.

The handleInterrupt() is a member function. That means that it’s probably not a the correct function pointer that you are looking for. Because the openTerm requires a c function pointer.
When you declare the function in arduino. Then i becomes a c function which works.
I do not have any solution for you. Maybe this is what is your problem.


I hope you find a solution. Sorry I could not help you more.
/Mattias

This code compiles:

class OpenThermSensor : public PollingComponent, public Sensor
{
public:
    OpenTherm ot = OpenTherm(inPin, outPin);

    OpenThermSensor() : PollingComponent(1000) {}

    void setup() override
    {
        ot.begin(&OpenThermSensor::handleInterrupt);
    }

    void update() override
    {
        publish_state(ot.getBoilerTemperature());
    }

    static void handleInterrupt()
    {
    
    }
};

But I can’t access ‘ot’ in static function… Is there any way to make ‘ot’ static?

I found this. He has solved it.

Check the opentherm_component.h.

He declare the handleInterrupt() outside the class.
and make an ot instance that he call from handleInterrupt()

// Configuración OpenTherm
const int inPin = D5; 
const int outPin = D6; 

OpenTherm ot(inPin, outPin, false);

ICACHE_RAM_ATTR void handleInterrupt() {
	ot.handleInterrupt();
}


class OpenthermComponent: public PollingComponent {
private:
  const char *TAG = "opentherm_component";
...

/Mattias

Yes, it works !!! :slight_smile:

Awesome.
/Mattias