mirror of https://github.com/arendst/Tasmota.git
Merge remote-tracking branch 'upstream/development' into pms3003
This commit is contained in:
commit
871f4740c6
|
@ -9,6 +9,7 @@
|
|||
* Add rule support after every command execution like Fanspeed#Data=2 (#6636)
|
||||
* Fix handling of ligth channels when pwm_multichannel (Option68) is enabled
|
||||
* Add WebUI for multiple, independent PWM channels
|
||||
* Remove default DS18B20 driver and only support define DS18x20 (#6647)
|
||||
*
|
||||
* 6.6.0.17 20191009
|
||||
* Add command SetOption34 0..255 to set backlog delay. Default value is 200 (mSeconds) (#6562)
|
||||
|
|
|
@ -338,7 +338,7 @@
|
|||
//#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices
|
||||
|
||||
// -- One wire sensors ----------------------------
|
||||
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
#define USE_DS18x20 // Add support for DS18x20 sensors with id sort, single scan and read retry (+2k6 code)
|
||||
// #define W1_PARASITE_POWER // Optimize for parasite powered sensors
|
||||
// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistor
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
|
||||
#define USE_COUNTER // Enable counters
|
||||
#undef USE_ADC_VCC // Add Analog input on selected devices
|
||||
#define USE_DS18x20 // For more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
#define USE_DS18x20 // Add support for DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
|
||||
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)
|
||||
#define USE_SHT // Add I2C emulating code for SHT1X sensor (+1k4 code)
|
||||
|
@ -365,7 +365,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#undef USE_TUYA_MCU // Disable support for Tuya Serial MCU
|
||||
#undef USE_ARMTRONIX_DIMMERS // Disable support for Armtronix Dimmers (+1k4 code)
|
||||
#undef USE_PS_16_DZ // Disable support for PS-16-DZ Dimmer and Sonoff L1 (+2k code)
|
||||
#undef USE_DS18x20 // Disable Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
#undef USE_DS18x20 // Disable support for DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
|
||||
#undef USE_I2C // Disable all I2C sensors
|
||||
#undef USE_SPI // Disable all SPI devices
|
||||
|
@ -415,15 +415,6 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
|
||||
#endif // FIRMWARE_IR
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Mandatory define for DS18x20 if changed by above image selections
|
||||
\*********************************************************************************************/
|
||||
|
||||
#if defined(USE_DS18x20)
|
||||
#else
|
||||
#define USE_DS18B20 // Default DS18B20 sensor needs no external library
|
||||
#endif
|
||||
|
||||
/*********************************************************************************************\
|
||||
* [sonoff-basic.bin]
|
||||
* Provide an image without sensors
|
||||
|
@ -465,7 +456,6 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
|
||||
#undef USE_COUNTER // Disable counters
|
||||
#undef USE_DS18x20 // Disable DS18x20 sensor
|
||||
#undef USE_DS18B20 // Disable internal DS18B20 sensor
|
||||
#undef USE_I2C // Disable all I2C sensors and devices
|
||||
#undef USE_SPI // Disable all SPI devices
|
||||
#undef USE_DISPLAY // Disable Display support
|
||||
|
@ -550,7 +540,6 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
|
||||
#undef USE_COUNTER // Disable counters
|
||||
#undef USE_DS18x20 // Disable DS18x20 sensor
|
||||
#undef USE_DS18B20 // Disable internal DS18B20 sensor
|
||||
#undef USE_I2C // Disable all I2C sensors and devices
|
||||
#undef USE_SPI // Disable all SPI devices
|
||||
#undef USE_DISPLAY // Disable Display support
|
||||
|
@ -638,9 +627,8 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
|
|||
#endif
|
||||
|
||||
#ifndef MESSZ
|
||||
//#define MESSZ 405 // Max number of characters in JSON message string (6 x DS18x20 sensors)
|
||||
//#define MESSZ 893 // Max number of characters in JSON message string (Hass discovery and nice MQTT_MAX_PACKET_SIZE = 1000)
|
||||
#define MESSZ (MQTT_MAX_PACKET_SIZE -TOPSZ -7) // Max number of characters in JSON message string (6 x DS18x20 sensors)
|
||||
#define MESSZ (MQTT_MAX_PACKET_SIZE -TOPSZ -7) // Max number of characters in JSON message string
|
||||
#endif
|
||||
|
||||
//#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
|
||||
|
|
|
@ -543,7 +543,7 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
|||
GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321
|
||||
GPIO_SI7021, // iTead SI7021
|
||||
#endif
|
||||
#if defined(USE_DS18B20) || defined(USE_DS18x20)
|
||||
#ifdef USE_DS18x20
|
||||
GPIO_DSB, // Single wire DS18B20 or DS18S20
|
||||
#endif
|
||||
|
||||
|
@ -1363,7 +1363,11 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
|
|||
// http://www.wykop.pl/ramka/3325399/diy-supla-do-puszki-instalacyjnej-podtynkowej-supla-org/
|
||||
0, // GPIO00 Flash jumper
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
#ifdef USE_DS18x20
|
||||
GPIO_DSB, // GPIO02 DS18B20 sensor
|
||||
#else
|
||||
GPIO_USER, // GPIO02 Optional sensor
|
||||
#endif
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
GPIO_KEY1, // GPIO04 Button 1
|
||||
GPIO_REL1, // GPIO05 Relay 1 (0 = Off, 1 = On)
|
||||
|
|
|
@ -240,10 +240,10 @@ void GetFeatures(void)
|
|||
feature_sns1 |= 0x00000008; // xnrg_03_pzem004t.ino
|
||||
#endif
|
||||
#ifdef USE_DS18B20
|
||||
feature_sns1 |= 0x00000010; // xsns_05_ds18b20.ino
|
||||
feature_sns1 |= 0x00000010; // xsns_05_ds18b20.ino - no more support since 6.6.0.18
|
||||
#endif
|
||||
#ifdef USE_DS18x20_LEGACY
|
||||
feature_sns1 |= 0x00000020; // xsns_05_ds18x20_legacy.ino - no more supported since 6.6.0.14
|
||||
feature_sns1 |= 0x00000020; // xsns_05_ds18x20_legacy.ino - no more support since 6.6.0.14
|
||||
#endif
|
||||
#ifdef USE_DS18x20
|
||||
feature_sns1 |= 0x00000040; // xsns_05_ds18x20.ino
|
||||
|
|
|
@ -204,7 +204,7 @@ void EnergyUpdateTotal(float value, bool kwh)
|
|||
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
|
||||
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||
Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight();
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total updated with hardware value"));
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total updated with hardware value"));
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
}
|
||||
|
@ -499,6 +499,7 @@ void CmndEnergyReset(void)
|
|||
Energy.kWhtoday_offset = lnum *100;
|
||||
Energy.kWhtoday = 0;
|
||||
Energy.kWhtoday_delta = 0;
|
||||
Energy.start_energy = 0;
|
||||
Energy.period = Energy.kWhtoday_offset;
|
||||
Settings.energy_kWhtoday = Energy.kWhtoday_offset;
|
||||
RtcSettings.energy_kWhtoday = Energy.kWhtoday_offset;
|
||||
|
@ -515,15 +516,14 @@ void CmndEnergyReset(void)
|
|||
// Reset Energy Total
|
||||
RtcSettings.energy_kWhtotal = lnum *100;
|
||||
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
|
||||
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||
// Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||
Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight();
|
||||
RtcSettings.energy_usage.last_usage_kWhtotal = (uint32_t)(Energy.total * 1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((XdrvMailbox.index > 3) && (XdrvMailbox.index <= 5)) {
|
||||
else if ((XdrvMailbox.index > 3) && (XdrvMailbox.index <= 5)) {
|
||||
char *p;
|
||||
char *str = strtok_r(XdrvMailbox.data, ", ", &p);
|
||||
int32_t position = -1;
|
||||
|
@ -559,13 +559,12 @@ void CmndEnergyReset(void)
|
|||
}
|
||||
Settings.energy_usage.return1_kWhtotal = RtcSettings.energy_usage.return1_kWhtotal;
|
||||
Settings.energy_usage.return2_kWhtotal = RtcSettings.energy_usage.return2_kWhtotal;
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||
|
||||
char energy_total_chr[FLOATSZ];
|
||||
dtostrfd(Energy.total, Settings.flag2.energy_resolution, energy_total_chr);
|
||||
char energy_daily_chr[FLOATSZ];
|
||||
|
|
|
@ -1,253 +0,0 @@
|
|||
/*
|
||||
xsns_05_ds18b20.ino - DS18B20 temperature sensor support for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2019 Theo Arends
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_DS18B20
|
||||
/*********************************************************************************************\
|
||||
* DS18B20 - Temperature - Single sensor
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define XSNS_05 5
|
||||
|
||||
#define W1_SKIP_ROM 0xCC
|
||||
#define W1_CONVERT_TEMP 0x44
|
||||
#define W1_READ_SCRATCHPAD 0xBE
|
||||
|
||||
float ds18b20_temperature = 0;
|
||||
uint8_t ds18b20_valid = 0;
|
||||
uint8_t ds18x20_pin = 0;
|
||||
char ds18b20_types[] = "DS18B20";
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Embedded stripped and tuned OneWire library
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint8_t OneWireReset(void)
|
||||
{
|
||||
uint8_t retries = 125;
|
||||
|
||||
//noInterrupts();
|
||||
#ifdef DS18B20_INTERNAL_PULLUP
|
||||
pinMode(ds18x20_pin, INPUT_PULLUP);
|
||||
#else
|
||||
pinMode(ds18x20_pin, INPUT);
|
||||
#endif
|
||||
do {
|
||||
if (--retries == 0) {
|
||||
return 0;
|
||||
}
|
||||
delayMicroseconds(2);
|
||||
} while (!digitalRead(ds18x20_pin));
|
||||
pinMode(ds18x20_pin, OUTPUT);
|
||||
digitalWrite(ds18x20_pin, LOW);
|
||||
delayMicroseconds(480);
|
||||
#ifdef DS18B20_INTERNAL_PULLUP
|
||||
pinMode(ds18x20_pin, INPUT_PULLUP);
|
||||
#else
|
||||
pinMode(ds18x20_pin, INPUT);
|
||||
#endif
|
||||
delayMicroseconds(70);
|
||||
uint8_t r = !digitalRead(ds18x20_pin);
|
||||
//interrupts();
|
||||
delayMicroseconds(410);
|
||||
return r;
|
||||
}
|
||||
|
||||
void OneWireWriteBit(uint8_t v)
|
||||
{
|
||||
static const uint8_t delay_low[2] = { 65, 10 };
|
||||
static const uint8_t delay_high[2] = { 5, 55 };
|
||||
|
||||
v &= 1;
|
||||
//noInterrupts();
|
||||
digitalWrite(ds18x20_pin, LOW);
|
||||
pinMode(ds18x20_pin, OUTPUT);
|
||||
delayMicroseconds(delay_low[v]);
|
||||
digitalWrite(ds18x20_pin, HIGH);
|
||||
//interrupts();
|
||||
delayMicroseconds(delay_high[v]);
|
||||
}
|
||||
|
||||
uint8_t OneWireReadBit(void)
|
||||
{
|
||||
//noInterrupts();
|
||||
pinMode(ds18x20_pin, OUTPUT);
|
||||
digitalWrite(ds18x20_pin, LOW);
|
||||
delayMicroseconds(3);
|
||||
#ifdef DS18B20_INTERNAL_PULLUP
|
||||
pinMode(ds18x20_pin, INPUT_PULLUP);
|
||||
#else
|
||||
pinMode(ds18x20_pin, INPUT);
|
||||
#endif
|
||||
delayMicroseconds(10);
|
||||
uint8_t r = digitalRead(ds18x20_pin);
|
||||
//interrupts();
|
||||
delayMicroseconds(53);
|
||||
return r;
|
||||
}
|
||||
|
||||
void OneWireWrite(uint8_t v)
|
||||
{
|
||||
for (uint8_t bit_mask = 0x01; bit_mask; bit_mask <<= 1) {
|
||||
OneWireWriteBit((bit_mask & v) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t OneWireRead(void)
|
||||
{
|
||||
uint8_t r = 0;
|
||||
|
||||
for (uint8_t bit_mask = 0x01; bit_mask; bit_mask <<= 1) {
|
||||
if (OneWireReadBit()) {
|
||||
r |= bit_mask;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
bool OneWireCrc8(uint8_t *addr)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
uint8_t len = 8;
|
||||
|
||||
while (len--) {
|
||||
uint8_t inbyte = *addr++; // from 0 to 7
|
||||
for (uint32_t i = 8; i; i--) {
|
||||
uint8_t mix = (crc ^ inbyte) & 0x01;
|
||||
crc >>= 1;
|
||||
if (mix) {
|
||||
crc ^= 0x8C;
|
||||
}
|
||||
inbyte >>= 1;
|
||||
}
|
||||
}
|
||||
return (crc == *addr); // addr 8
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void Ds18b20Convert(void)
|
||||
{
|
||||
OneWireReset();
|
||||
OneWireWrite(W1_SKIP_ROM); // Address all Sensors on Bus
|
||||
OneWireWrite(W1_CONVERT_TEMP); // start conversion, no parasite power on at the end
|
||||
// delay(750); // 750ms should be enough for 12bit conv
|
||||
}
|
||||
|
||||
bool Ds18b20Read(void)
|
||||
{
|
||||
uint8_t data[9];
|
||||
int8_t sign = 1;
|
||||
|
||||
if (ds18b20_valid) { ds18b20_valid--; }
|
||||
/*
|
||||
if (!OneWireReadBit()) { // Check end of measurement
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
for (uint32_t retry = 0; retry < 3; retry++) {
|
||||
OneWireReset();
|
||||
OneWireWrite(W1_SKIP_ROM);
|
||||
OneWireWrite(W1_READ_SCRATCHPAD);
|
||||
for (uint32_t i = 0; i < 9; i++) {
|
||||
data[i] = OneWireRead();
|
||||
}
|
||||
if (OneWireCrc8(data)) {
|
||||
uint16_t temp12 = (data[1] << 8) + data[0];
|
||||
if (temp12 > 2047) {
|
||||
temp12 = (~temp12) +1;
|
||||
sign = -1;
|
||||
}
|
||||
ds18b20_temperature = ConvertTemp(sign * temp12 * 0.0625);
|
||||
ds18b20_valid = SENSOR_MAX_MISS;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR));
|
||||
return false;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void Ds18b20EverySecond(void)
|
||||
{
|
||||
ds18x20_pin = pin[GPIO_DSB];
|
||||
if (uptime &1) {
|
||||
// 2mS
|
||||
Ds18b20Convert(); // Start conversion, takes up to one second
|
||||
} else {
|
||||
// 12mS
|
||||
if (!Ds18b20Read()) { // Read temperature
|
||||
AddLogMissed(ds18b20_types, ds18b20_valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ds18b20Show(bool json)
|
||||
{
|
||||
if (ds18b20_valid) { // Check for valid temperature
|
||||
char temperature[33];
|
||||
dtostrfd(ds18b20_temperature, Settings.flag2.temperature_resolution, temperature);
|
||||
if(json) {
|
||||
ResponseAppend_P(JSON_SNS_TEMP, ds18b20_types, temperature);
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (0 == tele_period) {
|
||||
DomoticzSensor(DZ_TEMP, temperature);
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
#ifdef USE_KNX
|
||||
if (0 == tele_period) {
|
||||
KnxSensor(KNX_TEMPERATURE, ds18b20_temperature);
|
||||
}
|
||||
#endif // USE_KNX
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_SNS_TEMP, ds18b20_types, temperature, TempUnit());
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
bool Xsns05(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (pin[GPIO_DSB] < 99) {
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
Ds18b20EverySecond();
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
Ds18b20Show(1);
|
||||
break;
|
||||
#ifdef USE_WEBSERVER
|
||||
case FUNC_WEB_SENSOR:
|
||||
Ds18b20Show(0);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // USE_DS18B20
|
Loading…
Reference in New Issue