Skip to content

Commit 274b1e8

Browse files
authored
Merge pull request #4283 from tonhuisman/feature/P044-led-and-events-without-client
[P044] Led settings and events without client, merged into [P020]
2 parents 08e1144 + 97bb276 commit 274b1e8

30 files changed

+1270
-429
lines changed

docs/source/Plugin/P020.rst

+97-7
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,120 @@ Supported hardware
2626

2727
|P020_usedby|
2828

29+
Configuration
30+
-------------
31+
32+
.. image:: P020_DeviceConfiguration.png
33+
34+
* **Name** In the Name field a unique name should be entered.
35+
36+
* **Enabled** When unchecked the plugin is not enabled.
37+
2938
Sensor
3039
^^^^^^
3140

3241
See: :ref:`SerialHelper_page`
3342

43+
Device Settings
44+
^^^^^^^^^^^^^^^
45+
46+
* **TCP Port**: The port for an external network client to read the data from, range 1..65535. The used port number must be unique within the device.
47+
48+
* **Baud Rate / Serial config**: See *Serial helper configuration*, above.
49+
50+
* **Event Processing**: Select the type of data that is expected, to enable correct preprocessing. Available options:
51+
52+
.. image:: P020_EventProcessingOptions.png
53+
54+
* *None*: No special processing, what is received is sent out to the network client, not generating an event.
55+
56+
* *Generic*: No special processing, received data is sent to the network client, and an event ``!Serial#<message>``, containing the message as is, is generated. Spaces and newlines are processed as configured below.
57+
58+
* *RFLink*: Specifically designed for receiving serial data from RFLink devices, it follows this process:
59+
60+
* Remove the regular RFLink ``20;xx;`` prefix
61+
* Check for prefix ``ESPEASY;``, if found, remove the prefix and generate event ``RFLink#<message>``. The ``<message>`` will contain commands to be handled by ESPEasy.
62+
* If previous prefix is not found, generate event ``!RFLink#<message>``, containing the entire received data. Spaces and newlines are processed as configured below.
63+
64+
*Also see the* **Multiple lines processing** *option, below.*
65+
66+
* *P1 WiFi Gateway*: Process the data, received from a P1 Energy meter, that does a checksum validation, as included in the message. No separate data values are available in ESPEasy, these are usually handled by Home automation systems that support the P1 protocol via TCP network communication. An event ``<TaskName>#Data`` is generated when a valid P1 packet is received.
67+
68+
Replacing spaces or newlines should be **disabled** for the P1 protocol data to be handled properly as these replacements will disturb the checksum calculation, and also, the **Multiple lines processing** should be disabled if the data is to be handled as P1 protocol data, as that does contain newlines.
69+
70+
.. spacer
71+
72+
* **P1 #data event with message**: When enabled, the *P1 WiFi Gateway* Event Processing option will include the received message. **WARNING** This may easily cause memory overflow exceptions, especially when running on ESP8266 or other low-memory situations!
73+
74+
When selecting the **Event processing** options *Generic* or *RFLink*, after submitting the page will show extra options for the events generated:
75+
76+
.. image:: P020_EventOptions.png
3477

35-
**TODO**: Complete this documentation...
78+
* **Use Serial Port as eventname**: Instead of the default ``!Serial#<data>`` event, the name of the configured serial port will be used: (**Only** available for *Generic* Event processing)
3679

37-
.. Commands available
38-
.. ^^^^^^^^^^^^^^^^^^
80+
.. spacer
3981
40-
.. .. include:: P020_commands.repl
82+
* *(Unchecked)* -> ``Serial``
83+
* *HW Serial0* -> ``serial0``
84+
* *HW Serial0 swap* -> ``serial0``
85+
* *HW Serial1* -> ``serial1``
86+
* *HW Serial2* -> ``serial2``
87+
* *SW Serial* -> ``serialsw``
88+
* *I2C Serial* -> ``seriali2c``
89+
* *USB HWCDC* -> ``serialhwcdc``
90+
* *USB CDC* -> ``serialcdc``
4191

42-
.. Events
43-
.. ~~~~~~
92+
.. spacer
4493
45-
.. .. include:: P020_events.repl
94+
* **Append Task Number to eventname**: Will append the task number to the event name, f.e. ``Serial8`` or ``RFLink12`` when task 8 or 12 is in use for this plugin. Can be combined with **Use Serial Port as eventname** if that is option is shown, resulting f.e. in ``serial0swap6`` etc. (Only available for *Generic* and *RFLink* Event processing)
95+
96+
.. spacer
97+
98+
* **Replace spaces in event by**: Here a single character can be selected to replace all spaces during receiving the data.
99+
* **Replace newlines in event by**: Here a single character can be selected to replace all newlines during receiving the data. When enabled, all linefeeds are replaced, and all carriage returns (if any) are discarded.
100+
101+
.. image:: P020_ReplaceCharInEventOptions.png
102+
103+
The available set of replacement characters is ``, ; : . ! ^ | / \`` (comma, semicolon, colon, period, exclamation, caret, pipe, slash and backslash). When set to None, no replacement will be done.
104+
105+
* **Process events without client**: By default, if no network client is connected, no serial data will be received and processed either. Enabling this option enables receiving data and generating events without a TCP client connected.
106+
107+
* **Multiple lines processing**: When enabled, all received data will be split at a linefeed and sent out/event generated as separate messages.
108+
109+
* **RX Receive timeout (mSec)**: If parts of serial data packets are somewhat delayed, but should still be handled as a single message, then the delay to wait for the next part can be configured here. 0 disables the delay.
110+
111+
* **Reset target after init**: Select a GPIO pin that should be pulled low once during initialization of the plugin, used to synchronize the external serial data source with the plugin.
112+
113+
* **RX Buffer size (bytes)**: To not overburden the memory use of the plugin, the buffer size is set rather low. Some serial devices, like energy meters may require a larger buffer if the message exceeds this size. Range: 256..1024.
114+
115+
Led
116+
^^^
117+
118+
* **Led enabled**: To enable a *data is being processed* activity led.
119+
120+
* **Led pin**: The GPIO pin the Led is connected to.
121+
122+
* **Led inverted**: Iverts the on/off state for the Led.
123+
124+
Data Acquisition
125+
^^^^^^^^^^^^^^^^
126+
127+
The Data Acquisition and Send to Controller settings are standard available configuration items. Send to Controller only when one or more Controllers are configured. *Single event with all values* option is not applicable for this plugin.
128+
129+
130+
Commands
131+
~~~~~~~~
132+
133+
.. include:: P020_commands.repl
46134

47135
Change log
48136
----------
49137

50138
.. versionchanged:: 2.0
51139
...
52140

141+
|changed| 2022-12-13: Merge of P020 and P044 to reduce code size and combine features, as P044 was initially started as a spin-off from P020, but not evolved with the P020 features.
142+
53143
|added|
54144
Major overhaul for 2.0 release.
55145

67.6 KB
Loading
30.1 KB
Loading
Loading
Loading

docs/source/Plugin/P020_commands.repl

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. csv-table::
2+
:header: "Command", "Extra information"
3+
:widths: 20, 30
4+
5+
"
6+
``serialsend,<content to send>``
7+
8+
``<content to send>``: Text that will be sent (nearly) unprocessed. Only the regular variable replacements will be applied before sending the content to the serial port.
9+
","
10+
Using this command, either from rules, via http or mqtt, the text that is provided as content is completely sent to the serial port. No extra data is added, other than any (system) variables that are included, being replaced.
11+
"
12+
"
13+
``ser2netclientsend,<content to send>``
14+
15+
``<content to send>``: Text that will be sent (nearly) unprocessed. Only the regular variable replacements will be applied before sending the content to the network client.
16+
","
17+
This command will only send data to the network client, when there is an active connection.
18+
19+
Using this command, either from rules, via http or mqtt, the text that is provided as content is completely sent to the network client. No extra data is added, other than any (system) variables that are included, being replaced.
20+
"
21+
"
22+
``serialsendmix,'<content to send>'[,...]``
23+
24+
``<content to send>``: Text and/or hex byte(s) (having 0x prefix) that will be sent (nearly) unprocessed. Only the regular variable replacements will be applied before sending the content to the serial port.
25+
","
26+
27+
This command requires quotes to be used if spaces or commas are part of the content.
28+
29+
Any data can be sent, even if it can not be typed in a text content, by specifying that as a separate argument: ``serialsendmix,'text, optionally including spaces or commas',0xXX,'0xXXxx XX,xx-XX:xx'``
30+
31+
``'text, optionally including spaces or commas'``: Any text content to be sent to the serial port. Can contain variables. Quotes are only required if spaces or commas (separators) are used.
32+
33+
``0xXX``: A single character in hexadecimal notation (range: 0x00..0xFF), that is appended to the data to send.
34+
35+
``'0xXXxx XX,xx-XX:xx'``: A sequence of hexadecimal values (range: 0x00..0xFF), that *can* be separated by a space, comma, dash, colon, semicolon or period, or are just entered adjecent. Only the first 2 characters should be ``0x`` or ``0X``, the rest is interpreted as hex bytes, and appended to the string to send. Quotes are only required if space or comma separators are used.
36+
Using this command, either from rules, via http or mqtt, the text that is provided as content is completely sent to the serial port. No extra data is added, other than any (system) variables that are included, being replaced.
37+
"

docs/source/Plugin/P037.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,17 @@ Option: Limit events being generated
190190

191191
* **Max. # events in event queue**: As a protection against event-overflow this configures a check for the queue-length, so if more than the selected number of events is still in the queue, new events will be discarded until some events are processed, and the remaining is less than this count. When set to 0 this check is disabled.
192192

193-
Option: Modify separater character in events
193+
Option: Modify separator character in events
194194
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195195

196196
* **To replace by comma in event**: Select a character that is to be replaced by a comma, before it is put into the event-queue. There is a limited set of characters that can be replaced, to avoid ending up with malformed events.
197197

198+
Available options:
199+
200+
.. image:: P037_ReplaceByCommaOptions.png
201+
202+
The available set of replacement characters is ``! @ $ % ^ & * ; : . | / \`` (exclamation, at, dollar, percent, caret, ampersand, semicolon, colon, period, pipe, slash and backslash). When set to None, no replacement will be done.
203+
198204
This can be used to 'transform' the content of a JSON message so the used separator is a comma, for easier use in rules.
199205

200206
Topic Subscriptions
Loading

docs/source/Plugin/P044.rst

+32-7
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,55 @@ Supported hardware
2626

2727
|P044_usedby|
2828

29+
.. note:: This plugin is now merged (back) into :ref:`P020_page` where it initially was forked off from, with using some predefined settings.
30+
31+
Configuration
32+
-------------
33+
34+
.. image:: P044_DeviceConfiguration.png
35+
36+
* **Name** In the Name field a unique name should be entered.
37+
38+
* **Enabled** When unchecked the plugin is not enabled.
39+
2940
Sensor
3041
^^^^^^
3142

3243
See: :ref:`SerialHelper_page`
3344

45+
Device Settings
46+
^^^^^^^^^^^^^^^
47+
48+
* **TCP Port**: The port for an external network client to read the data from, range 1..65535. The used port number must be unique within the device.
3449

35-
**TODO**: Complete this documentation...
50+
* **Baud Rate / Serial config**: See *Serial helper configuration*, above.
3651

37-
.. Commands available
38-
.. ^^^^^^^^^^^^^^^^^^
52+
* **P1 #data event with message**: When enabled, the *P1 WiFi Gateway* Event Processing option will include the received message. **WARNING** This may easily cause memory overflow exceptions, especially when running on ESP8266 or other low-memory situations!
3953

40-
.. .. include:: P044_commands.repl
54+
* **Process events without client**: By default, if no network client is connected, no serial data will be received and processed either. Enabling this option enables receiving data and generating events without a TCP client connected.
4155

42-
.. Events
43-
.. ~~~~~~
56+
* **RX Receive timeout (mSec)**: If parts of serial data packets are somewhat delayed, but should still be handled as a single message, then the delay to wait for the next part can be configured here. 0 disables the delay.
57+
58+
* **Reset target after init**: Select a GPIO pin that should be pulled low once during initialization of the plugin, used to synchronize the external serial data source with the plugin.
59+
60+
Led
61+
^^^
62+
63+
* **Led enabled**: To enable a *data is being processed* activity led.
64+
65+
* **Led pin**: The GPIO pin the Led is connected to.
66+
67+
* **Led inverted**: Iverts the on/off state for the Led.
4468

45-
.. .. include:: P044_events.repl
4669

4770
Change log
4871
----------
4972

5073
.. versionchanged:: 2.0
5174
...
5275

76+
|changed| 2022-10-08: Merge of P020 and P044 to reduce code size and combine features, as P044 was initially started as a spin-off from P020, but not evolved with the P020 features.
77+
5378
|added|
5479
Major overhaul for 2.0 release.
5580

44.4 KB
Loading
Loading

docs/source/Reference/Command.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ P019 :ref:`P019_page`
249249
.. include:: ../Plugin/P019_commands.repl
250250

251251

252-
.. P020 :ref:`P020_page`
253-
.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
252+
P020 :ref:`P020_page`
253+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254254

255-
.. .. include:: ../Plugin/P020_commands.repl
255+
.. include:: ../Plugin/P020_commands.repl
256256

257257

258258
P021 :ref:`P021_page`

lib/ESPEasySerial/ESPEasySerialPort.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#include "ESPEasySerialPort.h"
22

3-
const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort port)
3+
const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort port, bool shortName)
44
{
55
switch (port) {
66
case ESPEasySerialPort::not_set: break;
77
#if USES_I2C_SC16IS752
8-
case ESPEasySerialPort::sc16is752: return F("I2C Serial");
8+
case ESPEasySerialPort::sc16is752: return shortName ? F("seriali2c") : F("I2C Serial");
99
#endif // if USES_I2C_SC16IS752
1010
#ifdef ESP8266
11-
case ESPEasySerialPort::serial0_swap: return F("HW Serial0 swap");
11+
case ESPEasySerialPort::serial0_swap: return shortName ? F("serial0swap") : F("HW Serial0 swap");
1212
#endif // ifdef ESP8266
13-
case ESPEasySerialPort::serial0: return F("HW Serial0");
13+
case ESPEasySerialPort::serial0: return shortName ? F("serial0") : F("HW Serial0");
1414
#if SOC_UART_NUM > 1
15-
case ESPEasySerialPort::serial1: return F("HW Serial1");
15+
case ESPEasySerialPort::serial1: return shortName ? F("serial1") : F("HW Serial1");
1616
#endif // if SOC_UART_NUM > 1
1717
#if SOC_UART_NUM > 2
18-
case ESPEasySerialPort::serial2: return F("HW Serial2");
18+
case ESPEasySerialPort::serial2: return shortName ? F("serial2") : F("HW Serial2");
1919
#endif // if SOC_UART_NUM > 2
2020
#if USES_SW_SERIAL
21-
case ESPEasySerialPort::software: return F("SW Serial");
21+
case ESPEasySerialPort::software: return shortName ? F("serialsw") : F("SW Serial");
2222
#endif // if USES_SW_SERIAL
2323
#if USES_HWCDC
24-
case ESPEasySerialPort::usb_hw_cdc: return F("USB HWCDC");
24+
case ESPEasySerialPort::usb_hw_cdc: return shortName ? F("serialhwcdc") : F("USB HWCDC");
2525
#endif // if USES_HWCDC
2626
#if USES_USBCDC
27-
case ESPEasySerialPort::usb_cdc_0: return F("USB CDC");
28-
// case ESPEasySerialPort::usb_cdc_1: return F("USB CDC1");
27+
case ESPEasySerialPort::usb_cdc_0: return shortName ? F("serialcdc") : F("USB CDC");
28+
29+
// case ESPEasySerialPort::usb_cdc_1: return F("USB CDC1");
2930
#endif // if USES_USBCDC
3031
case ESPEasySerialPort::MAX_SERIAL_TYPE: break;
3132

@@ -103,7 +104,7 @@ bool validSerialPort(ESPEasySerialPort port)
103104
#endif // if USES_HWCDC
104105
#if USES_USBCDC
105106
case ESPEasySerialPort::usb_cdc_0:
106-
// case ESPEasySerialPort::usb_cdc_1:
107+
// case ESPEasySerialPort::usb_cdc_1:
107108
#endif // if USES_USBCDC
108109
return true;
109110

lib/ESPEasySerial/ESPEasySerialPort.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum class ESPEasySerialPort : uint8_t {
3636
};
3737

3838

39-
const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort port);
39+
const __FlashStringHelper* ESPEasySerialPort_toString(ESPEasySerialPort port, bool shortName = false);
4040

4141
bool isHWserial(ESPEasySerialPort port);
4242

0 commit comments

Comments
 (0)