Skip to content

Commit

Permalink
- [breakable change] refactoring userconfig from EEPROM to local json…
Browse files Browse the repository at this point in the history
… file incl. web config interface

- introduce another display (GAGC9A01 round TFT 1.28)
- implement a better factory mode with display support
- extend the docs
  • Loading branch information
ohAnd committed Jun 5, 2024
1 parent 027a4ff commit b279666
Show file tree
Hide file tree
Showing 18 changed files with 1,007 additions and 231 deletions.
Binary file added doc/images/dtuGateay_OLED.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/dtuGateay_OLED_firstStart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/roundTFT.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/roundTFT_firstSTart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 57 additions & 26 deletions include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,71 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <EEPROM.h>
#include <Arduino.h>
#include <ArduinoJson.h>
#include <LittleFS.h>

#define EEPROM_INIT_PATTERN 0xAA
#define CONFIG_FILE_PATH "/userconfig.json"

struct UserConfig
{
char dtuSsid[64];
char dtuPassword[64];
char wifiSsid[64];
char wifiPassword[64];
char dtuHostIp[16];
char openhabHostIp[16];
char openItemPrefix[32];
boolean openhabActive;
char mqttBrokerIp[16];
int mqttBrokerPort;
char mqttBrokerUser[64];
char mqttBrokerPassword[64];
char mqttBrokerMainTopic[32];
boolean mqttActive;
int dtuCloudPauseTime;
boolean dtuCloudPauseActive;
int dtuUpdateTime;
boolean wifiAPstart;
int selectedUpdateChannel; // 0 - release 1 - snapshot
byte eepromInitialized; // specific pattern to determine floating state in EEPROM from Factory
char dtuSsid[64] = "DTUBI-12345678";
char dtuPassword[64] = "dtubiPassword";

char wifiSsid[64] = "mySSID";
char wifiPassword[64] = "myPassword";

char dtuHostIpDomain[128] = "192.168.0.254";
int dtuCloudPauseTime = 40;
boolean dtuCloudPauseActive = true;
int dtuUpdateTime = 31;

char openhabHostIpDomain[128] = "192.168.1.100";
char openItemPrefix[32] = "inverter";
boolean openhabActive = 0;

char mqttBrokerIpDomain[128] = "192.168.1.100";
int mqttBrokerPort = 1883;
char mqttBrokerUser[64] = "dtuuser";
char mqttBrokerPassword[64] = "dtupass";
char mqttBrokerMainTopic[32] = "dtu1";
boolean mqttActive = false;

uint8_t displayConnected = 0; // OLED default

boolean wifiAPstart = true;
int selectedUpdateChannel = 0; // 0 - release 1 - snapshot
int timezoneOffest = 7200; // default CEST
};

extern UserConfig userConfig;

void saveConfigToEEPROM();
void loadConfigFromEEPROM();
void initializeEEPROM();
void printEEPROMdata();
// struct for web update
typedef struct keyAndValue_
{
char key[30];
String value;
} keyAndValue_t;

// Define the UserConfigManager class
class UserConfigManager {
public:
UserConfigManager(const char *filePath = CONFIG_FILE_PATH, const UserConfig &defaultConfig = UserConfig());
bool begin();
bool loadConfig(UserConfig &config);
void saveConfig(const UserConfig &config);
void resetConfig();
void printConfigdata();
// String getWebHandler(keyAndValue_t* keyValueWebClient, unsigned int size);
String getWebHandler(JsonDocument doc);


private:
const char *filePath;
UserConfig defaultConfig;
JsonDocument mappingStructToJson();
void mappingJsonToStruct(JsonDocument doc);
String createWebPage(bool updated);
};

#endif // CONFIG_H
1 change: 1 addition & 0 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Display {
Display();
void setup();
void renderScreen(String time, String version);
void drawFactoryMode(String version, String apName, String ip);
private:
void drawScreen();
void drawHeader();
Expand Down
57 changes: 57 additions & 0 deletions include/displayTFT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef DISPLAYTFT_H
#define DISPLAYTFT_H

#include <SPI.h>
#include <TFT_eSPI.h>

// TFT display

#define BRIGHTNESS_MIN 50
#define BRIGHTNESS_MAX 250

#define DARKER_GREY 0x18E3
#define SPECIAL_BLUE 0x24ae

struct DisplayDataTFT {
int16_t totalPower=0; // indicate current power (W)
float totalYieldDay=0.0f; // indicate day yield (Wh)
float totalYieldTotal=0.0f; // indicate total yield (kWh)
const char *formattedTime=nullptr;
const char *version=nullptr;
uint8_t powerLimit=0;
uint8_t rssiGW=0;
uint8_t rssiDTU=0;
bool stateWasOffline=false;
bool stateWasCloudPause=true;
bool stateWasNormal=false;
};

class DisplayTFT {
public:
DisplayTFT();
void setup();
void renderScreen(String time, String version);
void drawFactoryMode(String version, String apName, String ip);
private:
void drawScreen(String version, String time);
void drawHeader(String version);
void drawFooter(String time);

void drawMainDTUOnline(bool pause=false);
void drawMainDTUOffline();

void screenSaver();
void checkChangedValues();

void drawIcon(const uint16_t *icon, int16_t x, int16_t y, int16_t w, int16_t h);

// private member variables
DisplayDataTFT lastDisplayData;
uint8_t brightness=BRIGHTNESS_MIN;
uint8_t offset_x = 0; // shifting for anti burn in effect
uint8_t offset_y = 0; // shifting for anti burn in effect
bool valueChanged = false;
uint16_t displayTicks = 0; // local timer state machine
};

#endif // DISPLAYTFT_H
2 changes: 1 addition & 1 deletion include/dtuInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct inverterData
extern inverterData globalData;

extern CRC16 crc;
void dtuConnectionEstablish(WiFiClient *localDtuClient, char localDtuHostIp[16], uint16_t localDtuPort = 10081);
void dtuConnectionEstablish(WiFiClient *localDtuClient, char localdtuHostIpDomain[16], uint16_t localDtuPort = 10081);
void dtuConnectionStop(WiFiClient *localDtuClient, uint8_t tgtState);
void dtuConnectionHandleError(WiFiClient *localDtuClient, unsigned long locTimeSec, uint8_t errorState = DTU_ERROR_NO_ERROR);

Expand Down
34 changes: 17 additions & 17 deletions include/index_html.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title id="title">HoymilesGW</title>
<title id="title">dtuGateway</title>
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="style.css">
Expand All @@ -19,7 +19,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
</div>
<div class="popup" id="changeSettings">
<div class="popupHeader">
<div class="popupHeaderTitle">settings
<div class="popupHeaderTitle">settings <i style="font-size: x-small;float:right;"><a href="/config" target=_blank>advanced config</a></i>
<!-- <h2>settings</h2> -->
</div>
<div class="popupHeaderTabs">
Expand Down Expand Up @@ -112,7 +112,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
dtu host IP in your local network:
</div>
<div>
<input type="text" id="dtuHostIp" class="ipv4Input" name="ipv4" placeholder="xxx.xxx.xxx.xxx">
<input type="text" id="dtuHostIpDomain" class="ipv4Input" name="ipv4" placeholder="xxx.xxx.xxx.xxx">
</div>
<hr>
<div>
Expand Down Expand Up @@ -628,7 +628,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
dtuData = cacheInfoData.dtuConnection;
// get networkdata
$('#dtuHostIp').val(dtuData.dtuHostIp);
$('#dtuHostIpDomain').val(dtuData.dtuHostIpDomain);
$('#dtuDataCycle').val(dtuData.dtuDataCycle);
if (dtuData.dtuCloudPause) {
$('#dtuCloudPause').prop("checked", true);
Expand Down Expand Up @@ -733,7 +733,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
}
function changeDtuData() {
var dtuHostIpSend = $('#dtuHostIp').val();
var dtuHostIpDomainSend = $('#dtuHostIpDomain').val();
var dtuDataCycleSend = $('#dtuDataCycle').val();
if ($("#dtuCloudPause").is(':checked')) {
dtuCloudPauseSend = 1;
Expand All @@ -745,13 +745,13 @@ const char INDEX_HTML[] PROGMEM = R"=====(
var dtuPasswordSend = $('#dtuPassword').val();
var data = {};
data["dtuHostIpSend"] = dtuHostIpSend;
data["dtuHostIpDomainSend"] = dtuHostIpDomainSend;
data["dtuDataCycleSend"] = dtuDataCycleSend;
data["dtuCloudPauseSend"] = dtuCloudPauseSend;
data["dtuSsidSend"] = dtuSsidSend;
data["dtuPasswordSend"] = dtuPasswordSend;
console.log("send to server: dtuHostIp: " + dtuHostIpSend + " dtuDataCycle: " + dtuDataCycleSend + " dtuCloudPause: " + dtuCloudPauseSend + " - dtuSsid: " + dtuSsidSend + " - pass: " + dtuPasswordSend);
console.log("send to server: dtuHostIpDomain: " + dtuHostIpDomainSend + " dtuDataCycle: " + dtuDataCycleSend + " dtuCloudPause: " + dtuCloudPauseSend + " - dtuSsid: " + dtuSsidSend + " - pass: " + dtuPasswordSend);
const urlEncodedDataPairs = [];
Expand All @@ -777,11 +777,11 @@ const char INDEX_HTML[] PROGMEM = R"=====(
strResult = JSON.parse(xmlHttp.responseText);
console.log("got from server: " + strResult);
console.log("got from server - strResult.dtuHostIp: " + strResult.dtuHostIp + " - cmp with: " + dtuHostIpSend);
console.log("got from server - strResult.dtuHostIpDomain: " + strResult.dtuHostIpDomain + " - cmp with: " + dtuHostIpDomainSend);
console.log("got from server - strResult.dtuSsid: " + strResult.dtuSsid + " - cmp with: " + dtuSsidSend);
console.log("got from server - strResult.dtuPassword: " + strResult.dtuHostIp + " - cmp with: " + dtuPasswordSend);
console.log("got from server - strResult.dtuPassword: " + strResult.dtuHostIpDomain + " - cmp with: " + dtuPasswordSend);
if (strResult.dtuHostIp == dtuHostIpSend && strResult.dtuSsid == dtuSsidSend && strResult.dtuPassword == dtuPasswordSend) {
if (strResult.dtuHostIpDomain == dtuHostIpDomainSend && strResult.dtuSsid == dtuSsidSend && strResult.dtuPassword == dtuPasswordSend) {
console.log("check saved data - OK");
alert("dtu Settings change\n__________________________________\n\nYour settings were successfully changed.\n\nClient connection will be reconnected to the new IP.");
} else {
Expand All @@ -796,7 +796,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
}
function changeBindingsData() {
var openhabHostIpSend = $('#openhabIP').val();
var openhabHostIpDomainSend = $('#openhabIP').val();
var openhabPrefixSend = $('#ohItemPrefix').val();
if ($("#openhabActive").is(':checked')) {
openhabActiveSend = 1;
Expand All @@ -822,7 +822,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
}
var data = {};
data["openhabHostIpSend"] = openhabHostIpSend;
data["openhabHostIpDomainSend"] = openhabHostIpDomainSend;
data["openhabPrefixSend"] = openhabPrefixSend;
data["openhabActiveSend"] = openhabActiveSend;
Expand All @@ -833,7 +833,7 @@ const char INDEX_HTML[] PROGMEM = R"=====(
data["mqttMainTopicSend"] = mqttMainTopicSend;
data["mqttActiveSend"] = mqttActiveSend;
console.log("send to server: openhabHostIpSend: " + openhabHostIpSend);
console.log("send to server: openhabHostIpDomainSend: " + openhabHostIpDomainSend);
const urlEncodedDataPairs = [];
Expand All @@ -859,9 +859,9 @@ const char INDEX_HTML[] PROGMEM = R"=====(
strResult = JSON.parse(xmlHttp.responseText);
console.log("got from server: " + strResult);
console.log("got from server - strResult.dtuHostIp: " + strResult.openhabHostIp + " - cmp with: " + openhabHostIpSend);
console.log("got from server - strResult.dtuHostIpDomain: " + strResult.openhabHostIpDomain + " - cmp with: " + openhabHostIpDomainSend);
if (strResult.openhabHostIp == openhabHostIpSend && strResult.mqttBrokerIp == mqttIpSend && strResult.mqttBrokerUser == mqttUserSend) {
if (strResult.openhabHostIpDomain == openhabHostIpDomainSend && strResult.mqttBrokerIpDomain == mqttIpSend && strResult.mqttBrokerUser == mqttUserSend) {
console.log("check saved data - OK");
alert("bindings Settings change\n__________________________________\n\nYour settings were successfully changed.\n\nChanges will be applied.");
} else {
Expand Down Expand Up @@ -917,9 +917,9 @@ const char INDEX_HTML[] PROGMEM = R"=====(
try {
strResult = JSON.parse(xmlHttp.responseText);
console.log("got from server: " + strResult);
console.log("got from server - strResult.dtuHostIp: " + strResult.dtuHostIp + " - cmp with: " + dtuHostIpSend);
console.log("got from server - strResult.dtuHostIpDomain: " + strResult.dtuHostIpDomain + " - cmp with: " + dtuHostIpDomainSend);
if (strResult.dtuHostIp == dtuHostIpSend && strResult.dtuSsid == dtuSsidSend && strResult.dtuPassword == dtuPasswordSend) {
if (strResult.dtuHostIpDomain == dtuHostIpDomainSend && strResult.dtuSsid == dtuSsidSend && strResult.dtuPassword == dtuPasswordSend) {
console.log("check saved data - OK");
alert("dtu Settings change\n__________________________________\n\nYour settings were successfully changed.\n\nClient connection will be reconnected to the new IP.");
} else {
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 "1.5.0_localDev"
#define BUILDTIME "01.06.2024 - 17:49:18"
#define BUILDTIMESTAMP "1717256958"
#define VERSION "1.6.0_localDev"
#define BUILDTIME "05.06.2024 - 19:12:17"
#define BUILDTIMESTAMP "1717607537"
8 changes: 4 additions & 4 deletions include/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.5.0_localDev",
"versiondate": "01.06.2024 - 17:49:18",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.5.0_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway//releases/latest/download/dtuGateway_release_1.5.0_localDev.bin"
"version": "1.6.0_localDev",
"versiondate": "05.06.2024 - 19:12:17",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.6.0_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway//releases/latest/download/dtuGateway_release_1.6.0_localDev.bin"
}
12 changes: 12 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib_deps =
me-no-dev/ESPAsyncTCP @ ^1.2.2
me-no-dev/ESP Async WebServer @ ^1.2.3
olikraus/U8g2 @ ^2.35.19
bodmer/TFT_eSPI @ ^2.5.43
custom_nanopb_protos =
+<include/proto/AppGetHistPower.proto>
+<include/proto/RealtimeDataNew.proto>
Expand All @@ -35,3 +36,14 @@ monitor_filters =
esp8266_exception_decoder
default
time
build_flags =
; Define the TFT driver, pins etc. here:
-DGC9A01_DRIVER=1
-DTFT_WIDTH=240
-DTFT_HEIGHT=240
-DTFT_MISO=12
-DTFT_MOSI=13
-DTFT_SCLK=14
-DTFT_CS=18
-DTFT_DC=0
-DTFT_RST=-1
Loading

0 comments on commit b279666

Please sign in to comment.