Skip to content

Commit

Permalink
Fix sensor coexistence
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Mar 23, 2021
1 parent 0e40de5 commit dd4f165
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 44 deletions.
1 change: 1 addition & 0 deletions tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
17 changes: 12 additions & 5 deletions tasmota/support_features.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions tasmota/xsns_22_sr04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER

void Sr04Show(bool json)
{

Expand All @@ -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
}
}
Expand Down
53 changes: 23 additions & 30 deletions tasmota/xsns_86_tfminiplus.ino
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,23 +17,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// 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)
Expand All @@ -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 <TasmotaSerial.h>

// 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 <TasmotaSerial.h>

char Tfmp_buffer[TFMP_MAX_DATA_LEN + 1];

struct xsns_86_tfminiplus
Expand All @@ -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())
{
Expand Down Expand Up @@ -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);
Expand All @@ -168,7 +158,7 @@ void TfmpProcessSerialData (void)
}

bool TfmpAddData(char nextChar)
{
{
// Buffer position
static uint8_t currentIndex = 0;
// Store data into buffer at position
Expand All @@ -187,27 +177,30 @@ bool TfmpAddData(char nextChar)

#ifdef USE_WEBSERVER
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
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
}
}
Expand Down
8 changes: 5 additions & 3 deletions tools/decode-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@
"(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)",
"","","","",
"","","","",
"","","","",
Expand Down Expand Up @@ -249,7 +251,7 @@
"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",
"","","","",
"","","","",
"","","","",
Expand Down Expand Up @@ -284,7 +286,7 @@
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))

Expand Down

0 comments on commit dd4f165

Please sign in to comment.