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

Add custom OT requests #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add custom OT requests #138

wants to merge 4 commits into from

Conversation

nARN
Copy link
Contributor

@nARN nARN commented Feb 3, 2025

See https://t.me/otgateway/9331/10060

This will be useful to quickly detect which messages the boiler supports.

WRT the safety of calling sendRequest from another task. As far as I can see, OpenTherm is essentially a state machine and won't attempt to put anything on the wire until in READY state. Given that the request from the web form uses the same object (and thus state) there should not be any concurrency concerns.

Screencast:

OTGateway-custom-message-demo.mov

@nARN nARN marked this pull request as ready for review February 9, 2025 12:54
@nARN nARN changed the title WIP: Add custom OT requests Add custom OT requests Feb 9, 2025
@Laxilef Laxilef self-assigned this Feb 20, 2025
@Laxilef Laxilef added the enhancement New feature or request label Feb 20, 2025
@Laxilef
Copy link
Owner

Laxilef commented Feb 20, 2025

Приветствую

Думаю делать запрос в шину из PortalTask - не лучшая идея. Поэтому добавил свои мысли как можно сделать отправку запроса внутри OpenThermTask, а чтение результата в PortalTask.

@Laxilef Laxilef self-requested a review March 1, 2025 18:18
@@ -9,6 +9,30 @@ class OpenThermTask : public Task {
delete this->instance;
}

struct ReadResult{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переименовать в ExternalRequest

@@ -9,6 +9,30 @@ class OpenThermTask : public Task {
delete this->instance;
}

struct ReadResult{
bool valid = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить поле status:

OpenThermStatus status = OpenThermStatus::NOT_INITIALIZED;

uint16_t value = 0;
};

ReadResult readRequest(byte messageId) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо этого добавить метод sendExternalRequest(OpenThermMessageID id, unsigned int data), который будет заполнять структуру ExternalRequest. При вызове метода устанавливать статус OpenThermStatus::RESPONSE_WAITING.
И было бы здорово иметь возможность отправлять данные, а не только читать значение по ID'у :)

Добавить метод bool hasReadyExternalRequest(), который будет проверять статус.
Добавить метод unsigned long getResponseExternalRequest(), который будет возвращать респонс из ExternalRequest.

Внутри OpenThermTask::loop() проверять статус ExternalRequest, если он OpenThermStatus::RESPONSE_WAITING, то делать this->instance->sendRequest(...) и заполнять ExternalRequest. Статус после выполнения запроса поменять на OpenThermStatus::RESPONSE_READY.

doc.clear();
doc.shrinkToFit();

auto result = tOt->readRequest(messageId);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо этого вызывать tOt->sendExternalRequest(...)

doc[FPSTR(S_VALUE)] = result.value;
doc.shrinkToFit();

this->bufferedWebServer->send(200, F("application/json"), doc);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Просто вернуть пустой ответ с кодом 200

doc.shrinkToFit();

this->bufferedWebServer->send(200, F("application/json"), doc);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить обработчик для чтения данных через tOt->getResponseExternalRequest() если tOt->hasReadyExternalRequest() == true и вывод клиенту json с данными

@@ -522,6 +522,107 @@ const setupUpgradeForm = (formSelector) => {
});
}

const setupOTReadForm = (formSelector) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше переместить в opentherm_request.html

Код поправить:

  1. Сначала отправить запрос на отправку запроса
  2. Проверять каждые 2-5 сек наличие ответа, после получения ответа разблокировать кнопку отправки и сбросить таймер/интервал

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

Successfully merging this pull request may close these issues.

2 participants