From dd4f16526e23bab43bbc69ed32b346ac66ca9965 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Tue, 23 Mar 2021 12:57:56 +0100
Subject: [PATCH] Fix sensor coexistence
---
tasmota/i18n.h | 1 +
tasmota/support_features.ino | 17 +++++++----
tasmota/xsns_22_sr04.ino | 7 +----
tasmota/xsns_86_tfminiplus.ino | 53 +++++++++++++++-------------------
tools/decode-status.py | 8 +++--
5 files changed, 42 insertions(+), 44 deletions(-)
diff --git a/tasmota/i18n.h b/tasmota/i18n.h
index 13f2c494e..dcdd08445 100644
--- a/tasmota/i18n.h
+++ b/tasmota/i18n.h
@@ -826,6 +826,7 @@ const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{
const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d " D_UNIT_PERCENT "{e}";
const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d" "{e}";
const char HTTP_SNS_DISTANCE[] PROGMEM = "{s}%s " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}";
+const char HTTP_SNS_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%s " D_UNIT_CENTIMETER "{e}";
const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}";
const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}";
const char HTTP_SNS_POWER[] PROGMEM = "{s}" D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}";
diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino
index 04acd2e07..cdc864483 100644
--- a/tasmota/support_features.ino
+++ b/tasmota/support_features.ino
@@ -725,11 +725,18 @@ void ResponseAppendFeatures(void)
static uint32_t feature8 = 0x00000000;
if (!feature8) { // Only fill this once
-// feature8 |= 0x00000001;
-// feature8 |= 0x00000002;
-// feature8 |= 0x00000004;
-// feature8 |= 0x00000008;
-
+#if defined(USE_I2C) && defined(USE_MPU6886)
+ feature8 |= 0x00000001; // xsns_85_mpu6886.ino
+#endif
+#ifdef USE_TFMINIPLUS
+ feature8 |= 0x00000002; // xsns_86_tfminiplus.ino
+#endif
+#if defined(USE_ENERGY_SENSOR) && defined(USE_CSE7761)
+ feature8 |= 0x00000004; // xnrg_19_cse7761.ino
+#endif
+#ifdef USE_BERRY
+ feature8 |= 0x00000008; // xdrv_52_9_berry.ino
+#endif
// feature8 |= 0x00000010;
// feature8 |= 0x00000020;
// feature8 |= 0x00000040;
diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino
index 29876dce4..fb927aec5 100644
--- a/tasmota/xsns_22_sr04.ino
+++ b/tasmota/xsns_22_sr04.ino
@@ -159,11 +159,6 @@ void Sr04TReading(void) {
return;
}
-#ifdef USE_WEBSERVER
-const char HTTP_SNS_DISTANCE_CM[] PROGMEM =
- "{s}SR04 " D_DISTANCE "{m}%s" D_UNIT_CENTIMETER "{e}"; // {s} =
, {m} = | , {e} = |
-#endif // USE_WEBSERVER
-
void Sr04Show(bool json)
{
@@ -180,7 +175,7 @@ void Sr04Show(bool json)
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
- WSContentSend_PD(HTTP_SNS_DISTANCE_CM, distance_chr);
+ WSContentSend_PD(HTTP_SNS_DISTANCE_CM, "SR04", distance_chr);
#endif // USE_WEBSERVER
}
}
diff --git a/tasmota/xsns_86_tfminiplus.ino b/tasmota/xsns_86_tfminiplus.ino
index 341f097a0..703817f79 100644
--- a/tasmota/xsns_86_tfminiplus.ino
+++ b/tasmota/xsns_86_tfminiplus.ino
@@ -1,8 +1,6 @@
/*
xsns_86_tfminiplus.ino - TFmini Plus interface for Tasmota
- Created by Raphael Breiting on 12.11.2020.
-
Copyright (C) 2021 Raphael Breiting and Theo Arends
This program is free software: you can redistribute it and/or modify
@@ -19,23 +17,21 @@
along with this program. If not, see .
*/
-// Conditional compilation of driver
#ifdef USE_TFMINIPLUS
-
/*****************************************************************************\
* TFmini, TFmini Plus, TFmini Plus (Indoor Version), TFmini-S - LiDAR Module
* Manufacturer: Benewake (Beijing) Co. Ltd.
*
* Code for Time-Of-Flight (TOF) family single-point short-range LiDAR sensor
* modules with UART interface.
- *
+ *
* Connection Description for GH1.25-4P (Molex51021-0400) connector:
* No Color Corresponding PIN Function Comment
* 1 RED PIN-1 +5V Power Supply
* 2 WHITE PIN-2 RxD/SDA Receiving/Data
* 3 GREEN PIN-3 TxD/SCL Transmitting/Clock
* 4 BLACK PIN-4 GND Ground
- *
+ *
* Before connecting module to Tasmota, please prepare module with
* the following sequence through terminal program (e.g. Termite):
* 1. Connect sensor to USB-to-UART (TTL 3.3V)
@@ -54,33 +50,27 @@
* 7. When point 6 returned OK, than ready to connect to Tasmota! :)
* When point 6 returned FAIL, start with item 1 and
* - check connection of RX and TX pin are not exchanged
- * - check power supply
+ * - check power supply
* - 5V +-0,5V
* - 110mA average
* - 140mA max peak
- *
+ *
* References:
* - http://en.benewake.com/product
* - https://de.aliexpress.com/item/32852024277.html?spm=a2g0s.9042311.0.0.27424c4d5Edizk
* - https://de.aliexpress.com/item/4001076614996.html?spm=a2g0s.9042311.0.0.27424c4d5Edizk
\*****************************************************************************/
-#include
-
-// Define driver ID
#define XSNS_86 86
-// Use special no wait serial driver, should be always on
-#ifndef ESP32
-#define SPECIAL_SS
-#endif
-
// Default baudrate
-#define BAUDRATE 9600
+#define TFMP_SPEED 9600
// Serial buffer length for incoming data
#define TFMP_MAX_DATA_LEN 9
+#include
+
char Tfmp_buffer[TFMP_MAX_DATA_LEN + 1];
struct xsns_86_tfminiplus
@@ -101,7 +91,7 @@ void TfmpInit(void)
if (PinUsed(GPIO_TFMINIPLUS_RX) && PinUsed(GPIO_TFMINIPLUS_TX))
{
TfmpSerial = new TasmotaSerial(Pin(GPIO_TFMINIPLUS_RX), Pin(GPIO_TFMINIPLUS_TX), 1);
- if (TfmpSerial->begin(BAUDRATE))
+ if (TfmpSerial->begin(TFMP_SPEED))
{
if (TfmpSerial->hardwareSerial())
{
@@ -155,7 +145,7 @@ void TfmpProcessSerialData (void)
bool dataReady;
if (TfmpSerial && tfminiplus_sensor.ready)
{
- while (TfmpSerial->available() > 0)
+ while (TfmpSerial->available() > 0)
{
data = TfmpSerial->read();
dataReady = TfmpAddData((char)data);
@@ -168,7 +158,7 @@ void TfmpProcessSerialData (void)
}
bool TfmpAddData(char nextChar)
-{
+{
// Buffer position
static uint8_t currentIndex = 0;
// Store data into buffer at position
@@ -187,27 +177,30 @@ bool TfmpAddData(char nextChar)
#ifdef USE_WEBSERVER
// {s} = , {m} = | , {e} = |
-const char HTTP_SNS_DISTANCE_CM[] PROGMEM = "{s} " D_DISTANCE "{m}%d" D_UNIT_CENTIMETER "{e}";
-const char HTTP_SNS_SIGNALSTRENGTH[] PROGMEM = "{s} " D_SIGNALSTRENGTH "{m}%d{e}";
-const char HTTP_SNS_CHIPTEMPERATURE[] PROGMEM = "{s} " D_CHIPTEMPERATURE "{m}%d" D_UNIT_DEGREE D_UNIT_CELSIUS "{e}";
+const char HTTP_SNS_SIGNALSTRENGTH[] PROGMEM = "{s}%s " D_SIGNALSTRENGTH "{m}%d{e}";
+const char HTTP_SNS_CHIPTEMPERATURE[] PROGMEM = "{s}%s " D_CHIPTEMPERATURE "{m}%d " D_UNIT_DEGREE "%c{e}";
#endif // USE_WEBSERVER
void TfmpShow(bool json)
{
+ char sensor_name[12];
+ strcpy_P(sensor_name, "TFminiPlus");
+ char distance_chr[FLOATSZ];
+ dtostrfd(tfminiplus_sensor.distance, 3, distance_chr);
+
if (json) {
- ResponseAppend_P(PSTR(",\"TFmini Plus\":{\"" D_JSON_DISTANCE "\":\"%d\",\"" D_JSON_SIGNALSTRENGTH "\":\"%d\",\"" D_JSON_CHIPTEMPERATURE "\":%d}"),
- tfminiplus_sensor.distance, tfminiplus_sensor.sigstrength, tfminiplus_sensor.chiptemp);
+ ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":\"%s\",\"" D_JSON_SIGNALSTRENGTH "\":\"%d\",\"" D_JSON_CHIPTEMPERATURE "\":%d}"),
+ sensor_name, distance_chr, tfminiplus_sensor.sigstrength, tfminiplus_sensor.chiptemp);
#ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) {
- DomoticzFloatSensor(DZ_COUNT, tfminiplus_sensor.distance);
+ DomoticzSensor(DZ_COUNT, distance_chr);
}
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
- WSContentSend_P("{s}TFmini Plus");
- WSContentSend_P(HTTP_SNS_DISTANCE_CM, tfminiplus_sensor.distance);
- WSContentSend_P(HTTP_SNS_SIGNALSTRENGTH, tfminiplus_sensor.sigstrength);
- WSContentSend_P(HTTP_SNS_CHIPTEMPERATURE, tfminiplus_sensor.chiptemp);
+ WSContentSend_P(HTTP_SNS_DISTANCE_CM, sensor_name, distance_chr);
+ WSContentSend_P(HTTP_SNS_SIGNALSTRENGTH, sensor_name, tfminiplus_sensor.sigstrength);
+ WSContentSend_P(HTTP_SNS_CHIPTEMPERATURE, sensor_name, tfminiplus_sensor.chiptemp, TempUnit());
#endif // USE_WEBSERVER
}
}
diff --git a/tools/decode-status.py b/tools/decode-status.py
index 3f91107e2..249c8f8a9 100755
--- a/tools/decode-status.py
+++ b/tools/decode-status.py
@@ -177,7 +177,9 @@ a_setoption = [[
"(Zigbee) Append endpoint number to topic if device dependent (use with SetOption89)",
"(MQTT) Retain on State",
"(MQTT) Retain on Info",
- "","","",
+ "(Wiegand) switch tag number output to hex format (1)",
+ "(Wiegand) send key pad stroke as single char (0) or one tag (ending char #) (1)",
+ "(Zigbee) Hide bridge topic from zigbee topic (use with SetOption89) (1)",
"","","","",
"","","","",
"","","","",
@@ -249,7 +251,7 @@ a_features = [[
"USE_BS814A2","USE_SEESAW_SOIL","USE_WIEGAND","USE_NEOPOOL",
"USE_TOF10120","USE_SDM72","USE_DISPLAY_TM1637","USE_PROJECTOR_CTRL"
],[
- "USE_TFMINIPLUS","","","",
+ "USE_MPU6886","USE_TFMINIPLUS","USE_CSE7761","USE_BERRY",
"","","","",
"","","","",
"","","","",
@@ -284,7 +286,7 @@ else:
obj = json.load(fp)
def StartDecode():
- print ("\n*** decode-status.py v20210222 by Theo Arends and Jacek Ziolkowski ***")
+ print ("\n*** decode-status.py v20210323 by Theo Arends and Jacek Ziolkowski ***")
# print("Decoding\n{}".format(obj))