Skip to content

Commit

Permalink
Merge pull request #1603 from ElderJoy/thermostat
Browse files Browse the repository at this point in the history
Add thermostat module
  • Loading branch information
xoseperez committed Mar 25, 2019
2 parents fe67fb6 + 870f311 commit 5d5e915
Show file tree
Hide file tree
Showing 16 changed files with 3,657 additions and 5 deletions.
47 changes: 45 additions & 2 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@
#define EEPROM_ROTATE_DATA 11 // Reserved for the EEPROM_ROTATE library (3 bytes)
#define EEPROM_DATA_END 14 // End of custom EEPROM data block

//------------------------------------------------------------------------------
// THERMOSTAT
//------------------------------------------------------------------------------

#ifndef THERMOSTAT_SUPPORT
#define THERMOSTAT_SUPPORT 0
#endif

#ifndef THERMOSTAT_DISPLAY_SUPPORT
#define THERMOSTAT_DISPLAY_SUPPORT 0
#endif

#define THERMOSTAT_SERVER_LOST_INTERVAL 120000 //server means lost after 2 min from last response
#define THERMOSTAT_REMOTE_TEMP_MAX_WAIT 120 // 2 min

//------------------------------------------------------------------------------
// HEARTBEAT
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -259,6 +274,18 @@
#define HEARTBEAT_REPORT_INTERVAL 0
#endif

#if THERMOSTAT_SUPPORT && ! defined HEARTBEAT_REPORT_RANGE
#define HEARTBEAT_REPORT_RANGE 1
#else
#define HEARTBEAT_REPORT_RANGE 0
#endif

#if THERMOSTAT_SUPPORT && ! defined HEARTBEAT_REPORT_REMOTE_TEMP
#define HEARTBEAT_REPORT_REMOTE_TEMP 1
#else
#define HEARTBEAT_REPORT_REMOTE_TEMP 0
#endif

//------------------------------------------------------------------------------
// Load average
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -756,8 +783,14 @@
#endif


#ifndef MQTT_USE_JSON
#define MQTT_USE_JSON 0 // Group messages in a JSON body
#if THERMOSTAT_SUPPORT == 1
#ifndef MQTT_USE_JSON
#define MQTT_USE_JSON 1 // Group messages in a JSON body
#endif
#else
#ifndef MQTT_USE_JSON
#define MQTT_USE_JSON 0 // Don't group messages in a JSON body (default)
#endif
#endif

#ifndef MQTT_USE_JSON_DELAY
Expand Down Expand Up @@ -837,6 +870,16 @@
#define MQTT_TOPIC_KELVIN "kelvin"
#define MQTT_TOPIC_TRANSITION "transition"

// Thermostat module
#define MQTT_TOPIC_HOLD_TEMP "hold_temp"
#define MQTT_TOPIC_HOLD_TEMP_MIN "min"
#define MQTT_TOPIC_HOLD_TEMP_MAX "max"
#define MQTT_TOPIC_REMOTE_TEMP "remote_temp"
#define MQTT_TOPIC_ASK_TEMP_RANGE "ask_temp_range"
#define MQTT_TOPIC_NOTIFY_TEMP_RANGE_MIN "notify_temp_range_min"
#define MQTT_TOPIC_NOTIFY_TEMP_RANGE_MAX "notify_temp_range_max"


#define MQTT_STATUS_ONLINE "1" // Value for the device ON message
#define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will)

Expand Down
6 changes: 6 additions & 0 deletions code/espurna/config/progmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ PROGMEM const char espurna_modules[] =
#if TERMINAL_SUPPORT
"TERMINAL "
#endif
#if THERMOSTAT_SUPPORT
"THERMOSTAT "
#endif
#if THERMOSTAT_DISPLAY_SUPPORT
"THERMOSTAT_DISPLAY "
#endif
#if THINGSPEAK_SUPPORT
"THINGSPEAK "
#endif
Expand Down
11 changes: 11 additions & 0 deletions code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,14 @@ void webRequestRegister(web_request_callback_f callback);
typedef std::function<void(justwifi_messages_t code, char * parameter)> wifi_callback_f;
void wifiRegister(wifi_callback_f callback);
bool wifiConnected();

// -----------------------------------------------------------------------------
// THERMOSTAT
// -----------------------------------------------------------------------------
#if THERMOSTAT_SUPPORT
typedef std::function<void(bool)> thermostat_callback_f;
void thermostatRegister(thermostat_callback_f callback);
#else
#define thermostat_callback_f void *
#endif

13 changes: 13 additions & 0 deletions code/espurna/config/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define WEBUI_IMAGE_RFBRIDGE 4
#define WEBUI_IMAGE_RFM69 8
#define WEBUI_IMAGE_LIGHTFOX 16
#define WEBUI_IMAGE_THERMOSTAT 32
#define WEBUI_IMAGE_FULL 15

#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Expand Down Expand Up @@ -53,6 +54,15 @@
#define WEBUI_IMAGE WEBUI_IMAGE_LIGHTFOX
#endif

#if THERMOSTAT_SUPPORT == 1
#ifndef WEBUI_IMAGE
#define WEBUI_IMAGE WEBUI_IMAGE_THERMOSTAT
#else
#undef WEBUI_IMAGE
#define WEBUI_IMAGE WEBUI_IMAGE_FULL
#endif
#endif

#ifndef WEBUI_IMAGE
#define WEBUI_IMAGE WEBUI_IMAGE_SMALL
#endif
Expand All @@ -78,6 +88,9 @@ PROGMEM const char espurna_webui[] =
#if WEBUI_IMAGE == WEBUI_IMAGE_LIGHTFOX
"LIGHTFOX"
#endif
#if WEBUI_IMAGE == WEBUI_IMAGE_THERMOSTAT
"THERMOSTAT"
#endif
#if WEBUI_IMAGE == WEBUI_IMAGE_FULL
"FULL"
#endif
Expand Down
Binary file added code/espurna/data/index.thermostat.html.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ void setup() {
#ifdef FOXEL_LIGHTFOX_DUAL
lightfoxSetup();
#endif
#if THERMOSTAT_SUPPORT
thermostatSetup();
#endif
#if THERMOSTAT_DISPLAY_SUPPORT
displaySetup();
#endif


// 3rd party code hook
Expand Down
9 changes: 9 additions & 0 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "filters/MovingAverageFilter.h"
#include "sensors/BaseSensor.h"

#include <float.h>

typedef struct {
BaseSensor * sensor; // Sensor object
BaseFilter * filter; // Filter object
Expand Down Expand Up @@ -1290,6 +1292,13 @@ unsigned char magnitudeType(unsigned char index) {
return MAGNITUDE_NONE;
}

double magnitudeValue(unsigned char index) {
if (index < _magnitudes.size()) {
return _sensor_realtime ? _magnitudes[index].current : _magnitudes[index].reported;
}
return DBL_MIN;
}

unsigned char magnitudeIndex(unsigned char index) {
if (index < _magnitudes.size()) {
return int(_magnitudes[index].global);
Expand Down
Loading

0 comments on commit 5d5e915

Please sign in to comment.