Skip to content

Commit

Permalink
imrpovements for monitor mode + implementing Im Status "try reconnect…
Browse files Browse the repository at this point in the history
…" wird die "cloud pause" nicht eingehalten (v1.9.0049) #54
  • Loading branch information
ohAnd committed Oct 9, 2024
1 parent c86f435 commit fbb5fe3
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 127 deletions.
4 changes: 1 addition & 3 deletions include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ struct UserConfig
uint8_t displayBrightnessDay = 100;
uint8_t displayBrightnessNight = 10;
boolean displayNightClock = false; // in night mode: true - display clock/ false - display dark screen

boolean displayNightMode = false; // night mode enabled
boolean displayNightModeOfflineTrigger = false; // night mode triggered by offline state
uint16_t displayNightmodeStart = 1320; // 22:00 = 22 * 60 = 1320
uint16_t displayNightmodeEnd = 360; // 06:00 = 6 * 60 = 360



boolean wifiAPstart = true;
int selectedUpdateChannel = 0; // 0 - release 1 - snapshot
int timezoneOffest = 7200; // default CEST
Expand Down
7 changes: 5 additions & 2 deletions include/dtuInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct connectionControl
{
boolean preventCloudErrors = true;
boolean dtuActiveOffToCloudUpdate = false;
boolean dtuConnectionOnline = true; // true if connection is online as valued a summary
uint8_t dtuConnectState = DTU_STATE_OFFLINE;
uint8_t dtuErrorState = DTU_ERROR_NO_ERROR;
uint8_t dtuTxRxState = DTU_TXRX_STATE_IDLE;
Expand Down Expand Up @@ -142,12 +143,14 @@ class DTUInterface {
void initializeCRC();

static void txrxStateObserver();

boolean lastOnlineOfflineState = false;
unsigned long lastOnlineOfflineChange = 0;
void dtuConnectionObserver();

void checkingDataUpdate();
void checkingForLastDataReceived();
boolean cloudPauseActiveControl();

// Protobuf functions
void writeReqAppGetHistPower();
void readRespAppGetHistPower(pb_istream_t istream);
Expand Down
1 change: 1 addition & 0 deletions include/mqttHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct RemoteInverterData
uint32_t dtuRssi = 0;
uint32_t wifi_rssi_gateway = 0;
boolean cloudPause = false;
boolean dtuConnectionOnline = false;
uint8_t dtuConnectState = 0;
uint32_t respTimestamp = 1704063600; // init with start time stamp > 0
boolean updateReceived = false;
Expand Down
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION "2.0.117_localDev"
#define BUILDTIME "13.09.2024 - 21:47:24"
#define BUILDTIMESTAMP "1726256844"
#define VERSION "2.0.150_localDev"
#define BUILDTIME "09.10.2024 - 09:02:52"
#define BUILDTIMESTAMP "1728457372"
8 changes: 4 additions & 4 deletions include/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "2.0.117_localDev",
"versiondate": "13.09.2024 - 21:47:24",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_2.0.117_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_2.0.117_localDev.bin"
"version": "2.0.150_localDev",
"versiondate": "09.10.2024 - 09:02:52",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_2.0.150_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_2.0.150_localDev.bin"
}
21 changes: 12 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,23 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract
- brightness day [0...255] - will also be used without night mode enabled for standard brightness (falling back to this after power value changed)
- brightness night [0...255] - note: 0 = backlight off
- (to disable PWM control for TFT without backlight control set both brightness values to zero)
- night clock - on/off - if enabled the clock will be shown at night, otherwise blank or dark screen at night
- night mode enabled on/ off
- night mode OfflineTrigger on/off - the night mode will be additionally to the schedule triggered, if dtu is offline
- night mode start in minutes to start of the day - e.g. 1320 for 22:00
- night mode stop in minutes to start of the day - e.g. 360 for 6:00
- night clock enabled on/ off - on = clock will be displayed instead of dark screen
- example settings:

| setting | value | comment |
|-----------------|-------|---------
| brightnessDay | 150 | note: 255 - ~150 only difficult to perceive
| brightnessNight | 30 |
| nightClock | true | show the clock instead of black screen during night time
| nightMode | true | night mode is enabled
| nightmodeStart | 1320 | night time will start at 22 o'clock
| nightmodeEnd | 390 | night time will end at 6:30
| setting | value | comment |
|-------------------------|-------|---------
| brightnessDay | 150 | note: 255 - ~150 only difficult to perceive
| brightnessNight | 30 |
| nightClock | true | show the clock instead of black screen during night (and/ or offline)
| nightMode | true | night mode is enabled
| nightModeOfflineTrigger | true | night mode will be also triggered if dtu is offline
| nightmodeStart | 1320 | night time will start at 22 o'clock
| nightmodeEnd | 390 | night time will end at 6:30


- display hardware types
Expand Down Expand Up @@ -392,7 +395,7 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract
| ESP-WROOM-32 NodeMCU-32S | ESP32 | 3.3V | GND | D22/GPIO22/SCL | D21/GPIO21/SDA | OK |

- optional display GC9A01 round TFT 1,28" 240x240 (e.g. [link](https://de.aliexpress.com/i/1005006190625792.html)):
- connect SSH1106 driven round TFT display (240x240) with your ESP8266/ ESP32 board (VCC, GND, SCL, SDA, DC, CS, RST)
- connect GC9A01 driven round TFT display (240x240) with your ESP8266/ ESP32 board (VCC, GND, SCL, SDA, DC, CS, RST, BLK)
- pinning for different boards (display connector to ESPxx board pins)
- BLK = backlight control - will be served with PWM via GPIO 4

Expand Down
4 changes: 4 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ void UserConfigManager::printConfigdata()
Serial.println(userConfig.displayNightClock);
Serial.print(F("display night mode: \t\t"));
Serial.println(userConfig.displayNightMode);
Serial.print(F("display night mode offline trigger: \t"));
Serial.println(userConfig.displayNightModeOfflineTrigger);
Serial.print(F("display nightmode start: \t"));
Serial.println(userConfig.displayNightmodeStart);
Serial.print(F("display nightmode end: \t\t"));
Expand Down Expand Up @@ -216,6 +218,7 @@ JsonDocument UserConfigManager::mappingStructToJson(const UserConfig &config)
doc["display"]["brightnessNight"] = config.displayBrightnessNight;
doc["display"]["nightClock"] = config.displayNightClock;
doc["display"]["nightMode"] = config.displayNightMode;
doc["display"]["nightModeOfflineTrigger"] = config.displayNightModeOfflineTrigger;
doc["display"]["nightmodeStart"] = config.displayNightmodeStart;
doc["display"]["nightmodeEnd"] = config.displayNightmodeEnd;

Expand Down Expand Up @@ -259,6 +262,7 @@ void UserConfigManager::mappingJsonToStruct(JsonDocument doc)
userConfig.displayBrightnessNight = doc["display"]["brightnessNight"];
userConfig.displayNightClock = doc["display"]["nightClock"];
userConfig.displayNightMode = doc["display"]["nightMode"];
userConfig.displayNightModeOfflineTrigger = doc["display"]["nightModeOfflineTrigger"].as<bool>();
userConfig.displayNightmodeStart = doc["display"]["nightmodeStart"];
userConfig.displayNightmodeEnd = doc["display"]["nightmodeEnd"];

Expand Down
46 changes: 35 additions & 11 deletions src/displayTFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ void DisplayTFT::drawScreen(String version, String time)
drawMainDTUOnline(true);
displayState = 0;
}
// else if (lastDisplayData.remoteDisplayActive)
// {
// drawMainDTUOnline();
// displayState = 2;
// }
else if (dtuConnection.dtuConnectState == DTU_STATE_OFFLINE || dtuConnection.dtuConnectState == DTU_STATE_TRY_RECONNECT || dtuConnection.dtuConnectState == DTU_STATE_CONNECT_ERROR || dtuConnection.dtuConnectState == DTU_STATE_STOPPED)
else if (dtuConnection.dtuConnectionOnline == false)
{
drawMainDTUOffline();
displayState = 3;
Expand Down Expand Up @@ -376,30 +371,59 @@ void DisplayTFT::setBrightnessAuto()

void DisplayTFT::checkNightMode()
{
boolean isNightBySchedule = false;
boolean isNightByOffline = false;
// get currentTime in minutes to 00:00 of current day from current time in minutes to 1.1.1970 00:00
uint16_t currentTime = (platformData.currentNTPtime / 60) % 1440;
// Serial.println("current time in minutes today: " + String(currentTime) + " - start: " + String(userConfig.displayNightmodeStart) + " - end: " + String(userConfig.displayNightmodeEnd) + " - current brightness: " + String(brightness) + " - dtuState: " + String(dtuConnection.dtuConnectState) + " night: " + String(isNight));
if (userConfig.displayNightMode)
{
// schedule trigger
// check if night mode can be activated - start time is smaller than end time
if (
(userConfig.displayNightmodeStart < userConfig.displayNightmodeEnd && currentTime >= userConfig.displayNightmodeStart && currentTime < userConfig.displayNightmodeEnd) ||
(userConfig.displayNightmodeStart > userConfig.displayNightmodeEnd && (currentTime >= userConfig.displayNightmodeStart || currentTime < userConfig.displayNightmodeEnd)))
{
// Serial.println(" >> night mode active");
isNightBySchedule = true;
// Serial.println("DisplayTFT:\t >> night mode activated by schedule");
}
else
{
isNightBySchedule = false;
// Serial.println("DisplayTFT:\t >> day mode activated by schedule");
}

// offline trigger
if (dtuConnection.dtuConnectionOnline == true)
{
isNightByOffline = false;
// Serial.println("DisplayTFT:\t >> night mode activated by offline trigger");
}
else if (dtuConnection.dtuConnectionOnline == false)
{
isNightByOffline = true;
// Serial.println("DisplayTFT:\t >> day mode activated by offline trigger");
}

// summary
// start night mode if schedule or offline trigger (when enabled) is active
if (isNightBySchedule || (userConfig.displayNightModeOfflineTrigger && isNightByOffline))
{
if (!isNight)
{
isNight = true;
Serial.println("DisplayTFT:\t >> night mode activated");
Serial.println("DisplayTFT:\t >> night mode activated - schedule: " + String(isNightBySchedule) + " - offline: " + String(isNightByOffline));
}
}
else
// start day mode if
// offline trigger is enabled and schedule is not active and offline is not active OR
// offline trigger is dsiabled and schedule is not active
else if ((userConfig.displayNightModeOfflineTrigger && !isNightBySchedule && !isNightByOffline) || (!userConfig.displayNightModeOfflineTrigger && !isNightBySchedule))
{
// Serial.println(" >> day mode active");
if (isNight)
{
isNight = false;
Serial.println("DisplayTFT:\t >> day mode activated");
Serial.println("DisplayTFT:\t >> day mode activated - schedule: " + String(isNightBySchedule) + " - offline: " + String(isNightByOffline));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/dtuGateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ void updateValuesToMqtt(boolean haAutoDiscovery = false)
keyValueStore["inverter_PowerLimit"] = String(dtuGlobalData.powerLimit).c_str();
keyValueStore["inverter_WifiRSSI"] = String(dtuGlobalData.dtuRssi).c_str();
keyValueStore["inverter_cloudPause"] = String(dtuConnection.dtuActiveOffToCloudUpdate).c_str();
keyValueStore["inverter_dtuConnectionOnline"] = String(dtuConnection.dtuConnectionOnline).c_str();
keyValueStore["inverter_dtuConnectState"] = String(dtuConnection.dtuConnectState).c_str();
// copy
for (const auto &pair : keyValueStore)
Expand Down Expand Up @@ -1205,10 +1206,9 @@ void loop()
dtuGlobalData.powerLimit = remoteData.powerLimit;
dtuGlobalData.dtuRssi = remoteData.dtuRssi;

if (remoteData.cloudPause)
dtuConnection.dtuActiveOffToCloudUpdate = true;
else
dtuConnection.dtuActiveOffToCloudUpdate = false;
dtuConnection.dtuActiveOffToCloudUpdate = remoteData.cloudPause;
dtuConnection.dtuConnectionOnline = remoteData.dtuConnectionOnline;

dtuConnection.dtuConnectState = remoteData.dtuConnectState;
dtuGlobalData.lastRespTimestamp = remoteData.respTimestamp;
dtuGlobalData.currentTimestamp = remoteData.respTimestamp; // setting the local counter
Expand Down Expand Up @@ -1264,7 +1264,7 @@ void loop()
if (dtuConnection.dtuActiveOffToCloudUpdate)
blinkCode = BLINK_PAUSE_CLOUD_UPDATE;

if (userConfig.openhabActive) // && dtuConnection.dtuConnectState == DTU_STATE_CONNECTED)
if (userConfig.openhabActive && !userConfig.remoteDisplayActive)
getPowerSetDataFromOpenHab();

// direct request of new powerLimit
Expand Down
Loading

0 comments on commit fbb5fe3

Please sign in to comment.