Fix screen display
This commit is contained in:
parent
bbe6f17883
commit
b9c88f56f5
|
@ -51,8 +51,8 @@ void display_header() {
|
|||
|
||||
void display_header_small() {
|
||||
display.setFont(u8g2_font_6x10_tr);
|
||||
display.drawStr(40,7,"PV Monitor Project");
|
||||
display.drawLine(0, 8, 128, 8);
|
||||
display.drawStr(10,7,"PV Monitor Project");
|
||||
display.drawLine(0, 10, 128, 10);
|
||||
}
|
||||
|
||||
void display_init(char* VERSION) {
|
||||
|
@ -60,8 +60,8 @@ void display_init(char* VERSION) {
|
|||
do {
|
||||
display_header();
|
||||
display.drawStr(0,52,"by Carsten Schmiemann");
|
||||
sprintf(screenbuffer, "(C) 2022 %s", VERSION);
|
||||
display.drawStr(40,60,screenbuffer);
|
||||
display.drawStr(20,60, "(C) 2022");
|
||||
display.drawStr(76,60, VERSION);
|
||||
} while ( display.nextPage() );
|
||||
}
|
||||
|
||||
|
|
59
src/main.cpp
59
src/main.cpp
|
@ -22,16 +22,19 @@
|
|||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
; THE SOFTWARE.
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
//#include <Arduino.h>
|
||||
#include <logger.h>
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#define Flash SPIFFS
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
#define Flash LittleFS
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
|
@ -44,7 +47,7 @@
|
|||
#include <pins.h>
|
||||
#include <display.h>
|
||||
|
||||
static String VERSION = "0.5b";
|
||||
char VERSION[6] = "v0.5b";
|
||||
|
||||
//Defaults
|
||||
char mqtt_server[15] = "";
|
||||
|
@ -227,7 +230,7 @@ void reconnect() {
|
|||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
logPrintlnI("Attempting MQTT connection...");
|
||||
display_text((char*)"Connect to GX MQTT..", mqtt_server);
|
||||
display_text((char*)"Connect to GX MQTT...", mqtt_server);
|
||||
delay(2000);
|
||||
// Attempt to connect
|
||||
if (client.connect("PV_solar_monitor")) {
|
||||
|
@ -254,9 +257,10 @@ void reconnect() {
|
|||
} else {
|
||||
logPrintlnE("failed, rc=");
|
||||
logPrintlnE((char*)client.state());
|
||||
logPrintlnE(" try again in 5 seconds");
|
||||
display_text((char*)"MQTT Error, rc", (char*)client.state());
|
||||
// Wait 5 seconds before retrying
|
||||
logPrintlnE(" try again in 10 seconds");
|
||||
String msg = " MQTT Error rc=" + (String)client.state();
|
||||
display_text_fullscreen((char*)"MQTT Connection Error", (char*)"Did you enable MQTT", (char*)"on your GX device?", (char*)msg.c_str(), (char*)"", (char*)"Retry in 10 seconds...");
|
||||
// Wait 10 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
|
@ -267,19 +271,18 @@ void setup() {
|
|||
Serial.println("Booting...");
|
||||
display_begin();
|
||||
Serial.println("Display init...");
|
||||
display_init((char*)VERSION);
|
||||
display_init(VERSION);
|
||||
delay(2000);
|
||||
display_text_fullscreen((char*)"Test1", (char*)"Test2", (char*)"Test3", (char*)"Test4", (char*)"Test5", (char*)"Test6");
|
||||
delay(2000);
|
||||
//read configuration from FS json
|
||||
Serial.println("mounting FS...");
|
||||
|
||||
if (SPIFFS.begin()) {
|
||||
//read configuration from Flash json
|
||||
Serial.println("mounting Flash...");
|
||||
|
||||
if (Flash.begin()) {
|
||||
Serial.println("mounted file system");
|
||||
if (SPIFFS.exists("/config.json")) {
|
||||
if (Flash.exists("/config.json")) {
|
||||
//file exists, reading and loading
|
||||
Serial.println("reading config file");
|
||||
File configFile = SPIFFS.open("/config.json", "r");
|
||||
File configFile = Flash.open("/config.json", "r");
|
||||
if (configFile) {
|
||||
Serial.println("opened config file");
|
||||
size_t size = configFile.size();
|
||||
|
@ -316,12 +319,12 @@ void setup() {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println("failed to mount FS");
|
||||
Serial.println("failed to mount Flash");
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
//logPrintlnI(printf("Booting solar monitor app... %s", VERSION));
|
||||
logPrintlnI("Booting solar monitor app..." + VERSION);
|
||||
String bootmsg = "Booting solar monitor app..." + (String)VERSION;
|
||||
logPrintlnI(bootmsg.c_str());
|
||||
display_text((char*)"Connect to AP:PV_MON", (char*)" for configuration");
|
||||
//Wifi Manager parameters
|
||||
WiFiManagerParameter custom_mqtt_server("mqtt_server", "IP adress of GX Device (MQTT No SSL)", mqtt_server, 15);
|
||||
|
@ -345,10 +348,10 @@ void setup() {
|
|||
wm.addParameter(&custom_address_inverter);
|
||||
wm.addParameter(&custom_address_battery);
|
||||
wm.addParameter(&custom_address_outside_temperature);
|
||||
wm.setTimeout(60);
|
||||
wm.setTimeout(5);
|
||||
|
||||
wm.autoConnect("PV_Mon");
|
||||
display_text((char*)" Connecting wifi...", "");
|
||||
display_text((char*)" Connecting wifi...", (char*)"");
|
||||
delay(500);
|
||||
logPrintlnI("Connecting wifi...");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
|
@ -370,7 +373,7 @@ void setup() {
|
|||
char* ip_address = new char[40]();
|
||||
sprintf(ip_address, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
display_text((char*)" Connected. IP:", ip_address);
|
||||
//save the custom parameters to FS
|
||||
//save the custom parameters to Flash
|
||||
if (shouldSaveConfig) {
|
||||
Serial.println("saving config");
|
||||
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
|
||||
|
@ -389,7 +392,7 @@ void setup() {
|
|||
json["address_battery"] = address_battery;
|
||||
json["address_outside_temperature"] = address_outside_temperature;
|
||||
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
File configFile = Flash.open("/config.json", "w");
|
||||
if (!configFile) {
|
||||
Serial.println("failed to open config file for writing");
|
||||
}
|
||||
|
@ -450,14 +453,10 @@ void setup() {
|
|||
Serial.print("gx_vrm_id: "); Serial.println(gx_vrm_id);
|
||||
Serial.print("disp_refresh_interval: "); Serial.println(DISPLAY_REFRESH_INTERVAL);
|
||||
Serial.print("disp_screen_interval: "); Serial.println(DISPLAY_SCREEN_INTERVAL);
|
||||
display_text((char*)"Config: MQTT Server", mqtt_server);
|
||||
delay(1500);
|
||||
display_text((char*)"Config: GX VRM-ID", gx_vrm_id);
|
||||
delay(1500);
|
||||
display_text((char*)"Config: LCD Refresh", disp_refresh_interval);
|
||||
delay(1500);
|
||||
display_text((char*)"Config: LCD Rotation", disp_screen_interval);
|
||||
delay(1500);
|
||||
display_text_fullscreen((char*)"Configuration summary", (char*)"GX MQTT Server IP:", mqtt_server, (char*)"GX VRM ID:", gx_vrm_id, (char*)" 1/2");
|
||||
delay(3000);
|
||||
display_text_fullscreen((char*)"Configuration summary", (char*)"Disp. Refresh:", disp_refresh_interval, (char*)"Disp. rotation:", disp_screen_interval, (char*)" 2/2");
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in a new issue