mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
Merge pull request #5579 from tonhuisman/bugfix/P020-send-events-for-derived-values
[P020] Send events for Derived values
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
/************
|
||||
* Changelog:
|
||||
* 2026-07-11 tonhuisman: Send also Derived values when sending the event with received data, when enabled and available
|
||||
* 2025-03-26 tonhuisman: Add optional receiving (relaying) of UDP data to Serial. Uses the same port as configured for the (default) TCP
|
||||
* connection. Available on ESP32 only.
|
||||
* Can be enabled for ESP8266 in a Custom build by adding #define P020_USE_PROTOCOL 1
|
||||
|
||||
@@ -297,7 +297,8 @@ void P020_Task::handleSerialIn(struct EventStruct *event) {
|
||||
bool done = false;
|
||||
char ch;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (ser2netSerial->available()) {
|
||||
if ((serial_processing != P020_Events::P1WiFiGateway) // P1 handling without this check
|
||||
&& (serial_buffer.length() > static_cast<size_t>(P020_RX_BUFFER))) {
|
||||
@@ -357,7 +358,7 @@ void P020_Task::handleSerialIn(struct EventStruct *event) {
|
||||
|
||||
blinkLED();
|
||||
|
||||
rulesEngine(serial_buffer);
|
||||
rulesEngine(serial_buffer, event);
|
||||
ser2netClient.PR_9453_FLUSH_TO_CLEAR();
|
||||
clearBuffer();
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
@@ -375,14 +376,16 @@ void P020_Task::discardSerialIn() {
|
||||
}
|
||||
|
||||
// We can also use the rules engine for local control!
|
||||
void P020_Task::rulesEngine(const String& message) {
|
||||
void P020_Task::rulesEngine(const String& message, struct EventStruct *event) {
|
||||
if (!Settings.UseRules || message.isEmpty() || (P020_Events::None == serial_processing)) { return; }
|
||||
int NewLinePos = 0;
|
||||
uint16_t StartPos = 0;
|
||||
int NewLinePos = 0;
|
||||
uint16_t StartPos = 0;
|
||||
bool eventSent = false;
|
||||
|
||||
NewLinePos = handleMultiLine ? message.indexOf('\n', StartPos) : message.length();
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (NewLinePos < 0) {
|
||||
NewLinePos = message.length();
|
||||
}
|
||||
@@ -394,11 +397,14 @@ void P020_Task::rulesEngine(const String& message) {
|
||||
NewLinePos--;
|
||||
}
|
||||
|
||||
switch (serial_processing) {
|
||||
case P020_Events::None: { break; }
|
||||
case P020_Events::Generic: { // Generic
|
||||
switch (serial_processing)
|
||||
{
|
||||
case P020_Events::None:
|
||||
break;
|
||||
case P020_Events::Generic: // Generic
|
||||
{
|
||||
if (NewLinePos > StartPos) {
|
||||
eventString = '!'; // F("!Serial");
|
||||
eventString = '!'; // F("!Serial");
|
||||
|
||||
if (_serialId) {
|
||||
eventString += ESPEasySerialPort_toString(_port, true);
|
||||
@@ -421,8 +427,9 @@ void P020_Task::rulesEngine(const String& message) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case P020_Events::RFLink: { // RFLink
|
||||
StartPos += 6; // RFLink, strip 20;xx; from incoming message
|
||||
case P020_Events::RFLink: // RFLink
|
||||
{
|
||||
StartPos += 6; // RFLink, strip 20;xx; from incoming message
|
||||
|
||||
if (((NewLinePos - StartPos) >= 8) &&
|
||||
message.substring(StartPos, StartPos + 8)
|
||||
@@ -442,6 +449,7 @@ void P020_Task::rulesEngine(const String& message) {
|
||||
eventString += message.substring(StartPos, NewLinePos);
|
||||
}
|
||||
eventQueue.addMove(std::move(eventString));
|
||||
eventSent = true;
|
||||
break;
|
||||
}
|
||||
case P020_Events::P1WiFiGateway: // P1 WiFi Gateway
|
||||
@@ -466,6 +474,7 @@ void P020_Task::rulesEngine(const String& message) {
|
||||
|
||||
if (!eventString.isEmpty()) {
|
||||
eventQueue.add(eventString);
|
||||
eventSent = true;
|
||||
}
|
||||
NewLinePos = message.indexOf('\n', StartPos);
|
||||
|
||||
@@ -473,6 +482,13 @@ void P020_Task::rulesEngine(const String& message) {
|
||||
NewLinePos = message.length();
|
||||
}
|
||||
} while (handleMultiLine && NewLinePos > StartPos);
|
||||
|
||||
# if FEATURE_STRING_VARIABLES
|
||||
|
||||
if (eventSent) {
|
||||
sendData(event); // Send derived values
|
||||
}
|
||||
# endif // if FEATURE_STRING_VARIABLES
|
||||
}
|
||||
|
||||
bool P020_Task::isInit() const {
|
||||
@@ -483,10 +499,7 @@ bool P020_Task::isInit() const {
|
||||
) && nullptr != ser2netSerial;
|
||||
}
|
||||
|
||||
void P020_Task::sendConnectedEvent(bool connected)
|
||||
{
|
||||
eventQueue.add(_taskIndex, F("Client"), (connected ? 1 : 0));
|
||||
}
|
||||
void P020_Task::sendConnectedEvent(bool connected) { eventQueue.add(_taskIndex, F("Client"), (connected ? 1 : 0)); }
|
||||
|
||||
void P020_Task::blinkLED() {
|
||||
if (_ledEnabled) {
|
||||
@@ -605,7 +618,8 @@ bool P020_Task::handleP1Char(char ch) {
|
||||
bool done = false;
|
||||
bool invalid = false;
|
||||
|
||||
switch (_state) {
|
||||
switch (_state)
|
||||
{
|
||||
case ParserState::WAITING:
|
||||
|
||||
if (ch == P020_DATAGRAM_START_CHAR) {
|
||||
|
||||
@@ -79,6 +79,7 @@ enum class P020_Events : uint8_t {
|
||||
Generic = 1u,
|
||||
RFLink = 2u,
|
||||
P1WiFiGateway = 3u,
|
||||
|
||||
};
|
||||
|
||||
# if P020_USE_PROTOCOL
|
||||
@@ -86,7 +87,9 @@ enum class P020_Protocol_e : uint8_t {
|
||||
TCP = 0u,
|
||||
UDP = 1u,
|
||||
TCP_UDP = 2u,
|
||||
|
||||
};
|
||||
|
||||
# endif // if P020_USE_PROTOCOL
|
||||
|
||||
struct P020_Task : public PluginTaskData_base {
|
||||
@@ -94,6 +97,7 @@ struct P020_Task : public PluginTaskData_base {
|
||||
WAITING,
|
||||
READING,
|
||||
CHECKSUM
|
||||
|
||||
};
|
||||
|
||||
P020_Task(struct EventStruct *event);
|
||||
@@ -120,7 +124,8 @@ struct P020_Task : public PluginTaskData_base {
|
||||
void handleSerialIn(struct EventStruct *event);
|
||||
void handleClientIn(struct EventStruct *event);
|
||||
void discardSerialIn();
|
||||
void rulesEngine(const String& message);
|
||||
void rulesEngine(const String & message,
|
||||
struct EventStruct *event);
|
||||
|
||||
bool isInit() const;
|
||||
|
||||
@@ -187,6 +192,7 @@ struct P020_Task : public PluginTaskData_base {
|
||||
bool _eventAsHex = false;
|
||||
|
||||
ESPEasySerialPort _port;
|
||||
|
||||
};
|
||||
|
||||
#endif // ifdef USES_P020
|
||||
|
||||
Reference in New Issue
Block a user