Skip to content

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
budulinek committed Sep 17, 2023
1 parent 7b25a16 commit 3119f37
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 77 deletions.
22 changes: 9 additions & 13 deletions arduino-altherma-controller/01-interfaces.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,12 @@ void (*resetFunc)(void) = 0; //declare reset function at address 0
#ifdef ENABLE_DHCP
void maintainDhcp() {
if (data.config.enableDhcp && dhcpSuccess == true) { // only call maintain if initial DHCP request by startEthernet was successfull
byte maintainResult = Ethernet.maintain();
if (maintainResult == 1 || maintainResult == 3) { // renew failed or rebind failed
dhcpSuccess = false;
startEthernet(); // another DHCP request, fallback to static IP
}
Ethernet.maintain();
}
}
#endif /* ENABLE_DHCP */

#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
void maintainUptime() {
uint32_t milliseconds = millis();
if (last_milliseconds > milliseconds) {
Expand All @@ -96,7 +92,7 @@ void maintainUptime() {
//We add the "remaining_seconds", so that we can continue measuring the time passed from the last boot of the device.
seconds = (milliseconds / 1000) + remaining_seconds;
}
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */

const uint32_t ROLLOVER = 0xFFFFFF00;
bool rollover() {
Expand All @@ -106,7 +102,7 @@ bool rollover() {
return true;
}
}
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
for (byte i = 0; i < UDP_LAST; i++) {
if (data.udpCnt[i] > ROLLOVER) {
return true;
Expand All @@ -115,18 +111,18 @@ bool rollover() {
if (seconds > ROLLOVER) {
return true;
}
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
return false;
}

// resets counters to 0: data.p1p2Cnt, data.udpCnt
void resetStats() {
memset(data.statsDate, 0, sizeof(data.statsDate));
memset(data.p1p2Cnt, 0, sizeof(data.p1p2Cnt));
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
memset(data.udpCnt, 0, sizeof(data.udpCnt));
remaining_seconds = -(millis() / 1000);
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
}

void resetEepromStats() {
Expand Down Expand Up @@ -291,14 +287,14 @@ void manageController() {
cmdQueue.push(0);
indoorInQueue = true;
}
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
if (daikinOutdoor[0] == '\0' && outdoorInQueue == false) {
cmdQueue.push(2);
cmdQueue.push(PACKET_TYPE_OUTDOOR_NAME);
cmdQueue.push(0);
outdoorInQueue = true;
}
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions arduino-altherma-controller/02-UDP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void recvUdp() {
}
Udp.read(command, sizeof(command));
checkCommand(command, byte(udpLen));
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
data.udpCnt[UDP_RECEIVED]++;
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
}
}

Expand Down
8 changes: 4 additions & 4 deletions arduino-altherma-controller/03-P1P2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ void processParseRead(uint16_t n, uint16_t delta) {
Udp.beginPacket(remIp, data.config.udpPort);
Udp.write(RB, n);
Udp.endPacket();
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
data.udpCnt[UDP_SENT]++;
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
}
}
// Parse time and date
Expand Down Expand Up @@ -105,15 +105,15 @@ void processParseRead(uint16_t n, uint16_t delta) {
if (daikinIndoor[0] == '\0') daikinIndoor[0] = '-'; // if response from heat pup is empty, write '-' in order to prevent repeated requests from us
}

#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
if ((RB[0] == 0x40) && (RB[1] == 0x00) && (RB[2] == PACKET_TYPE_OUTDOOR_NAME)) {
for (byte i = 0; i < NAME_SIZE - 1; i++) {
if (RB[i + 4] == 0) break;
daikinOutdoor[i] = RB[i + 4];
}
if (daikinOutdoor[0] == '\0') daikinOutdoor[0] = '-'; // if response from heat pup is empty, write '-' in order to prevent repeated requests from us
}
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */

// check for other auxiliary controllers and get controller ID
if (((RB[1] & 0xFE) == 0xF0) && ((RB[2] & PACKET_TYPE_HANDSHAKE) == PACKET_TYPE_HANDSHAKE)) {
Expand Down
32 changes: 18 additions & 14 deletions arduino-altherma-controller/05-pages.ino
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ void contentInfo(ChunkedPrint &chunked) {
}
tagDivClose(chunked);

#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
tagLabelDiv(chunked, F("Ethernet Sockets"));
chunked.print(maxSockNum);
tagDivClose(chunked);
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */

tagLabelDiv(chunked, F("MAC Address"));
for (byte i = 0; i < 6; i++) {
Expand Down Expand Up @@ -269,11 +269,11 @@ void contentStatus(ChunkedPrint &chunked) {
tagLabelDiv(chunked, F("Daikin Indoor Unit"));
tagSpan(chunked, JSON_DAIKIN_INDOOR);
tagDivClose(chunked);
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
tagLabelDiv(chunked, F("Daikin Outdoor Unit"));
tagSpan(chunked, JSON_DAIKIN_OUTDOOR);
tagDivClose(chunked);
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
tagLabelDiv(chunked, F("Date"));
tagSpan(chunked, JSON_DATE);
tagDivClose(chunked);
Expand Down Expand Up @@ -308,21 +308,21 @@ void contentStatus(ChunkedPrint &chunked) {
tagSpan(chunked, JSON_WRITE_P1P2);
tagDivClose(chunked);
chunked.print(F("</form><form method=post>"));
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
tagLabelDiv(chunked, F("Run Time"));
tagSpan(chunked, JSON_RUNTIME);
tagDivClose(chunked);
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
tagLabelDiv(chunked, F("P1P2 Packets"));
tagButton(chunked, F("Reset"), ACT_RESET_STATS);
chunked.print(F(" Stats since "));
tagSpan(chunked, JSON_P1P2_STATS);
tagDivClose(chunked);
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
tagLabelDiv(chunked, F("UDP Messages"));
tagSpan(chunked, JSON_UDP_STATS);
tagDivClose(chunked);
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
}

// IP Settings
Expand Down Expand Up @@ -403,7 +403,7 @@ void contentP1P2(ChunkedPrint &chunked) {
tagSelect(chunked, POST_CONTROL_MODE, optionsList, 3, data.config.controllerMode);
tagDivClose(chunked);
tagLabelDiv(chunked, F("Connection Timeout"));
tagInputNumber(chunked, POST_TIMEOUT, F0THRESHOLD, 60, data.config.connectTimeout, F("secs"));
tagInputNumber(chunked, POST_TIMEOUT, F0THRESHOLD, 60, data.config.connectTimeout, F("s"));
tagDivClose(chunked);
tagLabelDiv(chunked, F("EEPROM Write Quota"));
tagInputNumber(chunked, POST_QUOTA, 0, 100, data.config.writeQuota, F("writes per day"));
Expand Down Expand Up @@ -639,7 +639,7 @@ void stringDate(ChunkedPrint &chunked, byte myDate[]) {

void jsonVal(ChunkedPrint &chunked, const byte JSONKEY) {
switch (JSONKEY) {
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
case JSON_RUNTIME:
chunked.print(seconds / (3600UL * 24L));
chunked.print(F(" days, "));
Expand Down Expand Up @@ -668,19 +668,19 @@ void jsonVal(ChunkedPrint &chunked, const byte JSONKEY) {
}
}
break;
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
case JSON_DAIKIN_INDOOR:
{
chunked.print(daikinIndoor);
}
break;
#ifdef ENABLE_EXTRA_DIAG
#ifdef ENABLE_EXTENDED_WEBUI
case JSON_DAIKIN_OUTDOOR:
{
chunked.print(daikinOutdoor);
}
break;
#endif /* ENABLE_EXTRA_DIAG */
#endif /* ENABLE_EXTENDED_WEBUI */
case JSON_DATE:
{
stringDate(chunked, date);
Expand All @@ -692,7 +692,11 @@ void jsonVal(ChunkedPrint &chunked, const byte JSONKEY) {
chunked.print(F("<br>"));
chunked.print(data.eepromDaikin.total);
chunked.print(F(" Total Commands<br>"));
chunked.print((uint16_t)(data.eepromDaikin.total / (days(date) - days(data.eepromDaikin.date) + 1)));
if (date[5] != 0) { // day can not be zero
chunked.print((uint16_t)(data.eepromDaikin.total / (days(date) - days(data.eepromDaikin.date) + 1)));
} else {
chunked.print(F("-"));
}
chunked.print(F(" Daily Average (should be bellow 19)<br>"));
chunked.print(data.eepromDaikin.yesterday);
chunked.print(F(" Yesterday<br>"));
Expand Down
82 changes: 47 additions & 35 deletions arduino-altherma-controller/advanced_settings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
/* Advanced settings, extra functions and default config forDaikin P1P2 ⇔ UDP Gateway
/* Advanced settings, extra functions and default config
*/

/****** FUNCTIONALITY ******/

// #define ENABLE_EXTENDED_WEBUI // Enable extended Web UI (additional items and settings), consumes FLASH memory
// uncomment ENABLE_EXTENDED_WEBUI if you have a board with large FLASH memory (Arduino Mega)

// #define ENABLE_DHCP // Enable DHCP (Auto IP settings), consumes a lot of FLASH memory


/****** DEFAULT CONFIGURATION ******/
/*
Arduino loads user settings stored in EEPROM, even if you flash new program to it.
Arduino loads factory defaults if:
1) User clicks "Load default settings" in WebUI (factory reset configuration, keeps MAC)
2) VERSION_MAJOR changes (factory reset configuration AND generates new MAC)
*/

/****** IP Settings ******/
const bool DEFAULT_AUTO_IP = false; // Default Auto IP setting (only used if ENABLE_DHCP)
#define DEFAULT_STATIC_IP \
{ 192, 168, 1, 254 } // Default Static IP
#define DEFAULT_SUBMASK \
{ 255, 255, 255, 0 } // Default Submask
#define DEFAULT_GATEWAY \
{ 192, 168, 1, 1 } // Default Gateway
#define DEFAULT_DNS \
{ 192, 168, 1, 1 } // Default DNS Server (only used if ENABLE_DHCP)

/****** TCP/UDP Settings ******/
#define DEFAULT_REMOTE_IP \
{ 192, 168, 1, 22 } // Default Remote IP (only used if ENABLE_EXTENDED_WEBUI)
const bool DEFAULT_BROADCAST = true; // Default UDP Broadcast setting (Send and Receive UDP)
const uint16_t DEFAULT_UDP_PORT = 10000; // Default UDP Port
const uint16_t DEFAULT_WEB_PORT = 80; // Default WebUI Port

/****** P1P2 Settings ******/
const byte DEFAULT_COTROLLER_MODE = CONTROL_MANUAL; // Default Controller Mode (CONTROL_DISABLED, CONTROL_MANUAL or CONTROL_AUTO)
const byte DEFAULT_EEPROM_QUOTA = 24; // Default EEPROM Write Quota
const byte DEFAUT_TEMPERATURE_HYSTERESIS = 1; // Default Target Temperature Hysteresis

/****** Packet Filter ******/
const bool DEFAULT_SEND_ALL = false; // Default Send All Packet Types
const byte DEFAULT_COUNTER_PERIOD = 10; // Default Counters Packet Request Period
const byte DEFAULT_DATA_PACKETS_MODE = DATA_CHANGE_AND_REQUEST; // Default Data Packets Mode (DATA_ALWAYS, DATA_CHANGE_AND_REQUEST or DATA_ONLY_CHANGE)


/****** ADVANCED SETTINGS ******/

const byte MAX_QUEUE_DATA = 64; // total length of UDP commands stored in a queue (in bytes)
Expand Down Expand Up @@ -51,37 +97,3 @@ const uint16_t FETCH_INTERVAL = 2000; // Fetch API interval (ms) for
const byte DATA_START = 96; // Start address where config and counters are saved in EEPROM
const byte EEPROM_INTERVAL = 6; // Interval (hours) for saving Modbus statistics to EEPROM (in order to minimize writes to EEPROM)

/****** EXTRA FUNCTIONS ******/

// these do not fit into the limited flash memory of Arduino Uno/Nano, uncomment if you have a board with more memory
// #define ENABLE_DHCP // Enable DHCP (Auto IP settings)
// #define ENABLE_EXTRA_DIAG // Enable outdoor unit name, runtime counter and UDP statistics.

/****** DEFAULT FACTORY SETTINGS ******/

/*
Please note that after boot, Arduino loads user settings stored in EEPROM, even if you flash new program to it!
Arduino loads factory defaults if:
1) User clicks "Load default settings" in WebUI (factory reset configuration, keeps MAC)
2) VERSION_MAJOR changes (factory reset configuration AND generates new MAC)
*/
const config_t DEFAULT_CONFIG = {
{ 192, 168, 1, 254 }, // ip
{ 255, 255, 255, 0 }, // subnet
{ 192, 168, 1, 1 }, // gateway
{ 192, 168, 1, 1 }, // Dns (only used if ENABLE_DHCP)
false, // enableDhcp (only used if ENABLE_DHCP)
{ 192, 168, 1, 22 }, // remoteIp
true, // udpBroadcast
503, // udpPort
80, // webPort
CONTROL_MANUAL, // controllerMode
(F0THRESHOLD * 2), // connectTimeout
false, // notSupported
1, // hysteresis
24, // writeQuota
false, // sendAllPackets
10, // counterPeriod
DATA_CHANGE_AND_REQUEST, // sendDataPackets
{} // packetStatus
};
Loading

0 comments on commit 3119f37

Please sign in to comment.