diff --git a/code/data/index.html.gz b/code/data/index.html.gz index 94413f85..59a3d111 100644 Binary files a/code/data/index.html.gz and b/code/data/index.html.gz differ diff --git a/code/html/index.html b/code/html/index.html index 7b9cddd7..0bec6d50 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -112,6 +112,11 @@ +
+ + +
+
diff --git a/code/platformio.ini b/code/platformio.ini index 9b5d699b..30dbc155 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -13,6 +13,8 @@ lib_deps = ESPAsyncUDP Embedis NtpClientLib + OneWire + DallasTemperature https://bitbucket.org/xoseperez/justwifi.git https://bitbucket.org/xoseperez/nofuss.git https://bitbucket.org/xoseperez/hlw8012.git diff --git a/code/src/config/sensors.h b/code/src/config/sensors.h index 4f11c0aa..338a9913 100644 --- a/code/src/config/sensors.h +++ b/code/src/config/sensors.h @@ -20,6 +20,15 @@ #define DHT_TEMPERATURE_TOPIC "/temperature" #define DHT_HUMIDITY_TOPIC "/humidity" +//-------------------------------------------------------------------------------- +// DS18B20 temperature sensor +// Enable support by passing ENABLE_DS18B20=1 build flag +//-------------------------------------------------------------------------------- + +#define DS_PIN 14 +#define DS_UPDATE_INTERVAL 60000 +#define DS_TEMPERATURE_TOPIC "/temperature" + //-------------------------------------------------------------------------------- // Custom current sensor // Check http://tinkerman.cat/your-laundry-is-done/ diff --git a/code/src/dht.ino b/code/src/dht.ino index b7fd2cf8..5dd07492 100644 --- a/code/src/dht.ino +++ b/code/src/dht.ino @@ -14,19 +14,19 @@ Copyright (C) 2016 by Xose Pérez DHT dht(DHT_PIN, DHT_TYPE, DHT_TIMING); -char temperature[6]; -char humidity[6]; +char dhtTemperature[6]; +char dhtHumidity[6]; // ----------------------------------------------------------------------------- // DHT // ----------------------------------------------------------------------------- -char * getTemperature() { - return temperature; +char * getDHTTemperature() { + return dhtTemperature; } -char * getHumidity() { - return humidity; +char * getDHTHumidity() { + return dhtHumidity; } void dhtSetup() { @@ -53,19 +53,19 @@ void dhtLoop() { } else { - dtostrf(t, 4, 1, temperature); - itoa((int) h, humidity, 10); + dtostrf(t, 4, 1, dhtTemperature); + itoa((int) h, dhtHumidity, 10); - DEBUG_MSG("[DHT] Temperature: %s\n", temperature); - DEBUG_MSG("[DHT] Humidity: %s\n", humidity); + DEBUG_MSG("[DHT] Temperature: %s\n", dhtTemperature); + DEBUG_MSG("[DHT] Humidity: %s\n", dhtHumidity); // Send MQTT messages - mqttSend((char *) getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature); - mqttSend((char *) getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity); + mqttSend((char *) getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), dhtTemperature); + mqttSend((char *) getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), dhtHumidity); // Update websocket clients char buffer[100]; - sprintf_P(buffer, PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s}"), temperature, humidity); + sprintf_P(buffer, PSTR("{\"dhtVisible\": 1, \"dhtTmp\": %s, \"dhtHum\": %s}"), dhtTemperature, dhtHumidity); wsSend(buffer); } diff --git a/code/src/ds18b20.ino b/code/src/ds18b20.ino new file mode 100644 index 00000000..02ecdd0f --- /dev/null +++ b/code/src/ds18b20.ino @@ -0,0 +1,70 @@ +/* + +ESPurna +SD18B20 MODULE + +Copyright (C) 2016 by Xose Pérez + +*/ + +#if ENABLE_DS18B20 + +#include +#include + +OneWire oneWire(DS_PIN); +DallasTemperature ds18b20(&oneWire); + +char dsTemperature[6]; + +// ----------------------------------------------------------------------------- +// DS18B20 +// ----------------------------------------------------------------------------- + +char * getDSTemperature() { + return dsTemperature; +} + +void dsSetup() { + ds18b20.begin(); +} + +void dsLoop() { + + if (!mqttConnected()) return; + + // Check if we should read new data + static unsigned long last_update = 0; + if ((millis() - last_update > DS_UPDATE_INTERVAL) || (last_update == 0)) { + last_update = millis(); + + // Read sensor data + ds18b20.requestTemperatures(); + double t = ds18b20.getTempCByIndex(0); + + // Check if readings are valid + if (isnan(t)) { + + DEBUG_MSG("[DS18B20] Error reading sensor\n"); + + } else { + + dtostrf(t, 4, 1, dsTemperature); + + DEBUG_MSG("[DS18B20] Temperature: %s\n", dsTemperature); + + // Send MQTT messages + mqttSend((char *) getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), dsTemperature); + + // Update websocket clients + char buffer[100]; + sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s}"), dsTemperature); + wsSend(buffer); + + } + + } + +} + +#endif diff --git a/code/src/main.ino b/code/src/main.ino index b8282859..8b0ca4b4 100644 --- a/code/src/main.ino +++ b/code/src/main.ino @@ -155,6 +155,9 @@ void setup() { #if ENABLE_POW powSetup(); #endif + #if ENABLE_DS18B20 + dsSetup(); + #endif #if ENABLE_DHT dhtSetup(); #endif @@ -183,6 +186,9 @@ void loop() { #if ENABLE_POW powLoop(); #endif + #if ENABLE_DS18B20 + dsLoop(); + #endif #if ENABLE_DHT dhtLoop(); #endif diff --git a/code/src/web.ino b/code/src/web.ino index 21d6347d..7cd8ac1e 100644 --- a/code/src/web.ino +++ b/code/src/web.ino @@ -207,10 +207,15 @@ void _wsStart(uint32_t client_id) { root["fauxmoEnabled"] = getSetting("fauxmoEnabled", String(FAUXMO_ENABLED)).toInt() == 1; #endif + #if ENABLE_DS18B20 + root["dsVisible"] = 1; + root["dsTmp"] = getDSTemperature(); + #endif + #if ENABLE_DHT root["dhtVisible"] = 1; - root["dhtTmp"] = getTemperature(); - root["dhtHum"] = getHumidity(); + root["dhtTmp"] = getDHTTemperature(); + root["dhtHum"] = getDHTHumidity(); #endif #if ENABLE_RF