Result 85 is typical for DS18B20 sensors when some error happens with
them. If so, attempt retry up to three times in order to recover from
the error. If still error, return error instead of "85" as temperature
value.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
char buf[16];
int fd;
int ret;
char buf[16];
int fd;
int ret;
fd = open(path, O_RDONLY);
if (fd < 0) {
printf("%s: Failed to open file %s: %m\n", __func__, path);
fd = open(path, O_RDONLY);
if (fd < 0) {
printf("%s: Failed to open file %s: %m\n", __func__, path);
+ if (*temp == 85) {
+ ret = -1;
+ if (retries < 3) {
+ retries++;
+ printf("Retrying 1wire read, try %d\n", retries);
+ goto retry;
+ }
+ }
+