Browse Source

Issue #69. Allow temperatures to be reported in Fahrenheit degrees

fastled
Xose Pérez 7 years ago
parent
commit
6402af4ab3
6 changed files with 34 additions and 13 deletions
  1. +8
    -0
      code/espurna/config/general.h
  2. +5
    -3
      code/espurna/dht.ino
  3. +5
    -3
      code/espurna/ds18b20.ino
  4. +2
    -5
      code/espurna/web.ino
  5. +6
    -0
      code/html/custom.js
  6. +8
    -2
      code/html/index.html

+ 8
- 0
code/espurna/config/general.h View File

@ -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
//--------------------------------------------------------------------------------


+ 5
- 3
code/espurna/dht.ino View File

@ -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);
}


+ 5
- 3
code/espurna/ds18b20.ino View File

@ -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);
}


+ 2
- 5
code/espurna/web.ino View File

@ -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;


+ 6
- 0
code/html/custom.js View File

@ -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");


+ 8
- 2
code/html/index.html View File

@ -121,12 +121,12 @@
</div>
<div class="pure-g module module-ds">
<label class="pure-u-1 pure-u-sm-1-4" for="dsTmp">Temperature (ºC)</label>
<label class="pure-u-1 pure-u-sm-1-4" for="dsTmp">Temperature (<span id="tmpUnit"></span>)</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="dsTmp" readonly />
</div>
<div class="pure-g module module-dht">
<label class="pure-u-1 pure-u-sm-1-4" for="dhtTmp">Temperature (ºC)</label>
<label class="pure-u-1 pure-u-sm-1-4" for="dhtTmp">Temperature (<span id="tmpUnit"></span>)</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="dhtTmp" readonly />
</div>
@ -247,6 +247,12 @@
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" tabindex="6" /></div>
</div>
<div class="pure-g module module-ds module-dht">
<div class="pure-u-1 pure-u-sm-1-4"><label for="tmpUnits">Temperature units</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="7" value="0"> Celsius (ºC)</input></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="8" value="1"> Fahrenheit (ºF)</input></div>
</div>
</fieldset>
</div>
</div>


Loading…
Cancel
Save