In this line:
int insideThermometer = (int)insideThermometer;
You create a local variable and assign it to itself. Not what you wanted. The global var you are trying to use is
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x83, 0x51, 0xB2, 0x17, 0x4, 0x8A };
If you look at the source code, DeviceAddress
is typdef’d as
typedef uint8_t DeviceAddress[8];
If you want to get the temperature you need to call sensors.getTempC(insideThermometer)
, which you already do in the printTemperature
function. Since you call that function before testing the temp, just modify it to return the temp:
float printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
float tempF = 0;
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
tempF = DallasTemperature::toFahrenheit(tempC);
Serial.print(tempF);
}
return tempF;
}
Then change to
int insideTempF = printTemperature(insideThermometer);
....
if (insideTempF > mintemp) {
....
(You may want to change the name of the function to something like printAndReturnTemperature
as that more clearly states its new functionality.)
solved WEMOS D1 + DallasTemperature: How to print temperature and temperature comparison in if [closed]