2017-01-28 13:41:01 +00:00
|
|
|
/*
|
2019-10-27 10:13:24 +00:00
|
|
|
xsns_05_ds18x20.ino - DS18x20 temperature sensor support for Tasmota
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2019-12-31 13:23:34 +00:00
|
|
|
Copyright (C) 2020 Theo Arends
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2017-05-13 12:02:10 +01:00
|
|
|
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.
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2017-05-13 12:02:10 +01:00
|
|
|
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/>.
|
2017-01-28 13:41:01 +00:00
|
|
|
*/
|
|
|
|
|
2020-09-27 17:26:30 +01:00
|
|
|
#ifdef ESP8266
|
2017-01-28 13:41:01 +00:00
|
|
|
#ifdef USE_DS18x20
|
|
|
|
/*********************************************************************************************\
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
* DS18B20 - Temperature - Multiple sensors
|
2017-01-28 13:41:01 +00:00
|
|
|
\*********************************************************************************************/
|
2018-11-06 16:33:51 +00:00
|
|
|
|
|
|
|
#define XSNS_05 5
|
|
|
|
|
2018-07-12 11:19:08 +01:00
|
|
|
//#define USE_DS18x20_RECONFIGURE // When sensor is lost keep retrying or re-configure
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2017-11-24 16:26:20 +00:00
|
|
|
#define DS18S20_CHIPID 0x10 // +/-0.5C 9-bit
|
|
|
|
#define DS1822_CHIPID 0x22 // +/-2C 12-bit
|
|
|
|
#define DS18B20_CHIPID 0x28 // +/-0.5C 12-bit
|
|
|
|
#define MAX31850_CHIPID 0x3B // +/-0.25C 14-bit
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2017-03-29 17:42:05 +01:00
|
|
|
#define W1_SKIP_ROM 0xCC
|
|
|
|
#define W1_CONVERT_TEMP 0x44
|
2017-11-24 16:26:20 +00:00
|
|
|
#define W1_WRITE_EEPROM 0x48
|
|
|
|
#define W1_WRITE_SCRATCHPAD 0x4E
|
2017-03-29 17:42:05 +01:00
|
|
|
#define W1_READ_SCRATCHPAD 0xBE
|
|
|
|
|
|
|
|
#define DS18X20_MAX_SENSORS 8
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2017-11-24 16:26:20 +00:00
|
|
|
const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850";
|
|
|
|
|
|
|
|
uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID };
|
2018-07-09 14:50:52 +01:00
|
|
|
|
2018-07-09 15:39:24 +01:00
|
|
|
struct DS18X20STRUCT {
|
|
|
|
uint8_t address[8];
|
|
|
|
uint8_t index;
|
2018-07-10 21:12:16 +01:00
|
|
|
uint8_t valid;
|
2018-07-09 15:39:24 +01:00
|
|
|
float temperature;
|
|
|
|
} ds18x20_sensor[DS18X20_MAX_SENSORS];
|
2017-10-18 17:22:34 +01:00
|
|
|
uint8_t ds18x20_sensors = 0;
|
2020-02-05 15:28:56 +00:00
|
|
|
uint8_t ds18x20_pin = 0; // Shelly GPIO3 input only
|
|
|
|
uint8_t ds18x20_pin_out = 0; // Shelly GPIO00 output only
|
|
|
|
bool ds18x20_dual_mode = false; // Single pin mode
|
2018-07-10 21:12:16 +01:00
|
|
|
char ds18x20_types[12];
|
2018-10-01 15:28:21 +01:00
|
|
|
#ifdef W1_PARASITE_POWER
|
|
|
|
uint8_t ds18x20_sensor_curr = 0;
|
|
|
|
unsigned long w1_power_until = 0;
|
|
|
|
#endif
|
2017-01-28 13:41:01 +00:00
|
|
|
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Embedded tuned OneWire library
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
#define W1_MATCH_ROM 0x55
|
|
|
|
#define W1_SEARCH_ROM 0xF0
|
|
|
|
|
|
|
|
uint8_t onewire_last_discrepancy = 0;
|
|
|
|
uint8_t onewire_last_family_discrepancy = 0;
|
|
|
|
bool onewire_last_device_flag = false;
|
|
|
|
unsigned char onewire_rom_id[8] = { 0 };
|
|
|
|
|
2020-02-05 15:28:56 +00:00
|
|
|
/*------------------------------------------------------------------------------------------*/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint8_t OneWireReset(void)
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
{
|
|
|
|
uint8_t retries = 125;
|
|
|
|
|
2020-02-05 15:28:56 +00:00
|
|
|
if (!ds18x20_dual_mode) {
|
|
|
|
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
|
|
|
|
do {
|
|
|
|
if (--retries == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
delayMicroseconds(2);
|
|
|
|
} while (!digitalRead(ds18x20_pin));
|
|
|
|
pinMode(ds18x20_pin, OUTPUT);
|
|
|
|
digitalWrite(ds18x20_pin, LOW);
|
|
|
|
delayMicroseconds(480);
|
|
|
|
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
|
2020-03-10 15:54:06 +00:00
|
|
|
delayMicroseconds(70);
|
|
|
|
uint8_t r = !digitalRead(ds18x20_pin);
|
|
|
|
delayMicroseconds(410);
|
|
|
|
return r;
|
2020-02-05 15:28:56 +00:00
|
|
|
} else {
|
|
|
|
digitalWrite(ds18x20_pin_out, HIGH);
|
|
|
|
do {
|
|
|
|
if (--retries == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
delayMicroseconds(2);
|
|
|
|
} while (!digitalRead(ds18x20_pin));
|
|
|
|
digitalWrite(ds18x20_pin_out, LOW);
|
|
|
|
delayMicroseconds(480);
|
|
|
|
digitalWrite(ds18x20_pin_out, HIGH);
|
2020-03-10 15:54:06 +00:00
|
|
|
delayMicroseconds(70);
|
|
|
|
uint8_t r = !digitalRead(ds18x20_pin);
|
|
|
|
delayMicroseconds(410);
|
|
|
|
return r;
|
2020-02-05 15:28:56 +00:00
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-02-05 15:28:56 +00:00
|
|
|
if (!ds18x20_dual_mode) {
|
|
|
|
digitalWrite(ds18x20_pin, LOW);
|
|
|
|
pinMode(ds18x20_pin, OUTPUT);
|
|
|
|
delayMicroseconds(delay_low[v]);
|
|
|
|
digitalWrite(ds18x20_pin, HIGH);
|
|
|
|
} else {
|
|
|
|
digitalWrite(ds18x20_pin_out, LOW);
|
|
|
|
delayMicroseconds(delay_low[v]);
|
|
|
|
digitalWrite(ds18x20_pin_out, HIGH);
|
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
delayMicroseconds(delay_high[v]);
|
|
|
|
}
|
|
|
|
|
2020-03-10 15:54:06 +00:00
|
|
|
uint8_t OneWire1ReadBit(void)
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
{
|
2020-03-10 15:54:06 +00:00
|
|
|
pinMode(ds18x20_pin, OUTPUT);
|
|
|
|
digitalWrite(ds18x20_pin, LOW);
|
|
|
|
delayMicroseconds(3);
|
|
|
|
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
|
|
|
|
delayMicroseconds(10);
|
|
|
|
uint8_t r = digitalRead(ds18x20_pin);
|
|
|
|
delayMicroseconds(53);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t OneWire2ReadBit(void)
|
|
|
|
{
|
|
|
|
digitalWrite(ds18x20_pin_out, LOW);
|
|
|
|
delayMicroseconds(3);
|
|
|
|
digitalWrite(ds18x20_pin_out, HIGH);
|
|
|
|
delayMicroseconds(10);
|
|
|
|
uint8_t r = digitalRead(ds18x20_pin);
|
|
|
|
delayMicroseconds(53);
|
|
|
|
return r;
|
2020-02-18 17:10:36 +00:00
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
|
2020-02-05 15:28:56 +00:00
|
|
|
/*------------------------------------------------------------------------------------------*/
|
|
|
|
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
void OneWireWrite(uint8_t v)
|
|
|
|
{
|
|
|
|
for (uint8_t bit_mask = 0x01; bit_mask; bit_mask <<= 1) {
|
|
|
|
OneWireWriteBit((bit_mask & v) ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint8_t OneWireRead(void)
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
{
|
|
|
|
uint8_t r = 0;
|
|
|
|
|
2020-03-10 15:54:06 +00:00
|
|
|
if (!ds18x20_dual_mode) {
|
|
|
|
for (uint8_t bit_mask = 0x01; bit_mask; bit_mask <<= 1) {
|
|
|
|
if (OneWire1ReadBit()) {
|
|
|
|
r |= bit_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (uint8_t bit_mask = 0x01; bit_mask; bit_mask <<= 1) {
|
|
|
|
if (OneWire2ReadBit()) {
|
|
|
|
r |= bit_mask;
|
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OneWireSelect(const uint8_t rom[8])
|
|
|
|
{
|
|
|
|
OneWireWrite(W1_MATCH_ROM);
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 8; i++) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireWrite(rom[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void OneWireResetSearch(void)
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
{
|
|
|
|
onewire_last_discrepancy = 0;
|
|
|
|
onewire_last_device_flag = false;
|
|
|
|
onewire_last_family_discrepancy = 0;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 8; i++) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
onewire_rom_id[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t OneWireSearch(uint8_t *newAddr)
|
|
|
|
{
|
|
|
|
uint8_t id_bit_number = 1;
|
|
|
|
uint8_t last_zero = 0;
|
|
|
|
uint8_t rom_byte_number = 0;
|
|
|
|
uint8_t search_result = 0;
|
|
|
|
uint8_t id_bit;
|
|
|
|
uint8_t cmp_id_bit;
|
|
|
|
unsigned char rom_byte_mask = 1;
|
|
|
|
unsigned char search_direction;
|
|
|
|
|
|
|
|
if (!onewire_last_device_flag) {
|
|
|
|
if (!OneWireReset()) {
|
|
|
|
onewire_last_discrepancy = 0;
|
|
|
|
onewire_last_device_flag = false;
|
|
|
|
onewire_last_family_discrepancy = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
OneWireWrite(W1_SEARCH_ROM);
|
|
|
|
do {
|
2020-03-10 15:54:06 +00:00
|
|
|
if (!ds18x20_dual_mode) {
|
|
|
|
id_bit = OneWire1ReadBit();
|
|
|
|
cmp_id_bit = OneWire1ReadBit();
|
|
|
|
} else {
|
|
|
|
id_bit = OneWire2ReadBit();
|
|
|
|
cmp_id_bit = OneWire2ReadBit();
|
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
if ((id_bit == 1) && (cmp_id_bit == 1)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (id_bit != cmp_id_bit) {
|
|
|
|
search_direction = id_bit;
|
|
|
|
} else {
|
|
|
|
if (id_bit_number < onewire_last_discrepancy) {
|
|
|
|
search_direction = ((onewire_rom_id[rom_byte_number] & rom_byte_mask) > 0);
|
|
|
|
} else {
|
|
|
|
search_direction = (id_bit_number == onewire_last_discrepancy);
|
|
|
|
}
|
|
|
|
if (search_direction == 0) {
|
|
|
|
last_zero = id_bit_number;
|
|
|
|
if (last_zero < 9) {
|
|
|
|
onewire_last_family_discrepancy = last_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (search_direction == 1) {
|
|
|
|
onewire_rom_id[rom_byte_number] |= rom_byte_mask;
|
|
|
|
} else {
|
|
|
|
onewire_rom_id[rom_byte_number] &= ~rom_byte_mask;
|
|
|
|
}
|
|
|
|
OneWireWriteBit(search_direction);
|
|
|
|
id_bit_number++;
|
|
|
|
rom_byte_mask <<= 1;
|
|
|
|
if (rom_byte_mask == 0) {
|
|
|
|
rom_byte_number++;
|
|
|
|
rom_byte_mask = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (rom_byte_number < 8);
|
|
|
|
if (!(id_bit_number < 65)) {
|
|
|
|
onewire_last_discrepancy = last_zero;
|
|
|
|
if (onewire_last_discrepancy == 0) {
|
|
|
|
onewire_last_device_flag = true;
|
|
|
|
}
|
|
|
|
search_result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!search_result || !onewire_rom_id[0]) {
|
|
|
|
onewire_last_discrepancy = 0;
|
|
|
|
onewire_last_device_flag = false;
|
|
|
|
onewire_last_family_discrepancy = 0;
|
|
|
|
search_result = false;
|
|
|
|
}
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 8; i++) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
newAddr[i] = onewire_rom_id[i];
|
|
|
|
}
|
|
|
|
return search_result;
|
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool OneWireCrc8(uint8_t *addr)
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
{
|
|
|
|
uint8_t crc = 0;
|
|
|
|
uint8_t len = 8;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
uint8_t inbyte = *addr++; // from 0 to 7
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 8; i; i--) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
uint8_t mix = (crc ^ inbyte) & 0x01;
|
|
|
|
crc >>= 1;
|
|
|
|
if (mix) {
|
|
|
|
crc ^= 0x8C;
|
|
|
|
}
|
|
|
|
inbyte >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (crc == *addr); // addr 8
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ds18x20Init(void)
|
2017-02-11 14:06:23 +00:00
|
|
|
{
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
uint64_t ids[DS18X20_MAX_SENSORS];
|
|
|
|
|
2020-04-27 11:54:07 +01:00
|
|
|
ds18x20_pin = Pin(GPIO_DSB);
|
2020-02-18 17:10:36 +00:00
|
|
|
|
2020-04-27 11:54:07 +01:00
|
|
|
if (PinUsed(GPIO_DSB_OUT)) {
|
|
|
|
ds18x20_pin_out = Pin(GPIO_DSB_OUT);
|
2020-02-05 15:28:56 +00:00
|
|
|
ds18x20_dual_mode = true; // Dual pins mode as used by Shelly
|
|
|
|
pinMode(ds18x20_pin_out, OUTPUT);
|
|
|
|
pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); // SetOption74 - Enable internal pullup for single DS18x20 sensor
|
|
|
|
}
|
2018-07-12 11:19:08 +01:00
|
|
|
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireResetSearch();
|
2018-12-24 17:14:25 +00:00
|
|
|
|
|
|
|
ds18x20_sensors = 0;
|
|
|
|
while (ds18x20_sensors < DS18X20_MAX_SENSORS) {
|
2018-07-09 14:50:52 +01:00
|
|
|
if (!OneWireSearch(ds18x20_sensor[ds18x20_sensors].address)) {
|
2017-01-28 13:41:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-07-09 14:50:52 +01:00
|
|
|
if (OneWireCrc8(ds18x20_sensor[ds18x20_sensors].address) &&
|
|
|
|
((ds18x20_sensor[ds18x20_sensors].address[0] == DS18S20_CHIPID) ||
|
|
|
|
(ds18x20_sensor[ds18x20_sensors].address[0] == DS1822_CHIPID) ||
|
|
|
|
(ds18x20_sensor[ds18x20_sensors].address[0] == DS18B20_CHIPID) ||
|
|
|
|
(ds18x20_sensor[ds18x20_sensors].address[0] == MAX31850_CHIPID))) {
|
|
|
|
ds18x20_sensor[ds18x20_sensors].index = ds18x20_sensors;
|
|
|
|
ids[ds18x20_sensors] = ds18x20_sensor[ds18x20_sensors].address[0]; // Chip id
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t j = 6; j > 0; j--) {
|
2018-07-09 14:50:52 +01:00
|
|
|
ids[ds18x20_sensors] = ids[ds18x20_sensors] << 8 | ds18x20_sensor[ds18x20_sensors].address[j];
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
2017-11-24 16:26:20 +00:00
|
|
|
ds18x20_sensors++;
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < ds18x20_sensors; i++) {
|
|
|
|
for (uint32_t j = i + 1; j < ds18x20_sensors; j++) {
|
2018-07-09 14:50:52 +01:00
|
|
|
if (ids[ds18x20_sensor[i].index] > ids[ds18x20_sensor[j].index]) { // Sort ascending
|
|
|
|
std::swap(ds18x20_sensor[i].index, ds18x20_sensor[j].index);
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSORS_FOUND " %d"), ds18x20_sensors);
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ds18x20Convert(void)
|
2017-01-28 13:41:01 +00:00
|
|
|
{
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireReset();
|
2018-10-01 15:28:21 +01:00
|
|
|
#ifdef W1_PARASITE_POWER
|
|
|
|
// With parasite power address one sensor at a time
|
|
|
|
if (++ds18x20_sensor_curr >= ds18x20_sensors)
|
|
|
|
ds18x20_sensor_curr = 0;
|
|
|
|
OneWireSelect(ds18x20_sensor[ds18x20_sensor_curr].address);
|
|
|
|
#else
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireWrite(W1_SKIP_ROM); // Address all Sensors on Bus
|
2018-10-01 15:28:21 +01:00
|
|
|
#endif
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireWrite(W1_CONVERT_TEMP); // start conversion, no parasite power on at the end
|
|
|
|
// delay(750); // 750ms should be enough for 12bit conv
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 21:12:16 +01:00
|
|
|
bool Ds18x20Read(uint8_t sensor)
|
2017-01-28 13:41:01 +00:00
|
|
|
{
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
uint8_t data[9];
|
2017-03-08 15:20:45 +00:00
|
|
|
int8_t sign = 1;
|
2017-01-28 13:41:01 +00:00
|
|
|
|
2018-07-09 14:50:52 +01:00
|
|
|
uint8_t index = ds18x20_sensor[sensor].index;
|
2018-07-10 21:12:16 +01:00
|
|
|
if (ds18x20_sensor[index].valid) { ds18x20_sensor[index].valid--; }
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t retry = 0; retry < 3; retry++) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireReset();
|
2018-07-09 14:50:52 +01:00
|
|
|
OneWireSelect(ds18x20_sensor[index].address);
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
OneWireWrite(W1_READ_SCRATCHPAD);
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 9; i++) {
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
data[i] = OneWireRead();
|
|
|
|
}
|
|
|
|
if (OneWireCrc8(data)) {
|
2018-07-09 14:50:52 +01:00
|
|
|
switch(ds18x20_sensor[index].address[0]) {
|
2019-03-02 11:33:52 +00:00
|
|
|
case DS18S20_CHIPID: {
|
2020-07-12 14:24:42 +01:00
|
|
|
/*
|
2019-03-02 11:33:52 +00:00
|
|
|
if (data[1] > 0x80) {
|
|
|
|
data[0] = (~data[0]) +1;
|
|
|
|
sign = -1; // App-Note fix possible sign error
|
|
|
|
}
|
|
|
|
float temp9 = (float)(data[0] >> 1) * sign;
|
|
|
|
ds18x20_sensor[index].temperature = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
2020-07-12 14:24:42 +01:00
|
|
|
|
|
|
|
Replaced by below based on issue #8777
|
|
|
|
*/
|
|
|
|
int16_t tempS = (((data[1] << 8) | (data[0] & 0xFE)) << 3) | ((0x10 - data[6]) & 0x0F);
|
|
|
|
ds18x20_sensor[index].temperature = ConvertTemp(tempS * 0.0625 - 0.250);
|
|
|
|
|
2019-03-02 11:33:52 +00:00
|
|
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
|
|
|
return true;
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
2019-03-02 11:33:52 +00:00
|
|
|
case DS1822_CHIPID:
|
|
|
|
case DS18B20_CHIPID: {
|
|
|
|
if (data[4] != 0x7F) {
|
|
|
|
data[4] = 0x7F; // Set resolution to 12-bit
|
|
|
|
OneWireReset();
|
|
|
|
OneWireSelect(ds18x20_sensor[index].address);
|
|
|
|
OneWireWrite(W1_WRITE_SCRATCHPAD);
|
|
|
|
OneWireWrite(data[2]); // Th Register
|
|
|
|
OneWireWrite(data[3]); // Tl Register
|
|
|
|
OneWireWrite(data[4]); // Configuration Register
|
|
|
|
OneWireSelect(ds18x20_sensor[index].address);
|
|
|
|
OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM
|
2018-10-01 15:28:21 +01:00
|
|
|
#ifdef W1_PARASITE_POWER
|
2019-03-02 11:33:52 +00:00
|
|
|
w1_power_until = millis() + 10; // 10ms specified duration for EEPROM write
|
2018-10-01 15:28:21 +01:00
|
|
|
#endif
|
2019-03-02 11:33:52 +00:00
|
|
|
}
|
|
|
|
uint16_t temp12 = (data[1] << 8) + data[0];
|
|
|
|
if (temp12 > 2047) {
|
|
|
|
temp12 = (~temp12) +1;
|
|
|
|
sign = -1;
|
|
|
|
}
|
|
|
|
ds18x20_sensor[index].temperature = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16
|
|
|
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
|
|
|
return true;
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
2019-03-02 11:33:52 +00:00
|
|
|
case MAX31850_CHIPID: {
|
|
|
|
int16_t temp14 = (data[1] << 8) + (data[0] & 0xFC);
|
|
|
|
ds18x20_sensor[index].temperature = ConvertTemp(temp14 * 0.0625); // Divide by 16
|
|
|
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
|
|
|
return true;
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
}
|
2017-04-10 16:25:31 +01:00
|
|
|
}
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR));
|
2018-07-10 21:12:16 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ds18x20Name(uint8_t sensor)
|
|
|
|
{
|
|
|
|
uint8_t index = sizeof(ds18x20_chipids);
|
|
|
|
while (index) {
|
|
|
|
if (ds18x20_sensor[ds18x20_sensor[sensor].index].address[0] == ds18x20_chipids[index]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
GetTextIndexed(ds18x20_types, sizeof(ds18x20_types), index, kDs18x20Types);
|
|
|
|
if (ds18x20_sensors > 1) {
|
2019-05-17 13:23:21 +01:00
|
|
|
snprintf_P(ds18x20_types, sizeof(ds18x20_types), PSTR("%s%c%d"), ds18x20_types, IndexSeparator(), sensor +1);
|
2018-07-10 21:12:16 +01:00
|
|
|
}
|
2018-07-09 14:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ds18x20EverySecond(void)
|
2018-07-09 14:50:52 +01:00
|
|
|
{
|
2020-02-18 17:10:36 +00:00
|
|
|
if (!ds18x20_sensors) { return; }
|
|
|
|
|
2018-10-01 15:28:21 +01:00
|
|
|
#ifdef W1_PARASITE_POWER
|
|
|
|
// skip access if there is still an eeprom write ongoing
|
|
|
|
unsigned long now = millis();
|
|
|
|
if (now < w1_power_until)
|
|
|
|
return;
|
|
|
|
#endif
|
2020-10-28 16:32:07 +00:00
|
|
|
if (TasmotaGlobal.uptime & 1
|
2018-10-01 15:28:21 +01:00
|
|
|
#ifdef W1_PARASITE_POWER
|
|
|
|
// if more than 1 sensor and only parasite power: convert every cycle
|
|
|
|
|| ds18x20_sensors >= 2
|
|
|
|
#endif
|
|
|
|
) {
|
2018-07-12 11:19:08 +01:00
|
|
|
// 2mS
|
2018-07-09 14:50:52 +01:00
|
|
|
Ds18x20Convert(); // Start conversion, takes up to one second
|
|
|
|
} else {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < ds18x20_sensors; i++) {
|
2018-07-12 11:19:08 +01:00
|
|
|
// 12mS per device
|
2018-07-10 21:12:16 +01:00
|
|
|
if (!Ds18x20Read(i)) { // Read temperature
|
|
|
|
Ds18x20Name(i);
|
|
|
|
AddLogMissed(ds18x20_types, ds18x20_sensor[ds18x20_sensor[i].index].valid);
|
2018-07-12 11:19:08 +01:00
|
|
|
#ifdef USE_DS18x20_RECONFIGURE
|
|
|
|
if (!ds18x20_sensor[ds18x20_sensor[i].index].valid) {
|
|
|
|
memset(&ds18x20_sensor, 0, sizeof(ds18x20_sensor));
|
|
|
|
Ds18x20Init(); // Re-configure
|
|
|
|
}
|
|
|
|
#endif // USE_DS18x20_RECONFIGURE
|
2018-07-10 21:12:16 +01:00
|
|
|
}
|
2018-07-09 14:50:52 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
void Ds18x20Show(bool json)
|
2017-01-28 13:41:01 +00:00
|
|
|
{
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < ds18x20_sensors; i++) {
|
2018-07-09 14:50:52 +01:00
|
|
|
uint8_t index = ds18x20_sensor[i].index;
|
|
|
|
|
2018-07-10 21:12:16 +01:00
|
|
|
if (ds18x20_sensor[index].valid) { // Check for valid temperature
|
2018-12-21 15:17:06 +00:00
|
|
|
char temperature[33];
|
2018-07-09 14:50:52 +01:00
|
|
|
dtostrfd(ds18x20_sensor[index].temperature, Settings.flag2.temperature_resolution, temperature);
|
2017-11-04 15:36:51 +00:00
|
|
|
|
2018-07-10 21:12:16 +01:00
|
|
|
Ds18x20Name(i);
|
v5.9.1j - Add Dual R2, Rewrite DS18x20 and fixes
5.9.1j
* Revert changes to xsns_05_ds18x20.ino and rename to
xsns_05_ds18x20_legacy.ino still needing library OneWire and providing
legacy JSON message:
*
"DS18x20":{"DS1":{"Type":"DS18B20","Address":"284CC48E04000079","Temperature":19.5},"DS2":{"Type":"DS18B20","Address":"283AC28304000052","Temperature":19.6}}
* Add new xdrv_05_ds18x20.ino free from library OneWire and add the
following features:
* Add support for DS1822
* Add forced setting of
12-bit resolution for selected device types (#1222)
* Add read
temperature retry counter (#1215)
* Fix lost sensors by performing
sensor probe at restart only thereby removing dynamic sensor probe
(#1215)
* Fix sensor address sorting using ascending sort on sensor
type followed by sensor address
* Rewrite JSON resulting in shorter
message allowing more sensors in default firmware image:
*
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}
* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
* Add support for Sonoff Dual R2 (#1249)
*
Fix ADS1115 detection (#1258)
2017-11-27 16:46:51 +00:00
|
|
|
|
2017-11-04 15:36:51 +00:00
|
|
|
if (json) {
|
2019-11-07 09:44:03 +00:00
|
|
|
char address[17];
|
|
|
|
for (uint32_t j = 0; j < 6; j++) {
|
|
|
|
sprintf(address+2*j, "%02X", ds18x20_sensor[index].address[6-j]); // Skip sensor type and crc
|
2017-11-04 15:36:51 +00:00
|
|
|
}
|
2019-11-07 09:44:03 +00:00
|
|
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, address, temperature);
|
2017-01-28 13:41:01 +00:00
|
|
|
#ifdef USE_DOMOTICZ
|
2020-10-29 12:37:09 +00:00
|
|
|
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
2017-11-04 15:36:51 +00:00
|
|
|
DomoticzSensor(DZ_TEMP, temperature);
|
|
|
|
}
|
2017-01-28 13:41:01 +00:00
|
|
|
#endif // USE_DOMOTICZ
|
2018-06-12 18:46:52 +01:00
|
|
|
#ifdef USE_KNX
|
2020-10-29 12:37:09 +00:00
|
|
|
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
2018-07-09 14:50:52 +01:00
|
|
|
KnxSensor(KNX_TEMPERATURE, ds18x20_sensor[index].temperature);
|
2018-06-12 18:46:52 +01:00
|
|
|
}
|
|
|
|
#endif // USE_KNX
|
2017-11-04 15:36:51 +00:00
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
} else {
|
2019-03-19 16:31:43 +00:00
|
|
|
WSContentSend_PD(HTTP_SNS_TEMP, ds18x20_types, temperature, TempUnit());
|
2017-11-04 15:36:51 +00:00
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
2017-01-28 13:41:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-03 17:07:25 +00:00
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool Xsns05(uint8_t function)
|
2017-11-03 17:07:25 +00:00
|
|
|
{
|
2019-01-28 13:08:33 +00:00
|
|
|
bool result = false;
|
2017-11-03 17:07:25 +00:00
|
|
|
|
2020-04-27 11:54:07 +01:00
|
|
|
if (PinUsed(GPIO_DSB)) {
|
2017-11-03 17:07:25 +00:00
|
|
|
switch (function) {
|
2017-12-25 16:41:12 +00:00
|
|
|
case FUNC_INIT:
|
2017-11-03 17:07:25 +00:00
|
|
|
Ds18x20Init();
|
|
|
|
break;
|
2018-07-09 14:50:52 +01:00
|
|
|
case FUNC_EVERY_SECOND:
|
|
|
|
Ds18x20EverySecond();
|
2017-11-03 17:07:25 +00:00
|
|
|
break;
|
2017-12-25 16:41:12 +00:00
|
|
|
case FUNC_JSON_APPEND:
|
2017-11-04 15:36:51 +00:00
|
|
|
Ds18x20Show(1);
|
2017-11-03 17:07:25 +00:00
|
|
|
break;
|
|
|
|
#ifdef USE_WEBSERVER
|
2019-03-19 16:31:43 +00:00
|
|
|
case FUNC_WEB_SENSOR:
|
2017-11-04 15:36:51 +00:00
|
|
|
Ds18x20Show(0);
|
2017-11-03 17:07:25 +00:00
|
|
|
break;
|
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-01-28 13:41:01 +00:00
|
|
|
#endif // USE_DS18x20
|
2020-09-27 17:26:30 +01:00
|
|
|
#endif // ESP8266
|