Compare commits

...

4 Commits

Author SHA1 Message Date
Carsten Schmiemann 3083b7a383 Add time display, set by NTP 2022-11-13 04:16:51 +01:00
Carsten Schmiemann 6b11226ac0 Fix temp outside display 2022-11-13 03:27:03 +01:00
Carsten Schmiemann 0c0020547b Add OA temp display 2022-11-13 02:47:22 +01:00
Carsten Schmiemann 3c599b5e42 Fix lang config 2022-11-13 00:59:30 +01:00
5 changed files with 66 additions and 15 deletions

View File

@ -21,4 +21,5 @@ lib_deps =
bblanchon/ArduinoJson@^6.19.4
olikraus/U8g2@^2.34.4
tzapu/WiFiManager@^0.16.0
paulstoffregen/Time@^1.6.1
monitor_speed = 115200

View File

@ -41,10 +41,26 @@ char* title_battery;
char* title_grid;
bool pv_charging = false;
bool show_temp_outside = false;
float temperature_outside = 0.0;
bool show_temp_outside;
int time_hour;
int time_minute;
float temperature_outside;
char* screenbuffer;
void display_setup(bool set_show_temp_outside, char lang[2]) {
show_temp_outside = set_show_temp_outside;
set_display_language(lang);
}
void display_temp_outside(float mqtt_temp_outside) {
temperature_outside = mqtt_temp_outside;
}
void display_time(int hour, int minute) {
time_hour = hour;
time_minute = minute;
}
void display_begin() {
display.begin();
}
@ -98,10 +114,20 @@ void display_header(char* TEXT) {
display.setFont(u8g2_font_6x10_tr);
display.drawStr(2,7,TEXT);
display.drawLine(0, 8, 128, 8);
display.drawLine(100, 0, 100, 8);
display.drawLine(93, 0, 93, 8);
display.setCursor(97,7);
if (time_hour < 10) {
display.print("0");
}
display.print(time_hour); display.print(":");
if (time_minute < 10) {
display.print("0");
}
display.print(time_minute);
if (show_temp_outside)
{
display.setCursor(50,7); display.print(temperature_outside);
display.drawLine(58, 0, 58, 8);
display.setCursor(67,7); display.print(temperature_outside,1); display.print("C");
}
}

View File

@ -22,6 +22,9 @@
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
; THE SOFTWARE.
*/
void display_setup(bool set_show_temp_outside,char lang[2]);
void display_temp_outside(float temperature_outside);
void display_time(int hour, int minute);
void display_begin();
void display_init(char* VERSION);
void display_logo();

View File

@ -37,6 +37,6 @@ void set_display_language(char lang[2])
{
title_pv = (char*)"PV modules";
title_battery = (char*)"Battery";
title_grid = (char*)"Grid overview";
title_grid = (char*)"Grid";
}
}

View File

@ -42,13 +42,16 @@
#include <ArduinoJson.h>
#include <Wire.h>
#include <U8g2lib.h>
#include "time.h"
//Program parts
#include <pins.h>
#include <lang.h>
#include <display.h>
char VERSION[6] = "v0.5b";
char VERSION[6] = "v0.8c";
#define TimeZone "CET-1CEST,M3.5.0,M10.5.0/3"
#define TimeServ "pool.ntp.org"
//Defaults
char mqtt_server[15] = "";
@ -60,14 +63,10 @@ char address_grid_meter[6] = "";
char address_inverter[6] = "";
char address_battery[6] = "";
char address_outside_temperature[6] = "";
char display_lang[2] = "";
char display_lang[6] = "";
long unsigned int DISPLAY_REFRESH_INTERVAL;
long unsigned int DISPLAY_SCREEN_INTERVAL;
//Display config
extern bool show_temp_outside;
extern float temperature_outside;
//MQTT connect strings
char mqtt_pv_voltage[80];
char mqtt_pv_power[80];
@ -100,6 +99,11 @@ void saveConfigCallback () {
WiFiClient espClient;
PubSubClient client(espClient);
//Time library setup
time_t now;
tm tm;
//Globals
long lastMsg = 0;
char msg[50];
@ -211,7 +215,7 @@ void callback(char* topic, byte* message, unsigned int length) {
if (String(topic) == mqtt_temp_outside) {
DynamicJsonDocument json(512);
deserializeJson(json, messageTemp);
temperature_outside = json["value"];
display_temp_outside(json["value"]);
}
//System - AC Load Phase 1
@ -357,7 +361,7 @@ void setup() {
WiFiManagerParameter custom_address_inverter("address_inverter", "Address of vebus inverter", address_inverter, 6);
WiFiManagerParameter custom_address_battery("address_battery", "Address of can battery", address_battery, 6);
WiFiManagerParameter custom_address_outside_temperature("address_outside_temperature", "Address of outside temperature", address_outside_temperature, 6);
WiFiManagerParameter custom_display_lang("display_lang", "Display language en, de", display_lang, 2);
WiFiManagerParameter custom_display_lang("display_lang", "Display language en, de", display_lang, 6);
WiFiManager wm;
wm.setSaveConfigCallback(saveConfigCallback);
@ -400,11 +404,14 @@ void setup() {
DISPLAY_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
set_display_language(display_lang);
if (strtol(address_outside_temperature, NULL, 10) != 0)
{
show_temp_outside = true;
display_setup(true, display_lang);
}
else
{
display_setup(false, display_lang);
}
client.setServer(mqtt_server, 1883);
@ -430,6 +437,7 @@ void setup() {
json["address_inverter"] = address_inverter;
json["address_battery"] = address_battery;
json["address_outside_temperature"] = address_outside_temperature;
json["display_language"] = display_lang;
File configFile = Flash.open("/config.json", "w");
if (!configFile) {
@ -447,6 +455,17 @@ void setup() {
//end save
}
//NTP setup
#ifdef ESP32
configTime(0, 0, TimeServ);
setenv("TZ", TimeZone, 1);
tzset();
#endif
#ifdef ESP8266
configTime(TimeZone, TimeServ);
#endif
delay(1000); //for screen display
//Generate mqtt topics from id and address
@ -523,6 +542,8 @@ void loop() {
{
if(millis() - lastScreenChangeTime >= DISPLAY_SCREEN_INTERVAL)
{
time(&now); localtime_r(&now, &tm); //Get local time
display_time(tm.tm_hour, tm.tm_min);
display_screen++;
lastScreenChangeTime += DISPLAY_SCREEN_INTERVAL;
if (display_screen == display_last_screen + 1)