Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rescan and RetryRead to onewire scan for bulletproove onewire #19700

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tasmota/include/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,9 @@
#define D_CMND_ADCPARAM "AdcParam"

// Commands xsns_05_ds18x20.ino
#define D_CMND_DS_ALIAS "DS18Alias"
#define D_CMND_DS_ALIAS "Alias"
#define D_CMND_DS_RESCAN "Rescan"
#define D_CMND_DS_RETRYREAD "RetryRead"

// xsns_70_veml6075.ino
#define D_JSON_UVA_INTENSITY "UvaIntensity"
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void Ds18x20Show(bool json) {
}

#ifdef DS18x20_USE_ID_ALIAS
const char kds18Commands[] PROGMEM = "|" // No prefix
const char kds18Commands[] PROGMEM = "DS18|" // prefix
D_CMND_DS_ALIAS;

void (* const DSCommand[])(void) PROGMEM = {
Expand Down
76 changes: 71 additions & 5 deletions tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ struct {
char name[17];
uint8_t sensors;
uint8_t gpios; // Count of GPIO found
uint8_t retryRead;
} DS18X20Data;

/********************************************************************************************/

void Ds18x20Init(void) {
DS18X20Data.retryRead = 0;
DS18X20Data.gpios = 0;
for (uint32_t pins = 0; pins < MAX_DSB; pins++) {
if (PinUsed(GPIO_DSB, pins)) {
Expand Down Expand Up @@ -254,7 +256,18 @@ void Ds18x20EverySecond(void) {
float t;
for (uint32_t i = 0; i < DS18X20Data.sensors; i++) {
// 12mS per device
if (Ds18x20Read(i, t)) { // Read temperature
bool result = false;
uint8_t counter = 0;
while (counter++ < DS18X20Data.retryRead+1) {
if(Ds18x20Read(i, t)) {
result = true;
break;
}
}
if (!result)
AddLog(LOG_LEVEL_ERROR, PSTR("Read sensor %u failed in Ds18x20EverySecond."), i);

if (result) { // Read temperature
if (Settings->flag5.ds18x20_mean) {
if (ds18x20_sensor[i].numread++ == 0) {
ds18x20_sensor[i].temp_sum = 0;
Expand All @@ -279,7 +292,17 @@ void Ds18x20Show(bool json) {
if (ds18x20_sensor[i].valid) {
t = ds18x20_sensor[i].temperature;
#else
if (Ds18x20Read(i, t)) { // Check if read failed
bool result = false;
uint8_t counter = 0;
while (counter++ < DS18X20Data.retryRead+1) {
if(Ds18x20Read(i, t)) {
result = true;
break;
}
}
if (!result)
AddLog(LOG_LEVEL_ERROR, PSTR("Read sensor %u failed in Ds18x20Show."), i);
if (result) { // Check if read failed
#endif
Ds18x20Name(i);

Expand Down Expand Up @@ -317,11 +340,54 @@ void Ds18x20Show(bool json) {
}

#ifdef DS18x20_USE_ID_ALIAS
const char kds18Commands[] PROGMEM = "|" // No prefix
D_CMND_DS_ALIAS;
const char kds18Commands[] PROGMEM = "DS18|" // prefix
D_CMND_DS_ALIAS "|" D_CMND_DS_RESCAN "|" D_CMND_DS_RETRYREAD;

void (* const DSCommand[])(void) PROGMEM = {
&CmndDSAlias };
&CmndDSAlias, &CmndDSRescan ,&CmndDSRetryRead };


void CmndDSRetryRead(void) {
char argument[XdrvMailbox.data_len];

if (ArgC()==1) {
DS18X20Data.retryRead = atoi(ArgV(argument, 1));
}
Response_P(PSTR("{\"DS18" D_CMND_DS_RETRYREAD "\": %d}"),DS18X20Data.retryRead);
}


void CmndDSRescan(void) {
char argument[XdrvMailbox.data_len];
uint8_t retries = 1;
uint8_t sensorsToFind = 1;
if (ArgC()>0 && ArgC()<3) {
sensorsToFind = atoi(ArgV(argument, 1));
}
if (ArgC()==2) {
retries = atoi(ArgV(argument, 2));
}

DS18X20Data.sensors = 0;
memset(&ds18x20_sensor, 0, sizeof(ds18x20_sensor));

while (DS18X20Data.sensors < sensorsToFind && retries-- > 0) {
Ds18x20Search();
AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_DSB D_SENSORS_FOUND " %d"), DS18X20Data.sensors);
}

Response_P(PSTR("{"));
for (uint32_t i = 0; i < DS18X20Data.sensors; i++) {
Ds18x20Name(i);
char address[17];
for (uint32_t j = 0; j < 8; j++) {
sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); // Skip sensor type and crc
}
ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"),DS18X20Data.name, address);
if (i < DS18X20Data.sensors-1) {ResponseAppend_P(PSTR(","));}
}
ResponseAppend_P(PSTR("}"));
}

void CmndDSAlias(void) {
char Argument1[XdrvMailbox.data_len];
Expand Down