Skip to content

Comments

Add custom OT requests#138

Draft
nARN wants to merge 4 commits intoLaxilef:masterfrom
nARN:custom_requests
Draft

Add custom OT requests#138
nARN wants to merge 4 commits intoLaxilef:masterfrom
nARN:custom_requests

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

}

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 с данными

});
}

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 сек наличие ответа, после получения ответа разблокировать кнопку отправки и сбросить таймер/интервал

@Laxilef Laxilef marked this pull request as draft September 28, 2025 05:26
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