diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index e502debb..52b994db 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -62,6 +62,14 @@ // 0 means no pulses, 1 means normally off, 2 normally on #define RELAY_PULSE_MODE RELAY_PULSE_NONE +//-------------------------------------------------------------------------------- +// I18N +//-------------------------------------------------------------------------------- + +#define TMP_CELSIUS 0 +#define TMP_FAHRENHEIT 1 +#define TMP_UNITS TMP_CELSIUS + //-------------------------------------------------------------------------------- // LED //-------------------------------------------------------------------------------- diff --git a/code/espurna/dht.ino b/code/espurna/dht.ino index c1aeb45e..11f05a18 100644 --- a/code/espurna/dht.ino +++ b/code/espurna/dht.ino @@ -45,9 +45,11 @@ void dhtLoop() { if ((millis() - last_update > DHT_UPDATE_INTERVAL) || (last_update == 0)) { last_update = millis(); + unsigned char tmpUnits = getSetting("tmpUnits", TMP_UNITS).toInt(); + // Read sensor data double h = dht.readHumidity(); - double t = dht.readTemperature(); + double t = dht.readTemperature(tmpUnits == TMP_FAHRENHEIT); // Check if readings are valid if (isnan(h) || isnan(t)) { @@ -64,7 +66,7 @@ void dhtLoop() { dtostrf(t, 4, 1, temperature); itoa((unsigned int) h, humidity, 10); - DEBUG_MSG("[DHT] Temperature: %s\n", temperature); + DEBUG_MSG("[DHT] Temperature: %s%s\n", temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF"); DEBUG_MSG("[DHT] Humidity: %s\n", humidity); // Send MQTT messages @@ -93,7 +95,7 @@ void dhtLoop() { // 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, \"tmpUnits\": %d}"), temperature, humidity, tmpUnits); wsSend(buffer); } diff --git a/code/espurna/ds18b20.ino b/code/espurna/ds18b20.ino index 7424241b..197a8180 100644 --- a/code/espurna/ds18b20.ino +++ b/code/espurna/ds18b20.ino @@ -40,9 +40,11 @@ void dsLoop() { if ((millis() - last_update > DS_UPDATE_INTERVAL) || (last_update == 0)) { last_update = millis(); + unsigned char tmpUnits = getSetting("tmpUnits", TMP_UNITS).toInt(); + // Read sensor data ds18b20.requestTemperatures(); - double t = ds18b20.getTempCByIndex(0); + double t = (tmpUnits == TMP_CELSIUS) ? ds18b20.getTempCByIndex(0) : ds18b20.getTempFByIndex(0); // Check if readings are valid if (isnan(t)) { @@ -55,7 +57,7 @@ void dsLoop() { char temperature[6]; dtostrf(t, 5, 1, temperature); - DEBUG_MSG("[DS18B20] Temperature: %s\n", temperature); + DEBUG_MSG("[DS18B20] Temperature: %s%s\n", temperature, (tmpUnits == TMP_CELSIUS) ? "ºC" : "ºF"); // Send MQTT messages mqttSend(getSetting("dsTmpTopic", DS_TEMPERATURE_TOPIC).c_str(), temperature); @@ -67,7 +69,7 @@ void dsLoop() { // Update websocket clients char buffer[100]; - sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s}"), temperature); + sprintf_P(buffer, PSTR("{\"dsVisible\": 1, \"dsTmp\": %s, \"tmpUnits\": %d}"), temperature, tmpUnits); wsSend(buffer); } diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 658efcb8..25da21c1 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -273,11 +273,6 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { setCurrentRatio(getSetting("emonRatio").toFloat()); #endif - #if LED_PULSE - byte relayPulseMode = getSetting("relayPulseMode", String(RELAY_PULSE_MODE)).toInt(); - digitalWrite(LED_PULSE, relayPulseMode != RELAY_PULSE_NONE); - #endif - // Check if we should reconfigure MQTT connection if (changedMQTT) { mqttDisconnect(); @@ -339,6 +334,8 @@ void _wsStart(uint32_t client_id) { root["apiEnabled"] = getSetting("apiEnabled").toInt() == 1; root["apiKey"] = getSetting("apiKey"); + root["tmpUnits"] = getSetting("tmpUnits", TMP_UNITS).toInt(); + #if ENABLE_DOMOTICZ root["dczVisible"] = 1; diff --git a/code/html/custom.js b/code/html/custom.js index 4724b509..e12e0d92 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -297,6 +297,9 @@ function processData(data) { if (key == "mqttStatus") { data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED"; } + if (key == "tmpUnits") { + $("span#tmpUnit").html(data[key] == 1 ? "ºF" : "ºC"); + } // Look for INPUTs var element = $("input[name=" + key + "]"); @@ -305,6 +308,8 @@ function processData(data) { element .prop("checked", data[key]) .iphoneStyle("refresh"); + } else if (element.attr('type') == 'radio') { + element.val([data[key]]); } else { element.val(data[key]); } @@ -342,6 +347,7 @@ function connect(host, port) { if (typeof port === 'undefined') { port = location.port; } + if (websock) websock.close(); websock = new WebSocket('ws://' + host + ':' + port + '/ws'); websock.onopen = function(evt) { console.log("Connected"); diff --git a/code/html/index.html b/code/html/index.html index a7901f98..23e8b3a1 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -121,12 +121,12 @@
- +
- +
@@ -247,6 +247,12 @@
+
+
+
Celsius (ºC)
+
Fahrenheit (ºF)
+
+