Skip to content

Commit 4858ec0

Browse files
committed
Allow receive or send using SerialBridge
1 parent a02e3aa commit 4858ec0

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
2222
- Matter filter suffix automatically added for sensors (#21589)
2323
- Display timing splash screen with display modes 1 to 5
2424
- ESP32 MI32 refactoring, bugfixes, generic device scanning (#21603)
25+
- Allow receive or send using SerialBridge
2526

2627
### Fixed
2728
- Berry `input()` returns empty string and does not crash (#21565)

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
132132
### Changed
133133
- Optional MQTT_TELE_RETAIN to Energy Margins message replaced by ``SensorRetain``
134134
- Display timing splash screen with display modes 1 to 5
135+
- Allow receive or send using SerialBridge
135136
- ESP32 Core3 platform update from 2024.05.13 to 2024.06.10 [#21569](https://github.com/arendst/Tasmota/issues/21569)
136137
- ESP32 MI32 refactoring, bugfixes, generic device scanning [#21603](https://github.com/arendst/Tasmota/issues/21603)
137138
- Matter refactoring of bridged devices [#21575](https://github.com/arendst/Tasmota/issues/21575)

tasmota/tasmota_xdrv_driver/xdrv_08_serial_bridge.ino

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
#ifdef USE_SERIAL_BRIDGE
2121
/*********************************************************************************************\
2222
* Serial Bridge using Software Serial library (TasmotaSerial)
23+
*
24+
* SBaudrate <baudrate> - Set baudrate
25+
* SBaudrate 9600
26+
* SSerialConfig <config> - Set serial config
27+
* SSerialConfig 8N1
28+
* SSerialBuffer <size> - Set serial receive buffer
29+
* SSerialSend "Hello Tiger" - Send "Hello Tiger\n"
30+
* SSerialSend - Set to text decoding
31+
* SSerialSend1 "Hello Tiger" - Send "Hello Tiger\n"
32+
* SSerialSend2 "Hello Tiger" - Send "Hello Tiger"
33+
* SSerialSend3 "Hello Tiger" - Send "Hello Tiger\f"
34+
* SSerialSend4 - Set to binary decoding
35+
* SSerialSend4 "Hello Tiger" - Send "Hello Tiger" and set to binary decoding
36+
* SSerialSend5 "AA004566" - Send "AA004566" as hex values
37+
* SSerialSend6 "72,101,108,108" - Send decimals as hex values
38+
* SerialDelimiter 255 - Receive data between 32 and 127 only
39+
* SerialDelimiter 254 - Receive hexadecimal data
40+
* SerialDelimiter 128 - Receive no data between 32 and 127
2341
\*********************************************************************************************/
2442

2543
#define XDRV_08 8
@@ -91,7 +109,7 @@ void SerialBridgeInput(void) {
91109
uint8_t serial_in_byte = SerialBridgeSerial->read();
92110

93111
#ifdef USE_SERIAL_BRIDGE_TEE
94-
if (Settings->sbflag1.serbridge_console) {
112+
if (Settings->sbflag1.serbridge_console) { // CMND_SSERIALSEND9 - Enable logging tee to serialbridge
95113
static bool serial_bridge_overrun = false;
96114

97115
if (isprint(serial_in_byte)) { // Any char between 32 and 127
@@ -117,7 +135,7 @@ void SerialBridgeInput(void) {
117135
}
118136
} else {
119137
#endif // USE_SERIAL_BRIDGE_TEE
120-
serial_bridge_raw = (254 == Settings->serial_delimiter);
138+
serial_bridge_raw = (254 == Settings->serial_delimiter); // SerialDelimiter
121139
if ((serial_in_byte > 127) && !serial_bridge_raw) { // Discard binary data above 127 if no raw reception allowed
122140
serial_bridge_in_byte_counter = 0;
123141
SerialBridgeSerial->flush();
@@ -147,17 +165,17 @@ void SerialBridgeInput(void) {
147165
}
148166

149167
#ifdef USE_SERIAL_BRIDGE_TEE
150-
if (Settings->sbflag1.serbridge_console) {
168+
if (Settings->sbflag1.serbridge_console) { // CMND_SSERIALSEND9 - Enable logging tee to serialbridge
151169
return;
152170
}
153171
#endif // USE_SERIAL_BRIDGE_TEE
154172

155173
if (serial_bridge_in_byte_counter && (millis() > (serial_bridge_polling_window + SERIAL_POLLING))) {
156-
serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // Serial data completed
174+
serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // Serial data completed
157175
bool assume_json = (!serial_bridge_raw && (serial_bridge_buffer[0] == '{'));
158176

159-
TasmotaGlobal.serial_skip++; // SetOption35 Skip number of serial messages received (default 0)
160-
if (TasmotaGlobal.serial_skip > Settings->param[P_SERIAL_SKIP]) { // Handle intermediate changes to SetOption35
177+
TasmotaGlobal.serial_skip++; // SetOption35 Skip number of serial messages received (default 0)
178+
if (TasmotaGlobal.serial_skip > Settings->param[P_SERIAL_SKIP]) { // Handle intermediate changes to SetOption35
161179
TasmotaGlobal.serial_skip = 0;
162180

163181
Response_P(PSTR("{\"" D_JSON_SSERIALRECEIVED "\":"));
@@ -188,7 +206,7 @@ void SerialBridgeInput(void) {
188206
/********************************************************************************************/
189207

190208
void SerialBridgeInit(void) {
191-
if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) {
209+
if (PinUsed(GPIO_SBR_RX) || PinUsed(GPIO_SBR_TX)) {
192210
// SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX), HARDWARE_FALLBACK); // Default TM_SERIAL_BUFFER_SIZE (=64) size
193211
SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX), HARDWARE_FALLBACK, 0, MIN_INPUT_BUFFER_SIZE); // 256
194212
if (SetSSerialBegin()) {

0 commit comments

Comments
 (0)