Handle empty mqtt_host, add /start_config_ap
This commit is contained in:
parent
6db6bfc2ff
commit
88b476db51
2 changed files with 25 additions and 15 deletions
|
@ -219,7 +219,7 @@ void setup() {
|
||||||
//if it does not connect it starts an access point with the specified name
|
//if it does not connect it starts an access point with the specified name
|
||||||
//here "AutoConnectAP"
|
//here "AutoConnectAP"
|
||||||
//and goes into a blocking loop awaiting configuration
|
//and goes into a blocking loop awaiting configuration
|
||||||
if (!wifiManager.autoConnect()) {
|
if (!wifiManager.autoConnect(HOSTNAME)) {
|
||||||
DBG_OUTPUT_PORT.println("failed to connect and hit timeout");
|
DBG_OUTPUT_PORT.println("failed to connect and hit timeout");
|
||||||
//reset and try again, or maybe put it to deep sleep
|
//reset and try again, or maybe put it to deep sleep
|
||||||
ESP.reset();
|
ESP.reset();
|
||||||
|
@ -241,7 +241,7 @@ void setup() {
|
||||||
writeEEPROM(64, 6, mqtt_port); // 64-69
|
writeEEPROM(64, 6, mqtt_port); // 64-69
|
||||||
writeEEPROM(70, 32, mqtt_user); // 70-101
|
writeEEPROM(70, 32, mqtt_user); // 70-101
|
||||||
writeEEPROM(102, 32, mqtt_pass); // 102-133
|
writeEEPROM(102, 32, mqtt_pass); // 102-133
|
||||||
writeEEPROM(134, 1, "1"); // 134 --> alwasy "1"
|
writeEEPROM(134, 1, "1"); // 134 --> always "1"
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -299,13 +299,15 @@ void setup() {
|
||||||
// Configure MQTT
|
// Configure MQTT
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
String(String(HOSTNAME) + "/in").toCharArray(mqtt_intopic, strlen(HOSTNAME) + 3);
|
if (mqtt_host != "" && String(mqtt_port).toInt() > 0) {
|
||||||
String(String(HOSTNAME) + "/out").toCharArray(mqtt_outtopic, strlen(HOSTNAME) + 4);
|
String(String(HOSTNAME) + "/in").toCharArray(mqtt_intopic, strlen(HOSTNAME) + 4);
|
||||||
|
String(String(HOSTNAME) + "/out").toCharArray(mqtt_outtopic, strlen(HOSTNAME) + 5);
|
||||||
DBG_OUTPUT_PORT.printf("Connect %s %d\n", mqtt_host, String(mqtt_port).toInt());
|
|
||||||
|
|
||||||
mqtt_client.setServer(mqtt_host, String(mqtt_port).toInt());
|
DBG_OUTPUT_PORT.printf("Connect %s %d\n", mqtt_host, String(mqtt_port).toInt());
|
||||||
mqtt_client.setCallback(mqtt_callback);
|
|
||||||
|
mqtt_client.setServer(mqtt_host, String(mqtt_port).toInt());
|
||||||
|
mqtt_client.setCallback(mqtt_callback);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,19 +391,26 @@ void setup() {
|
||||||
server.on("/upload", handleMinimalUpload);
|
server.on("/upload", handleMinimalUpload);
|
||||||
|
|
||||||
server.on("/restart", []() {
|
server.on("/restart", []() {
|
||||||
DBG_OUTPUT_PORT.printf("/restart:\n");
|
DBG_OUTPUT_PORT.printf("/restart\n");
|
||||||
server.send(200, "text/plain", "restarting..." );
|
server.send(200, "text/plain", "restarting..." );
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/reset_wlan", []() {
|
server.on("/reset_wlan", []() {
|
||||||
DBG_OUTPUT_PORT.printf("/reset_wlan:\n");
|
DBG_OUTPUT_PORT.printf("/reset_wlan\n");
|
||||||
server.send(200, "text/plain", "Resetting WLAN and restarting..." );
|
server.send(200, "text/plain", "Resetting WLAN and restarting..." );
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
wifiManager.resetSettings();
|
wifiManager.resetSettings();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.on("/start_config_ap", []() {
|
||||||
|
DBG_OUTPUT_PORT.printf("/start_config_ap\n");
|
||||||
|
server.send(200, "text/plain", "Starting config AP ..." );
|
||||||
|
WiFiManager wifiManager;
|
||||||
|
wifiManager.startConfigPortal(HOSTNAME);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Setup: SPIFFS Webserver handler
|
// Setup: SPIFFS Webserver handler
|
||||||
|
@ -528,10 +537,12 @@ void loop() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
if (!mqtt_client.connected()) {
|
if (mqtt_host != "" && String(mqtt_port).toInt() > 0) {
|
||||||
mqtt_reconnect();
|
if (!mqtt_client.connected()) {
|
||||||
|
mqtt_reconnect();
|
||||||
|
}
|
||||||
|
mqtt_client.loop();
|
||||||
}
|
}
|
||||||
mqtt_client.loop();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Simple statemachine that handles the different modes
|
// Simple statemachine that handles the different modes
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
#define PIN 5 // PIN where neopixel / WS2811 strip is attached
|
#define PIN 5 // PIN where neopixel / WS2811 strip is attached
|
||||||
#define NUMLEDS 24 // Number of leds in the strip
|
#define NUMLEDS 24 // Number of leds in the strip
|
||||||
|
|
||||||
|
const char HOSTNAME[] = "ESP8266_01"; // Friedly hostname
|
||||||
const char HOSTNAME[] = "ESP8266_VORONOI"; // Friedly hostname
|
|
||||||
|
|
||||||
#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue