Skip to content

Commit

Permalink
Merge last develop into migrate_ESP32 - fixing littlefs init on facto…
Browse files Browse the repository at this point in the history
…ry state - fixing webpage stream - basic features config, first setup, web page, OLED for both arch ok
  • Loading branch information
ohAnd committed Jun 22, 2024
2 parents 6b09b32 + 8e5581a commit 463a748
Show file tree
Hide file tree
Showing 24 changed files with 2,123 additions and 436 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
1 change: 1 addition & 0 deletions .github/workflows/feature_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dtuGateway_snapshot_${{ env.CURRENT_VERSIONNUMBER }}
path: |
.pio/build/dtuGateway_snapshot_${{ env.CURRENT_VERSIONNUMBER }}.bin
.pio/build/dtuGateway_ESP32_snapshot_${{ env.CURRENT_VERSIONNUMBER }}.bin
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.
78 changes: 52 additions & 26 deletions include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,66 @@
#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;
boolean mqttUseTLS = false;
char mqttBrokerUser[64] = "dtuuser";
char mqttBrokerPassword[64] = "dtupass";
char mqttBrokerMainTopic[32] = "dtu_12345678";
boolean mqttHAautoDiscoveryON = false;
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();
// 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
47 changes: 47 additions & 0 deletions include/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef DISPLAY_H
#define DISPLAY_H

#include <U8g2lib.h>

// OLED display

#define BRIGHTNESS_MIN 50
#define BRIGHTNESS_MAX 250

struct DisplayData {
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;
};

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

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

void screenSaver();
void checkChangedValues();
// private member variables
DisplayData lastDisplayData;
uint8_t brightness=BRIGHTNESS_MIN;
u8g2_uint_t offset_x = 0; // shifting for anti burn in effect
u8g2_uint_t offset_y = 0; // shifting for anti burn in effect
bool valueChanged = false;
uint16_t displayTicks = 0; // local timer state machine
};

#endif // DISPLAY_H
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 @@ -79,7 +79,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
Loading

0 comments on commit 463a748

Please sign in to comment.