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

[question] Async response handler: sending back responses doesn't work without delay #31

Closed
robertklep opened this issue Apr 13, 2021 · 2 comments

Comments

@robertklep
Copy link

I have an issue with sending back responses from an async response handler. My code looks like this:

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

void processRequest(unsigned long request, OpenThermResponseStatus status) {
  if (status != OpenThermResponseStatus::SUCCESS) return;

  auto dataId = ot.getDataID(request);
  auto response;

  if (dataId == 0) {
    response = ot.buildResponse(…);
  } else if (dataId == 1) {
    response = ot.buildResponse(…);
  } else { … }

  ot.sendResponse(response);
}

void setup() {
  ot.begin(handleInterrupt, processRequest);
}

void loop() {
  ot.process();
}

Basically, I'm trying to build a (very minimal) boiler simulator by responding to commands sent by a thermostat.

The issue is that unless I add a delay (of about 200ms) before ot.sendResponse(), the response seems to put the thermostat in an error mode. Do I have to wait for a specific event before I can send back a response? Or am I doing something wrong entirely?

For what it's worth, the thermostat is sending quite a lot of messages, mostly READ_DATA for different types of data ID's.

@ihormelnyk
Copy link
Owner

Hi @robertklep ,
It is necessary to add a delay before a response.
According to OT protocol specification:

The slave is expected to respond with a single frame reply within a defined period of 20ms to 800ms from the end of the master transmission.
The master unit must wait 100ms from the end of a previous conversation before initiating a new
conversation. The master must communicate at least every 1 sec

@robertklep
Copy link
Author

@ihormelnyk thanks! I changed the delay to 30ms to be safe and that seems to be acceptable 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants