Add config ap with button press at start-up

This commit is contained in:
Carsten Schmiemann 2022-11-09 02:10:55 +01:00
parent d94e07459d
commit 73c25b2351

View file

@ -328,6 +328,14 @@ void setup() {
String bootmsg = "Booting solar monitor app..." + (String)VERSION;
logPrintlnI(bootmsg.c_str());
display_text((char*)"Connect to AP:PV_Mon", (char*)" for configuration");
#ifdef ESP8266
WiFi.hostname("ESP_Solar_Monitor");
#endif
#ifdef ESP32
WiFi.setHostname("ESP_Solar_Monitor");
#endif
//Wifi Manager parameters
WiFiManagerParameter custom_mqtt_server("mqtt_server", "IP adress of GX Device (MQTT No SSL)", mqtt_server, 15);
WiFiManagerParameter custom_gx_vrm_id("gx_vrm_id", "VRM ID of GX device", gx_vrm_id, 20);
@ -340,13 +348,6 @@ void setup() {
WiFiManagerParameter custom_address_outside_temperature("address_outside_temperature", "Address of outside temperature", address_outside_temperature, 6);
WiFiManager wm;
#ifdef ESP8266
WiFi.hostname("ESP_Solar_Monitor");
#endif
#ifdef ESP32
WiFi.setHostname("ESP_Solar_Monitor");
#endif
wm.setSaveConfigCallback(saveConfigCallback);
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_gx_vrm_id);
@ -358,7 +359,17 @@ void setup() {
wm.addParameter(&custom_address_battery);
wm.addParameter(&custom_address_outside_temperature);
wm.autoConnect("PV_Mon");
//Start wifi manager configuration if BUTTON_SETUP is pressed on start-up
currentButtonSetupState = digitalRead(BUTTON_SETUP);
if(lastButtonSetupState == HIGH && currentButtonSetupState == LOW)
{
display_text((char*)"Connect to AP:PV_Mon", (char*)"for re-configuration");
wm.startConfigPortal("PV_Mon");
} else
{
wm.autoConnect("PV_Mon");
}
display_text((char*)" Connecting wifi...", (char*)"");
delay(500);
logPrintlnI("Connecting wifi...");
@ -468,11 +479,6 @@ void setup() {
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
static unsigned long lastDispRefreshTime = 0;
static unsigned long lastScreenChangeTime = 0;
@ -515,7 +521,7 @@ void loop() {
//Rotate screen if BUTTON_ROTATION is pressed
currentButtonRotationState = digitalRead(BUTTON_ROTATION);
if(lastButtonRotationState == LOW && currentButtonRotationState == HIGH)
if(lastButtonRotationState == HIGH && currentButtonRotationState == LOW)
{
display_screen++;
if (display_screen == display_last_screen + 1)
@ -533,13 +539,8 @@ void loop() {
lastButtonRotationState = currentButtonRotationState;
}
//Start wifi manager configuration if BUTTON_SETUP is pressed
currentButtonSetupState = digitalRead(BUTTON_SETUP);
if(lastButtonSetupState == LOW && currentButtonSetupState == HIGH)
{
display_text((char*)"Connect to AP:PV_Mon", (char*)"for re-configuration");
WiFiManager wm;
wm.startConfigPortal("PV_Mon");
lastButtonSetupState = currentButtonSetupState;
if (!client.connected()) {
reconnect();
}
client.loop();
}