Skip to content

Commit

Permalink
6.2.1.17 Changes and Adds
Browse files Browse the repository at this point in the history
6.2.1.17 20181017
 * Enable updated non-blocking PubSubClient as default MQTT client
 * Update TasmotaModbus and TasmotaSerial libraries for support of serial 8N2 communication
 * Add support for Pzem-003/017 DC Energy monitoring module (#3694)
 * Change support for Pzem-014/016 AC Energy monitoring module (#3694)
  • Loading branch information
arendst committed Oct 17, 2018
1 parent b2ca987 commit 0ab4390
Show file tree
Hide file tree
Showing 45 changed files with 446 additions and 254 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TasmotaModbus",
"version": "1.0.0",
"version": "1.1.0",
"keywords": [
"serial", "io", "TasmotaModbus"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TasmotaModbus
version=1.0.0
version=1.1.0
author=Theo Arends
maintainer=Theo Arends <[email protected]>
sentence=Basic modbus wrapper for TasmotaSerial for ESP8266.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin) : TasmotaSerial(receive_pin, transmit_pin, 1)
{
}

TasmotaModbus::~TasmotaModbus()
{
mb_address = 0;
}

uint16_t CalculateCRC(uint8_t *frame, uint8_t num)
Expand All @@ -46,11 +43,11 @@ uint16_t CalculateCRC(uint8_t *frame, uint8_t num)
return crc;
}

int TasmotaModbus::Begin(long speed)
int TasmotaModbus::Begin(long speed, int stop_bits)
{
int result = 0;

if (begin(speed)) {
if (begin(speed, stop_bits)) {
result = 1;
if (hardwareSerial()) { result = 2; }
}
Expand All @@ -61,7 +58,9 @@ void TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint16_t
{
uint8_t frame[8];

frame[0] = device_address; // 0xFE default device address or dedicated like 0x01
mb_address = device_address; // Save address for receipt check

frame[0] = mb_address; // 0xFE default device address or dedicated like 0x01
frame[1] = function_code;
frame[2] = (uint8_t)(start_address >> 8);
frame[3] = (uint8_t)(start_address);
Expand All @@ -85,10 +84,17 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count)
uint8_t len = 0;
uint32_t last = millis();
while ((available() > 0) && (len < (register_count *2) + 5) && (millis() - last < 10)) {
buffer[len++] = (uint8_t)read();
if (3 == len) {
if (buffer[1] & 0x80) { // fe 84 02 f2 f1
return buffer[2]; // 1 = Illegal Function, 2 = Illegal Address, 3 = Illegal Data, 4 = Slave Error
uint8_t data = (uint8_t)read();
if (!len) { // Skip leading data as provided by hardware serial
if (mb_address == data) {
buffer[len++] = data;
}
} else {
buffer[len++] = data;
if (3 == len) {
if (buffer[1] & 0x80) { // 01 84 02 f2 f1
return buffer[2]; // 1 = Illegal Function, 2 = Illegal Address, 3 = Illegal Data, 4 = Slave Error
}
}
}
last = millis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
class TasmotaModbus : public TasmotaSerial {
public:
TasmotaModbus(int receive_pin, int transmit_pin);
~TasmotaModbus();
virtual ~TasmotaModbus() {}

int Begin(long speed = TM_MODBUS_BAUDRATE);
int Begin(long speed = TM_MODBUS_BAUDRATE, int stop_bits = 1);

void Send(uint8_t device_address, uint8_t function_code, uint16_t start_address, uint16_t register_count);

Expand All @@ -49,6 +49,9 @@ class TasmotaModbus : public TasmotaSerial {
uint8_t ReceiveBuffer(uint8_t *buffer, uint8_t register_count);
uint8_t Receive16BitRegister(uint16_t *value);
uint8_t Receive32BitRegister(float *value);

private:
uint8_t mb_address;
};

#endif // TasmotaModbus_h
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TasmotaSerial",
"version": "2.0.0",
"version": "2.1.0",
"keywords": [
"serial", "io", "TasmotaSerial"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TasmotaSerial
version=2.0.0
version=2.1.0
author=Theo Arends
maintainer=Theo Arends <[email protected]>
sentence=Implementation of software serial with hardware serial fallback for ESP8266.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, bool hardware_fa
{
m_valid = false;
m_hardserial = 0;
m_stop_bits = 1;
if (!((isValidGPIOpin(receive_pin)) && (isValidGPIOpin(transmit_pin) || transmit_pin == 16))) {
return;
}
Expand All @@ -106,15 +107,33 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, bool hardware_fa
m_valid = true;
}

TasmotaSerial::~TasmotaSerial()
{
if (!m_hardserial) {
if (m_rx_pin > -1) {
detachInterrupt(m_rx_pin);
tms_obj_list[m_rx_pin] = NULL;
if (m_buffer) {
free(m_buffer);
}
}
}
}

bool TasmotaSerial::isValidGPIOpin(int pin)
{
return (pin >= -1 && pin <= 5) || (pin >= 12 && pin <= 15);
}

bool TasmotaSerial::begin(long speed) {
bool TasmotaSerial::begin(long speed, int stop_bits) {
m_stop_bits = ((stop_bits -1) &1) +1;
if (m_hardserial) {
Serial.flush();
Serial.begin(speed, SERIAL_8N1);
if (2 == m_stop_bits) {
Serial.begin(speed, SERIAL_8N2);
} else {
Serial.begin(speed, SERIAL_8N1);
}
} else {
// Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() *1000000 /speed;
Expand Down Expand Up @@ -195,9 +214,11 @@ size_t TasmotaSerial::write(uint8_t b)
TM_SERIAL_WAIT;
b >>= 1;
}
// Stop bit
digitalWrite(m_tx_pin, HIGH);
TM_SERIAL_WAIT;
// Stop bit(s)
for (int i = 0; i < m_stop_bits; i++) {
digitalWrite(m_tx_pin, HIGH);
TM_SERIAL_WAIT;
}
if (m_high_speed) sei();
return 1;
}
Expand All @@ -220,8 +241,12 @@ void TasmotaSerial::rxRead()
rec >>= 1;
if (digitalRead(m_rx_pin)) rec |= 0x80;
}
// Stop bit
// Stop bit(s)
TM_SERIAL_WAIT;
if (2 == m_stop_bits) {
digitalRead(m_rx_pin);
TM_SERIAL_WAIT;
}
// Store the received value in the buffer unless we have an overflow
int next = (m_in_pos+1) % TM_SERIAL_BUFFER_SIZE;
if (next != (int)m_out_pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
#define TM_SERIAL_USE_IRAM // Enable to use iram (+368 bytes)
#endif

#include <inttypes.h>
#include <Stream.h>

class TasmotaSerial : public Stream {
public:
TasmotaSerial(int receive_pin, int transmit_pin, bool hardware_fallback = false);
bool begin(long speed);
virtual ~TasmotaSerial();

bool begin(long speed, int stop_bits = 1);
bool begin();
bool hardwareSerial();
int peek();
Expand All @@ -62,6 +65,7 @@ class TasmotaSerial : public Stream {
bool m_high_speed;
int m_rx_pin;
int m_tx_pin;
int m_stop_bits;
unsigned long m_bit_time;
unsigned int m_in_pos;
unsigned int m_out_pos;
Expand Down
8 changes: 7 additions & 1 deletion sonoff/_changelog.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* 6.2.1.16 20181015
/* 6.2.1.17 20181017
* Enable updated non-blocking PubSubClient as default MQTT client
* Update TasmotaModbus and TasmotaSerial libraries for support of serial 8N2 communication
* Add support for Pzem-003/017 DC Energy monitoring module (#3694)
* Change support for Pzem-014/016 AC Energy monitoring module (#3694)
*
* 6.2.1.16 20181015
* Add TasmotaModbus library for very basic modbus wrapper for TasmotaSerial
* Change xsns_17_senseair.ino to use TasmotaModbus library
* Fix xnrg_05_pzem2.ino for PZEM-014/016 support using TasmotaModbus library (#3694)
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/bg-BG.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRRecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/el-GR.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/es-AR.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IR RX"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "RécptIR"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/he-HE.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRvevő"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHZ Rx"
#define D_SENSOR_MHZ_TX "MHZ Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAir Rx"
#define D_SENSOR_SAIR_TX "SAir Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
6 changes: 4 additions & 2 deletions sonoff/language/pt-BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,10 @@
#define D_SENSOR_IRRECV "IRrecv"
#define D_SENSOR_MHZ_RX "MHz Rx"
#define D_SENSOR_MHZ_TX "MHz Tx"
#define D_SENSOR_PZEM_RX "PZEM Rx"
#define D_SENSOR_PZEM_TX "PZEM Tx"
#define D_SENSOR_PZEM004_RX "PZEM004 Rx"
#define D_SENSOR_PZEM016_RX "PZEM016 Rx"
#define D_SENSOR_PZEM017_RX "PZEM017 Rx"
#define D_SENSOR_PZEM0XX_TX "PZEM0XX Tx"
#define D_SENSOR_SAIR_RX "SAIR Rx"
#define D_SENSOR_SAIR_TX "SAIR Tx"
#define D_SENSOR_SPI_CS "SPI CS"
Expand Down
Loading

0 comments on commit 0ab4390

Please sign in to comment.