Commit 11b36705 authored by Eric Duminil's avatar Eric Duminil
Browse files

WiFi callbacks

parent d0c32222
Pipeline #5799 passed with stage
in 2 minutes and 37 seconds
......@@ -56,11 +56,37 @@
* and define your credentials and parameters in 'config.h'.
*/
void failedConnection() {
Serial.println("Seriously. What???");
led_effects::showKITTWheel(color::red);
//void failedConnection() {
// Serial.println("Seriously. What???");
// led_effects::showKITTWheel(color::red);
//}
//
void wifiConnected() {
led_effects::showKITTWheel(color::green);
Serial.println();
Serial.print(F("WiFi - Connected! IP address: "));
IPAddress address = WiFi.localIP();
snprintf(wifi::local_ip, sizeof(wifi::local_ip), "%d.%d.%d.%d", address[0], address[1], address[2], address[3]);
Serial.println(wifi::local_ip);
ntp::initialize();
if (config::mqtt_active()) {
mqtt::initialize(ampel.sensorId);
}
//TODO: If http enabled
Serial.print(F("You can access this sensor via http://"));
Serial.print(ampel.sensorId);
Serial.print(F(".local (might be unstable) or http://"));
Serial.println(WiFi.localIP());
}
void wifiFailed() {
Serial.print(F("WiFi - Could not connect to "));
Serial.println(config::current_ssid()); //TODO: Rename
led_effects::showKITTWheel(color::red);
}
/*****************************************************************
* Setup *
*****************************************************************/
......@@ -72,35 +98,9 @@ void setup() {
web_config::initialize();
if (config::wifi_active) {
web_config::setWifiConnectionCallback([]() {
//TODO: Move somewhere else
led_effects::showKITTWheel(color::green);
Serial.println();
Serial.print(F("WiFi - Connected! IP address: "));
IPAddress address = WiFi.localIP();
snprintf(wifi::local_ip, sizeof(wifi::local_ip), "%d.%d.%d.%d", address[0], address[1], address[2], address[3]);
Serial.println(wifi::local_ip);
ntp::initialize();
if (config::mqtt_active()) {
mqtt::initialize(ampel.sensorId);
}
Serial.print(F("You can access this sensor via http://"));
Serial.print(ampel.sensorId);
Serial.print(F(".local (might be unstable) or http://"));
Serial.println(WiFi.localIP());
});
web_config::setWifiConnectionCallback(wifiConnected);
web_config::setWifiFailCallback(failedConnection);
// web_config::setWifiConnectionFailedCallback([]() {
// led_effects::showKITTWheel(color::red);
// Serial.println(F("Connection to WiFi failed"));
// });
}
web_config::setWifiFailCallback(wifiFailed);
pinMode(0, INPUT); // Flash button (used for forced calibration)
......@@ -124,8 +124,6 @@ void setup() {
wifi::defineCommands();
# if (AMPEL_HTTP==1)
web_server::definePages();
//TODO: Rename. Not just web_server
// web_server::initialize();
# endif
}
......
......@@ -50,6 +50,7 @@ namespace web_config {
"[s]").build();
//TODO: Distribute to corresponding classes, possibly with callbacks?
//TODO: Chainedparameters?
/**
* CO2 sensor
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment