|
@ -14,7 +14,9 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
OneWire oneWire(DS_PIN); |
|
|
OneWire oneWire(DS_PIN); |
|
|
DallasTemperature ds18b20(&oneWire); |
|
|
DallasTemperature ds18b20(&oneWire); |
|
|
|
|
|
|
|
|
|
|
|
bool _dsIsConnected = false; |
|
|
double _dsTemperature = 0; |
|
|
double _dsTemperature = 0; |
|
|
|
|
|
char _dsTemperatureStr[6]; |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// DS18B20
|
|
|
// DS18B20
|
|
@ -24,6 +26,13 @@ double getDSTemperature() { |
|
|
return _dsTemperature; |
|
|
return _dsTemperature; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* getDSTemperatureStr() { |
|
|
|
|
|
if (!_dsIsConnected) |
|
|
|
|
|
return "NOT CONNECTED"; |
|
|
|
|
|
|
|
|
|
|
|
return _dsTemperatureStr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void dsSetup() { |
|
|
void dsSetup() { |
|
|
ds18b20.begin(); |
|
|
ds18b20.begin(); |
|
|
ds18b20.setWaitForConversion(false); |
|
|
ds18b20.setWaitForConversion(false); |
|
@ -70,21 +79,29 @@ void dsLoop() { |
|
|
|
|
|
|
|
|
_dsTemperature = t; |
|
|
_dsTemperature = t; |
|
|
|
|
|
|
|
|
char temperature[6]; |
|
|
|
|
|
dtostrf(t, 5, 1, temperature); |
|
|
|
|
|
DEBUG_MSG("[DS18B20] Temperature: %s%s\n", temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF"); |
|
|
|
|
|
|
|
|
if ((tmpUnits == TMP_CELSIUS && _dsTemperature == DEVICE_DISCONNECTED_C) || |
|
|
|
|
|
(tmpUnits == TMP_FAHRENHEIT && _dsTemperature == DEVICE_DISCONNECTED_F)) |
|
|
|
|
|
_dsIsConnected = false; |
|
|
|
|
|
else |
|
|
|
|
|
_dsIsConnected = true; |
|
|
|
|
|
|
|
|
|
|
|
dtostrf(t, 5, 1, _dsTemperatureStr); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_MSG("[DS18B20] Temperature: %s%s\n", |
|
|
|
|
|
getDSTemperatureStr(), |
|
|
|
|
|
(_dsIsConnected ? ((tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF") : "")); |
|
|
|
|
|
|
|
|
// Send MQTT messages
|
|
|
// Send MQTT messages
|
|
|
mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), temperature); |
|
|
|
|
|
|
|
|
mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), _dsTemperatureStr); |
|
|
|
|
|
|
|
|
// Send to Domoticz
|
|
|
// Send to Domoticz
|
|
|
#if ENABLE_DOMOTICZ
|
|
|
#if ENABLE_DOMOTICZ
|
|
|
domoticzSend("dczTmpIdx", 0, temperature); |
|
|
|
|
|
|
|
|
domoticzSend("dczTmpIdx", 0, _dsTemperatureStr); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// Update websocket clients
|
|
|
// Update websocket clients
|
|
|
char buffer[100]; |
|
|
char buffer[100]; |
|
|
sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), temperature, tmpUnits); |
|
|
|
|
|
|
|
|
sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), getDSTemperatureStr(), tmpUnits); |
|
|
wsSend(buffer); |
|
|
wsSend(buffer); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|