Skip to content

Commit

Permalink
v5.12.0h - Add Serial Bridges
Browse files Browse the repository at this point in the history
5.12.0h
 * Add support for Software Serial bridge using commands
SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only
(#2190)
 * Add support for Hardware Serial bridge using commands
SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only
(#2182)
  • Loading branch information
arendst committed Mar 20, 2018
1 parent d3ef9ca commit 2ba4d6f
Show file tree
Hide file tree
Showing 32 changed files with 307 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **5.12.0g** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.12.0h** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.

### ATTENTION All versions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TasmotaSerial

Implementation of software serial library for the ESP8266 at 9600 baud
Implementation of software serial library for the ESP8266

Allows for several instances to be active at the same time.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "TasmotaSerial",
"version": "1.0.0",
"version": "1.2.0",
"keywords": [
"serial", "io", "TasmotaSerial"
],
"description": "Implementation of software serial for ESP8266 at 9600 baud.",
"description": "Implementation of software serial for ESP8266.",
"repository":
{
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=TasmotaSerial
version=1.0
version=1.2.0
author=Theo Arends
maintainer=Theo Arends <[email protected]>
sentence=Implementation of software serial for ESP8266 at 9600 baud.
sentence=Implementation of software serial for ESP8266.
paragraph=
category=Signal Input/Output
url=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin)
m_in_pos = m_out_pos = 0;
if (m_rx_pin > -1) {
m_buffer = (uint8_t*)malloc(TM_SERIAL_BUFFER_SIZE);
if (m_buffer == NULL) {
return;
}
if (m_buffer == NULL) return;
// Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() *1000000 /TM_SERIAL_BAUDRATE;
pinMode(m_rx_pin, INPUT);
Expand All @@ -111,7 +109,8 @@ bool TasmotaSerial::isValidGPIOpin(int pin)
bool TasmotaSerial::begin(long speed) {
// Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() *1000000 /speed;
return m_valid && (speed <= TM_SERIAL_BAUDRATE);
m_high_speed = (speed > 9600);
return m_valid;
}

bool TasmotaSerial::begin() {
Expand All @@ -123,17 +122,13 @@ void TasmotaSerial::flush() {
}

int TasmotaSerial::peek() {
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) {
return -1;
}
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1;
return m_buffer[m_out_pos];
}

int TasmotaSerial::read()
{
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) {
return -1;
}
if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1;
uint8_t ch = m_buffer[m_out_pos];
m_out_pos = (m_out_pos +1) % TM_SERIAL_BUFFER_SIZE;
return ch;
Expand All @@ -142,23 +137,20 @@ int TasmotaSerial::read()
int TasmotaSerial::available()
{
int avail = m_in_pos - m_out_pos;
if (avail < 0) {
avail += TM_SERIAL_BUFFER_SIZE;
}
if (avail < 0) avail += TM_SERIAL_BUFFER_SIZE;
return avail;
}

#ifdef TM_SERIAL_USE_IRAM
#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts
#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait) if (!m_high_speed) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts
#else
#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bit_time; }
#endif

size_t TasmotaSerial::write(uint8_t b)
{
if (-1 == m_tx_pin) {
return 0;
}
if (-1 == m_tx_pin) return 0;
if (m_high_speed) cli(); // Disable interrupts in order to get a clean transmit
unsigned long wait = m_bit_time;
digitalWrite(m_tx_pin, HIGH);
unsigned long start = ESP.getCycleCount();
Expand All @@ -173,6 +165,7 @@ size_t TasmotaSerial::write(uint8_t b)
// Stop bit
digitalWrite(m_tx_pin, HIGH);
TM_SERIAL_WAIT;
if (m_high_speed) sei();
return 1;
}

Expand All @@ -191,9 +184,7 @@ void TasmotaSerial::rxRead()
for (int i = 0; i < 8; i++) {
TM_SERIAL_WAIT;
rec >>= 1;
if (digitalRead(m_rx_pin)) {
rec |= 0x80;
}
if (digitalRead(m_rx_pin)) rec |= 0x80;
}
// Stop bit
TM_SERIAL_WAIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#ifndef TasmotaSerial_h
#define TasmotaSerial_h
/*********************************************************************************************\
* TasmotaSerial supports up to 9600 baud with fixed buffer size of 64 bytes using optional no iram
* TasmotaSerial supports up to 115200 baud with fixed buffer size of 64 bytes using optional no iram
*
* Based on EspSoftwareSerial v3.3.1 by Peter Lerup (https://github.com/plerup/espsoftwareserial)
\*********************************************************************************************/

#define TM_SERIAL_BAUDRATE 9600 // Max supported baudrate
#define TM_SERIAL_BAUDRATE 9600 // Default baudrate
#define TM_SERIAL_BUFFER_SIZE 64 // Receive buffer size

#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
Expand Down Expand Up @@ -57,6 +57,7 @@ class TasmotaSerial : public Stream {

// Member variables
bool m_valid;
bool m_high_speed;
int m_rx_pin;
int m_tx_pin;
unsigned long m_bit_time;
Expand Down
5 changes: 3 additions & 2 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* 5.12.0g
* Add support for MQTT to hardware serial bridge using commands Baudrate and SerialSend. Currently supports 8N1 and text only (#2182)
/* 5.12.0h
* Add support for Software Serial bridge using commands SerialDelimiter, SBaudrate and SSerialSend. Supports 8N1 and text only (#2190)
* Add support for Hardware Serial bridge using commands SerialDelimiter, Baudrate and SerialSend. Supports 8N1 and text only (#2182)
*
* 5.12.0f
* Add compile time support for WS2812 BRG and RBG led configurations to be defined in user_config.h (#1690)
Expand Down
6 changes: 6 additions & 0 deletions sonoff/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
#define D_CMND_CFGDUMP "CfgDump"
#define D_CMND_I2CSCAN "I2CScan"
#define D_CMND_SERIALSEND "SerialSend"
#define D_CMND_SERIALDELIMITER "SerialDelimiter"
#define D_CMND_BAUDRATE "Baudrate"
#define D_CMND_EXCEPTION "Exception"

Expand Down Expand Up @@ -340,6 +341,11 @@
#define D_CMND_DISP_SIZE "Size"
#define D_CMND_DISP_TEXT "Text"

// Commands xdrv_08_serial_bridge.ino
#define D_CMND_SSERIALSEND "SSerialSend"
#define D_CMND_SBAUDRATE "SBaudrate"
#define D_JSON_SSERIALRECEIVED "SSerialReceived"

/********************************************************************************************/

#ifndef MY_LANGUAGE
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/es-AR.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "Háttérvil"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/pt-PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "Luz negra"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/ru-RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "А"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "安"
Expand Down
2 changes: 2 additions & 0 deletions sonoff/language/zh-TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
#define D_SENSOR_BACKLIGHT "BkLight"
#define D_SENSOR_PMS5003 "PMS5003"
#define D_SENSOR_SDS0X1 "SDS0X1"
#define D_SENSOR_SBR_RX "SerBr Rx"
#define D_SENSOR_SBR_TX "SerBr Tx"

// Units
#define D_UNIT_AMPERE "安"
Expand Down
5 changes: 2 additions & 3 deletions sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ struct SYSCFG {
uint16_t ws_wakeup; // 3AA Not used since 5.8.0
char friendlyname[MAX_FRIENDLYNAMES][33]; // 3AC
char switch_topic[33]; // 430

byte free_451[2]; // 451

char serial_delimiter; // 451
uint8_t sbaudrate; // 452
uint8_t sleep; // 453
uint16_t domoticz_switch_idx[MAX_DOMOTICZ_IDX]; // 454
uint16_t domoticz_sensor_idx[MAX_DOMOTICZ_SNS_IDX]; // 45C
Expand Down
6 changes: 6 additions & 0 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ void SettingsDefaultSet2()
Settings.timezone = APP_TIMEZONE;
strlcpy(Settings.ota_url, OTA_URL, sizeof(Settings.ota_url));
Settings.baudrate = APP_BAUDRATE / 1200;
Settings.sbaudrate = SOFT_BAUDRATE / 1200;
Settings.serial_delimiter = 0xff;

Settings.seriallog_level = SERIAL_LOG_LEVEL;
// Settings.sta_active = 0;
Expand Down Expand Up @@ -903,6 +905,10 @@ void SettingsDelta()
if (Settings.version < 0x050C0007) {
Settings.baudrate = APP_BAUDRATE / 1200;
}
if (Settings.version < 0x050C0008) {
Settings.sbaudrate = SOFT_BAUDRATE / 1200;
Settings.serial_delimiter = 0xff;
}

Settings.version = VERSION;
SettingsSave(1);
Expand Down
1 change: 1 addition & 0 deletions sonoff/sonoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ typedef unsigned long power_t; // Power (Relay) type
#define MAX_BACKLOG 16 // Max number of commands in backlog (chk backlog_index and backlog_pointer code)
#define MIN_BACKLOG_DELAY 2 // Minimal backlog delay in 0.1 seconds

#define SOFT_BAUDRATE 9600 // Default software serial baudrate
#define APP_BAUDRATE 115200 // Default serial baudrate
#define SERIAL_POLLING 100 // Serial receive polling in ms
#define MAX_STATUS 11 // Max number of status lines
Expand Down
Loading

0 comments on commit 2ba4d6f

Please sign in to comment.