Compare commits
No commits in common. "db76255a2c42932bbe6cd728558e1d3b85f335a5" and "47cd48d572d489d07fea183a57cdda1eb3ef237c" have entirely different histories.
db76255a2c
...
47cd48d572
@ -35,9 +35,7 @@ Valid keys are:
|
||||
## Startup sequence
|
||||
|
||||
During startup:
|
||||
* 1 green corner: FastLED is initialized.
|
||||
* 2 green corners: WiFi is connecting...
|
||||
* 3 green corners: Layout is analyzed...
|
||||
* 4 green corners: Connecting to MQTT server...
|
||||
* 5 green corners (only if OTA_DELAY is set): Waiting for an OTA connection...
|
||||
* 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.
|
||||
* Everything green (quarter of a second): Initialization done.
|
@ -24,10 +24,6 @@
|
||||
// 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 "..."
|
||||
@ -43,7 +39,4 @@
|
||||
#define MQTT_TOPIC_STATE_LONG "espleaf/state_long"
|
||||
#define MQTT_TOPIC_COMMANDS "esplead/cmnd"
|
||||
|
||||
#define SYSLOG_HOST "..."
|
||||
#define SYSLOG_PORT 514
|
||||
|
||||
//#define TEST_MODE
|
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#ifdef SYSLOG_HOST
|
||||
void syslog(String msg, uint8_t severity=7);
|
||||
#endif
|
@ -1,15 +1,8 @@
|
||||
#pragma once
|
||||
#include "my_fastled.h"
|
||||
#include "syslog.h"
|
||||
|
||||
//#define LOG(...) Serial.printf(__VA_ARGS__)
|
||||
//#define LOGln(...) Serial.printf(__VA_ARGS__); Serial.println()
|
||||
|
||||
#ifdef SYSLOG_HOST
|
||||
#define LOGln(...) { char buffer[512]; snprintf(buffer, 512, __VA_ARGS__); syslog(buffer); Serial.println(buffer);}
|
||||
#else
|
||||
#define LOG(...) Serial.printf(__VA_ARGS__)
|
||||
#define LOGln(...) Serial.printf(__VA_ARGS__); Serial.println()
|
||||
#endif
|
||||
|
||||
|
||||
void clear_leds();
|
||||
|
@ -39,7 +39,6 @@ void Corner::infect(uint16_t infect_short_level, uint16_t infect_long_level) {
|
||||
}
|
||||
|
||||
bool Corner::reached_level(uint16_t level) {
|
||||
if (color_blend_state >= 1024) return false;
|
||||
uint16_t old_cbs = color_blend_state >= effect_speed ? color_blend_state - effect_speed : 0;
|
||||
return (old_cbs < level && color_blend_state >= level);
|
||||
}
|
||||
|
56
src/main.cpp
56
src/main.cpp
@ -10,7 +10,6 @@
|
||||
#include "prototypes.h"
|
||||
#include "mqtt.h"
|
||||
#include "state.h"
|
||||
#include "syslog.h"
|
||||
|
||||
std::vector<Node*> nodes;
|
||||
std::list<Edge*> edges;
|
||||
@ -132,31 +131,15 @@ void show_all() {
|
||||
}
|
||||
|
||||
void show_status(uint8_t status, CRGB color=CRGB::Green) {
|
||||
for (int i=0; i<status*LEDS_PER_CORNER && i<LED_COUNT; i++) {
|
||||
leds[i] = color;
|
||||
for (int i=0; i<status; i++) {
|
||||
if (i<corners.size()) {
|
||||
corners[i]->set_color(color);
|
||||
}
|
||||
|
||||
for (int i=status*LEDS_PER_CORNER; i<LED_COUNT; i++) {
|
||||
leds[i] = CRGB::Black;
|
||||
}
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
void display_layout() {
|
||||
for(Corner* corner : corners) {
|
||||
corner->set_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);
|
||||
for (int i=status; i<corners.size(); i++) {
|
||||
corners[i]->set_color(CRGB::Black);
|
||||
}
|
||||
show_all();
|
||||
delay(1500);
|
||||
for(Corner* c : corners) {
|
||||
c->set_color(CRGB::Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@ -167,16 +150,16 @@ void setup() {
|
||||
setup_fastled();
|
||||
show_status(1);
|
||||
|
||||
setup_layout();
|
||||
show_status(2);
|
||||
|
||||
#ifdef TEST_MODE
|
||||
LOGln("TEST_MODE is active!");
|
||||
#else
|
||||
show_status(2);
|
||||
wifi_setup();
|
||||
|
||||
show_status(3);
|
||||
setup_layout();
|
||||
|
||||
show_status(4);
|
||||
mqtt_setup();
|
||||
ArduinoOTA.setHostname(OTA_HOSTNAME);
|
||||
ArduinoOTA.onProgress([&](unsigned int progress, unsigned int total){
|
||||
@ -186,33 +169,10 @@ void setup() {
|
||||
ArduinoOTA.onEnd([](){ show_status(0); });
|
||||
ArduinoOTA.begin();
|
||||
|
||||
#ifdef WAIT_FOR_OTA
|
||||
show_status(5);
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
for(Corner* corner : corners) {
|
||||
corner->set_color(CRGB::Black);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -5,15 +5,15 @@
|
||||
|
||||
void connect() {
|
||||
LOGln("Connecting to MQTT broker...");
|
||||
if (mqtt.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_TOPIC "available", 0, true, "offline")) {
|
||||
if (mqtt.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_TOPIC "state", 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,7 +62,6 @@ void mqtt_setup() {
|
||||
mqtt.setServer(MQTT_SERVER, MQTT_SERVER_PORT);
|
||||
mqtt.setCallback(callback);
|
||||
mqtt.setSocketTimeout(1);
|
||||
mqtt.setBufferSize(400);
|
||||
connect();
|
||||
}
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include "syslog.h"
|
||||
#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;
|
||||
WiFiUDP udp;
|
||||
|
||||
udp.beginPacket(SYSLOG_HOST, SYSLOG_PORT);
|
||||
udp.write("<");
|
||||
udp.write(String(facility * 8 + severity).c_str());
|
||||
udp.write(">1 - " OTA_HOSTNAME " core 1 ");
|
||||
udp.write(String(syslog_msg_id++).c_str());
|
||||
udp.write(" - ");
|
||||
udp.write(msg.c_str());
|
||||
udp.endPacket();
|
||||
}
|
||||
#endif
|
@ -2,14 +2,13 @@
|
||||
#include "tools.h"
|
||||
|
||||
void wifi_setup() {
|
||||
Serial.printf("Connecting to WiFi %s...", WIFI_SSID);
|
||||
LOG("Connecting to WiFi %s...", WIFI_SSID);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print(".");
|
||||
LOG(".");
|
||||
delay(300);
|
||||
}
|
||||
Serial.println();
|
||||
LOGln(" Connected as %s", WiFi.localIP().toString().c_str());
|
||||
random16_add_entropy(micros());
|
||||
}
|
Loading…
Reference in New Issue
Block a user