Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chip #23

Merged
merged 12 commits into from
Nov 2, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ backups
pcb/production/.nfs*
*backup
*.DONOTCOMPILE
*DO_NOT_COMPILE*
Matter/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Basic layout of thermostat:

<img src="./assets/Block%20Diagram.drawio.png">

# October 4, 2023 addition of Matter support

Getting started: https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html

Matter support is delayed until the SDK can be added as a library to PlatformIO. Currently, the actions required to create a dev environment is too extreme.

# September 8, 2023 update - V0.6

The thermostat app code is now 100% ESP-IDF based. All dependencies on the Arduino framework have been removed. This provides for much better control of the code and better integration with the upcoming Matter implementation.
Expand Down
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
lib
10 changes: 1 addition & 9 deletions app/.unotes/unotes_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
},
"files": {}
},
"test": {
"name": "test",
"isOrdered": true,
"folders": {},
"files": {}
},
"boards": {
"name": "boards",
"isOrdered": true,
Expand All @@ -70,7 +64,5 @@
"files": {}
}
},
"files": {
"GettingStarted": 0
}
"files": {}
}
2 changes: 1 addition & 1 deletion app/include/Arduino.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*---------------------------------------------------------------
Simple header file to incorporate Arduino functions
mostly for the LD2410 sensor.
mostly for the LD2410 sensor library.
---------------------------------------------------------------*/

#include "thermostat.hpp"
Expand Down
1 change: 1 addition & 0 deletions app/include/gpio_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define HVAC_FAN_PIN 4
#define HVAC_HEAT_PIN 5
#define HVAC_COOL_PIN 6
#define HVAC_RVALV_PIN 7
#define BUZZER_PIN 17
#define MOTION_PIN 18
#define LIGHT_SENS_PIN 8
Expand Down
60 changes: 50 additions & 10 deletions app/include/thermostat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define LOW 0



/////////////////////////////////////////////////////////////////////
// Shared data structures
/////////////////////////////////////////////////////////////////////
Expand All @@ -28,7 +27,7 @@ typedef enum
AUTO,
HEAT,
COOL,
FAN,
FAN_ONLY,
AUX_HEAT,
ERROR,
IDLE
Expand All @@ -37,6 +36,12 @@ typedef enum

typedef struct
{
// FriendlyName and DeviceName must be
// the same size due to copy operation
// in ui_events.cpp, saveDeviceName()
char FriendlyName[32];
char DeviceName[32];
uint8_t mac[6];
HVAC_MODE hvacOpMode;
HVAC_MODE hvacSetMode;
float tempSet;
Expand All @@ -62,14 +67,29 @@ typedef struct
char *timezone;
uint16_t timezone_sel;

#ifdef MQTT_ENABLED
bool MqttEnabled;
// bool MqttStarted;
bool MqttConnected;
char MqttBrokerHost[32];
uint16_t MqttBrokerPort;
char MqttBrokerUsername[32];
char MqttBrokerPassword[72];
void *MqttClient; // Used during MQTT publish
#endif

#ifdef MATTER_ENABLED
bool MatterEnabled;
bool MatterStarted;
#endif
//@@@ Zipcode for outside temp??
//@@@ Calibration data for touchscreen?

} OPERATING_PARAMETERS;

typedef struct
{
char hostname[24];
// char hostname[24]; ...replaced by OperatingParameters.DeviceName
char ssid[24];
char password[16];

Expand All @@ -90,10 +110,14 @@ typedef struct

} WIFI_STATUS;


extern OPERATING_PARAMETERS OperatingParameters;
extern WIFI_CREDS WifiCreds;
extern int32_t ui_WifiStatusLabel_timestamp;
extern int64_t ui_WifiStatusLabel_timestamp;

#ifdef MQTT_ENABLED
#define MQTT_RECONNECT_DELAY 75000
#endif
#define MOTION_TIMEOUT 10000
#define WIFI_CONNECT_INTERVAL 30000
#define UPDATE_TIME_INTERVAL 60000
Expand All @@ -116,15 +140,25 @@ extern void app_main();
} /*extern "C"*/
#endif

int32_t millis(); // Defined in main.cpp
int64_t millis(); // Defined in main.cpp

void showConfigurationData();
void scanI2cBus();

#ifdef MATTER_ENABLED
bool MatterInit();
#endif

#ifdef MQTT_ENABLED
void MqttInit();
bool MqttConnect();
void MqttUpdateStatusTopic();
void MqttHomeAssistantDiscovery();
#endif

// State Machine
void stateCreateTask();
void serialStart();
extern int32_t lastWifiReconnect;
extern int64_t lastWifiReconnect;

// EEPROM
void eepromInit();
Expand Down Expand Up @@ -157,6 +191,9 @@ void tftCreateTask();
HVAC_MODE strToHvacMode(char *mode);
HVAC_MODE convertSelectedHvacMode();
void setHvacModesDropdown();
#ifdef MQTT_ENABLED
const char *hvacModeToMqttCurrMode(HVAC_MODE mode);
#endif
const char *hvacModeToString(HVAC_MODE mode);
extern volatile bool tftMotionTrigger;

Expand All @@ -176,16 +213,19 @@ void tftDimDisplay();
#endif

// Sensors
void updateHvacMode(HVAC_MODE mode);
void updateHvacSetTemp(float setTemp);
// float roundValue(float value, int places = 0);
float roundValue(float value, int places);
float getRoundedFrac(float value);
void initTimeSntp();
// int degCfrac(float tempF);
// int tempOut(float tempF);
// float tempIn(float tempC);
// float degFtoC(float degF);
void resetTempSmooth();
bool sensorsInit();
void testToggleRelays();
void sensorsInit();
void initRelays();
int getTemp();
int getHumidity();
void ld2410_loop();
Expand All @@ -198,7 +238,7 @@ void audioBeep();

// SNTP Time Sync
void updateTimezone();
bool getLocalTime(struct tm *, uint32_t);
bool getLocalTime(struct tm *, uint64_t);
void updateTimeSntp();

// ui_events.cpp
Expand Down
2 changes: 1 addition & 1 deletion app/include/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#define VERSION_MAJOR 0
#define VERSION_MINOR 6
#define VERSION_MINOR 7
#define VERSION_BUILD 0

#define VERSION_BUILD_DATE __DATE__
Expand Down
4 changes: 4 additions & 0 deletions app/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ build_unflags =
build_flags =
-std=gnu++14
-I include/
;;; -I ~/.platformio/packages/framework-espidf/components/mqtt/esp-mqtt/include/
-D LV_CONF_INCLUDE_SIMPLE
-D MQTT_ENABLED
;; -D MATTER_ENABLED
lib_compat_mode = off ;; To enable Arduino LD2410 library to be included
lib_deps =
rzeldent/micro-timezonedb@^1.0.2
mattfryer/Smoothed@^1.2.0
lvgl/lvgl@^8.3.9
lovyan03/LovyanGFX@^1.1.9
ncmreynolds/ld2410@^0.1.3
bblanchon/ArduinoJson@^6.21.3
debug_init_break = tbreak app_main
monitor_filters =
esp32_exception_decoder
Expand Down
65 changes: 64 additions & 1 deletion app/smart-thermostat.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,68 @@
"path": "."
}
],
"settings": {}
"settings": {
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"netfwd": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
}
Loading