#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.
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