ihormelnyk / opentherm_library

Arduino/ESP8266/ESP32 OpenTherm Library for HVAC system control communication
MIT License
207 stars 91 forks source link

Asynchronous requests example? #13

Open phenotypic opened 5 years ago

phenotypic commented 5 years ago

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 commented 3 years ago

Look here - https://github.com/miksumin/OpenTherm/tree/master/examples/OpenThermMaster_Async

ProphetOfDoom commented 5 months ago

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