diff --git a/README.md b/README.md index e9c4226..bc7d3f4 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,5 @@ During startup: * 1 green corner: FastLED is initialized. Layout is now being analyzed. * 2 green corners: Layout is done. WiFi is being connected. * 3 green corners: WiFi connection established. Connecting to MQTT server. +* 4 green corners (only if OTA_DELAY is set): Waiting for an OTA connection. * Everything green (quarter of a second): Initialization done. \ No newline at end of file diff --git a/include/config.sample.h b/include/config.sample.h index 41332c1..92a0690 100644 --- a/include/config.sample.h +++ b/include/config.sample.h @@ -24,6 +24,10 @@ // Maximum color difference for the random effects. // This changes the hue value +/- this value. Use a maximum value of 127, otherwise strange things might happen. #define COLOR_DIFFERENCE 25 +// If this is enabled, the node layout will be visualized at startup. +#define SHOW_LAYOUT_AT_BOOT +// Wait this many seconds for OTA requests during startup. +#define WAIT_FOR_OTA 5 #define WIFI_SSID "..." #define WIFI_PASS "..." diff --git a/src/main.cpp b/src/main.cpp index 6054cd1..16fa6e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,15 +132,31 @@ void show_all() { } void show_status(uint8_t status, CRGB color=CRGB::Green) { - for (int i=0; iset_color(color); + for (int i=0; iset_color(CRGB::Blue); + for(Corner* c : corner->_short_neighbours) { + c->set_color(CRGB::Red); + } + for(Corner* c : corner->_long_neighbours) { + c->set_color(CRGB::Green); + } + show_all(); + delay(1500); + for(Corner* c : corners) { + c->set_color(CRGB::Black); } } - for (int i=status; iset_color(CRGB::Black); - } - show_all(); } void setup() { @@ -170,12 +186,29 @@ void setup() { ArduinoOTA.onEnd([](){ show_status(0); }); ArduinoOTA.begin(); + #ifdef WAIT_FOR_OTA + show_status(4); + LOGln("Waiting %d seconds for OTA requests...", WAIT_FOR_OTA); + unsigned long ota_target_time = millis() + WAIT_FOR_OTA*1000; + while (millis() < ota_target_time) { + ArduinoOTA.handle(); + yield(); + } + LOGln("Done waiting for OTA requests."); + #endif + show_status(255); delay(250); show_status(0); #endif - syslog("Setup done."); + LOGln("Setup done."); + + #ifdef SHOW_LAYOUT_AT_BOOT + LOGln("SHOW_LAYOUT_AT_BOOT is active - showing layout..."); + display_layout(); + LOGln("Showing layout is done."); + #endif } void loop() { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 6d63da0..a2969d8 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -5,15 +5,15 @@ void connect() { LOGln("Connecting to MQTT broker..."); - if (mqtt.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_TOPIC "state", 0, true, "OFFLINE")) { + if (mqtt.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_TOPIC "available", 0, true, "offline")) { LOGln("Connected."); mqtt.publish(MQTT_TOPIC "available", "online", true); char buffer[40]; snprintf(buffer, 40, "online %s", wifi.localIP().toString().c_str()); mqtt.publish(MQTT_TOPIC "available_long", buffer, true); mqtt.subscribe(MQTT_TOPIC"cmnd"); - String discovery_msg = "{\"" - "\"~\":\"" MQTT_TOPIC ",\"avty_t\":\"~available\",\"cmd_t\":\"~cmnd\",\"stat_t\":\"~state\"," + String discovery_msg = "{" + "\"~\":\"" MQTT_TOPIC "\",\"avty_t\":\"~available\",\"cmd_t\":\"~cmnd\",\"stat_t\":\"~state\"," "\"name\":\"ESPleaf\",\"schema\":\"json\"," "\"brightness\":true,\"bri_scl\":255," "\"effect\":true,\"effect_list\":[\"off\",\"corners\",\"nodes\",\"flash\",\"static\"]," @@ -62,6 +62,7 @@ void mqtt_setup() { mqtt.setServer(MQTT_SERVER, MQTT_SERVER_PORT); mqtt.setCallback(callback); mqtt.setSocketTimeout(1); + mqtt.setBufferSize(400); connect(); } diff --git a/src/syslog.cpp b/src/syslog.cpp index 0152c02..2757173 100644 --- a/src/syslog.cpp +++ b/src/syslog.cpp @@ -2,6 +2,8 @@ #include "config.h" #ifdef SYSLOG_HOST + static uint16_t syslog_msg_id = 1; + void syslog(String msg, uint8_t severity) { uint8_t facility = 16; // local0 if (severity > 7) severity = 7; @@ -10,7 +12,9 @@ udp.beginPacket(SYSLOG_HOST, SYSLOG_PORT); udp.write("<"); udp.write(String(facility * 8 + severity).c_str()); - udp.write(">1 - " OTA_HOSTNAME " espleaf 1 1 - "); + udp.write(">1 - " OTA_HOSTNAME " core 1 "); + udp.write(String(syslog_msg_id++).c_str()); + udp.write(" - "); udp.write(msg.c_str()); udp.endPacket(); }