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

Asynchronous requests example? #13

Open
phenotypic opened this issue Apr 20, 2019 · 2 comments
Open

Asynchronous requests example? #13

phenotypic opened this issue Apr 20, 2019 · 2 comments

Comments

@phenotypic
Copy link

phenotypic commented Apr 20, 2019

Hi there,

I'm currently developing a script which aims to integrate an OpenTherm boiler with Homebridge.

In this script, I attempt to make quite a few requests at the same time and have noticed that there is a large delay in doing so, causing the script to run slowly. After doing some looking around, I saw that you mentioned asynchronous requests on your website and assume that these will be able to fix the issue by implementing them on all of the requests I make to OpenTherm.

However, whilst you did write some basic instructions on how to implement these requests, I am still struggling to understand exactly how to do so. Would you be able to give a short example showing how exactly to implement asynchronous requests?

To help illustrate, here is a simplified version of my script (delay(1000); is purely there for simplicity - look here for clarity):

#include <OpenTherm.h>

const int inPin = 4;
const int outPin = 5;
OpenTherm ot(inPin, outPin);

unsigned long request, response;
float boilerTempCurrent, dhwTemp;
int currentHeatingCoolingState, domesticHotWater;

bool enableCentralHeating = true;
bool enableHotWater = true;
bool enableCooling = false;
float dhwSetPoint = 50;
float boilerTargetTemp = 90;

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

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

void loop() {

  //Set statuses
  response = ot.setBoilerStatus(enableCentralHeating, enableHotWater, enableCooling);
  OpenThermResponseStatus responseStatus = ot.getLastResponseStatus();
  if (responseStatus != OpenThermResponseStatus::SUCCESS) {
    Serial.println("Error: Invalid boiler response " + String(response, HEX));
  } else {

   //Get CH temperature
    boilerTempCurrent = ot.getBoilerTemperature();

    //Set CH temperature
    ot.setBoilerTemperature(boilerTargetTemp);

    //Get CH state
    currentHeatingCoolingState = ot.isCentralHeatingEnabled(response);

    //Get DHW state
    domesticHotWater = ot.isHotWaterEnabled(response);

    // Set DHW temperature
    unsigned int data = ot.temperatureToData(dhwSetPoint);
    request = ot.buildRequest(
      OpenThermRequestType::WRITE,
      OpenThermMessageID::TdhwSet,
      data
    );
    ot.sendRequest(request);

    // Get DHW temperature
    request = ot.buildRequest(
      OpenThermRequestType::READ,
      OpenThermMessageID::Tdhw,
      0x0000
    );
    response = ot.sendRequest(request);
    dhwTemp = ot.getTemperature(response);
  }
  //Simulate `milis()`
  delay(1000);
}

Thank you in advance for your help,

Kind regards, Tom

@miksumin
Copy link

miksumin commented Mar 15, 2021

@ProphetOfDoom
Copy link

I know it's been a while since the above post, but I thought I'd add my recent observations.

I flashed the following Arduino sketch by the same author as above to my ESP32-DevkitC-V4 board with DiyLess ESP32/ESP8266 Thermostat Shield, connected to my (nearly new) Baxi 824 System Boiler.

https://github.com/miksumin/OpenTherm/tree/master/examples/OpenThermTestIDs

This produced the attached output, but worringly, left the boiler flashing an E83 (Communication Error) message, which repeatedly returned after disconnecting the ESP32 kit and power cycling the boiler to return to Hive 230v control. I couldn't find anything online on how to clear this error message, but eventually reasoned that it might have been due to the final request/response in the above sketch returning an error, as shown in the log. So, I then flashed the ESP32 with a simple sketch that periodically just gets the boiler temperature as shown below, and to my great relief, this cleared the boiler error message.

  // Get Boiler Temperature
  ch_temperature = ot.getBoilerTemperature();
  Serial.println("CH temperature is " + String(ch_temperature) + " degrees C");

Looking at the output log, it seems that my Baxi 824 System Boiler is OpenTherm 4.0, information I surprisingly couldn't find in any of the manuals or online!

Hope this helps someone.

arduino_output.log

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

3 participants