Compare commits
No commits in common. "db76255a2c42932bbe6cd728558e1d3b85f335a5" and "47cd48d572d489d07fea183a57cdda1eb3ef237c" have entirely different histories.
db76255a2c
...
47cd48d572
@ -35,9 +35,7 @@ Valid keys are:
|
|||||||
## Startup sequence
|
## Startup sequence
|
||||||
|
|
||||||
During startup:
|
During startup:
|
||||||
* 1 green corner: FastLED is initialized.
|
* 1 green corner: FastLED is initialized. Layout is now being analyzed.
|
||||||
* 2 green corners: WiFi is connecting...
|
* 2 green corners: Layout is done. WiFi is being connected.
|
||||||
* 3 green corners: Layout is analyzed...
|
* 3 green corners: WiFi connection established. Connecting to MQTT server.
|
||||||
* 4 green corners: Connecting to MQTT server...
|
|
||||||
* 5 green corners (only if OTA_DELAY is set): Waiting for an OTA connection...
|
|
||||||
* Everything green (quarter of a second): Initialization done.
|
* Everything green (quarter of a second): Initialization done.
|
@ -24,10 +24,6 @@
|
|||||||
// Maximum color difference for the random effects.
|
// 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.
|
// This changes the hue value +/- this value. Use a maximum value of 127, otherwise strange things might happen.
|
||||||
#define COLOR_DIFFERENCE 25
|
#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_SSID "..."
|
||||||
#define WIFI_PASS "..."
|
#define WIFI_PASS "..."
|
||||||
@ -43,7 +39,4 @@
|
|||||||
#define MQTT_TOPIC_STATE_LONG "espleaf/state_long"
|
#define MQTT_TOPIC_STATE_LONG "espleaf/state_long"
|
||||||
#define MQTT_TOPIC_COMMANDS "esplead/cmnd"
|
#define MQTT_TOPIC_COMMANDS "esplead/cmnd"
|
||||||
|
|
||||||
#define SYSLOG_HOST "..."
|
|
||||||
#define SYSLOG_PORT 514
|
|
||||||
|
|
||||||
//#define TEST_MODE
|
//#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
|
#pragma once
|
||||||
#include "my_fastled.h"
|
#include "my_fastled.h"
|
||||||
#include "syslog.h"
|
|
||||||
|
|
||||||
//#define LOG(...) Serial.printf(__VA_ARGS__)
|
#define LOG(...) Serial.printf(__VA_ARGS__)
|
||||||
//#define LOGln(...) Serial.printf(__VA_ARGS__); Serial.println()
|
#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 LOGln(...) Serial.printf(__VA_ARGS__); Serial.println()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void clear_leds();
|
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) {
|
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;
|
uint16_t old_cbs = color_blend_state >= effect_speed ? color_blend_state - effect_speed : 0;
|
||||||
return (old_cbs < level && color_blend_state >= level);
|
return (old_cbs < level && color_blend_state >= level);
|
||||||
}
|
}
|
||||||
|
56
src/main.cpp
56
src/main.cpp
@ -10,7 +10,6 @@
|
|||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "syslog.h"
|
|
||||||
|
|
||||||
std::vector<Node*> nodes;
|
std::vector<Node*> nodes;
|
||||||
std::list<Edge*> edges;
|
std::list<Edge*> edges;
|
||||||
@ -132,31 +131,15 @@ void show_all() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_status(uint8_t status, CRGB color=CRGB::Green) {
|
void show_status(uint8_t status, CRGB color=CRGB::Green) {
|
||||||
for (int i=0; i<status*LEDS_PER_CORNER && i<LED_COUNT; i++) {
|
for (int i=0; i<status; i++) {
|
||||||
leds[i] = color;
|
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();
|
for (int i=status; i<corners.size(); i++) {
|
||||||
}
|
corners[i]->set_color(CRGB::Black);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
show_all();
|
show_all();
|
||||||
delay(1500);
|
|
||||||
for(Corner* c : corners) {
|
|
||||||
c->set_color(CRGB::Black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -167,16 +150,16 @@ void setup() {
|
|||||||
setup_fastled();
|
setup_fastled();
|
||||||
show_status(1);
|
show_status(1);
|
||||||
|
|
||||||
|
setup_layout();
|
||||||
|
show_status(2);
|
||||||
|
|
||||||
#ifdef TEST_MODE
|
#ifdef TEST_MODE
|
||||||
LOGln("TEST_MODE is active!");
|
LOGln("TEST_MODE is active!");
|
||||||
#else
|
#else
|
||||||
show_status(2);
|
|
||||||
wifi_setup();
|
wifi_setup();
|
||||||
|
|
||||||
show_status(3);
|
show_status(3);
|
||||||
setup_layout();
|
|
||||||
|
|
||||||
show_status(4);
|
|
||||||
mqtt_setup();
|
mqtt_setup();
|
||||||
ArduinoOTA.setHostname(OTA_HOSTNAME);
|
ArduinoOTA.setHostname(OTA_HOSTNAME);
|
||||||
ArduinoOTA.onProgress([&](unsigned int progress, unsigned int total){
|
ArduinoOTA.onProgress([&](unsigned int progress, unsigned int total){
|
||||||
@ -186,33 +169,10 @@ void setup() {
|
|||||||
ArduinoOTA.onEnd([](){ show_status(0); });
|
ArduinoOTA.onEnd([](){ show_status(0); });
|
||||||
ArduinoOTA.begin();
|
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);
|
show_status(255);
|
||||||
delay(250);
|
delay(250);
|
||||||
show_status(0);
|
show_status(0);
|
||||||
#endif
|
#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() {
|
void loop() {
|
||||||
|
@ -5,15 +5,15 @@
|
|||||||
|
|
||||||
void connect() {
|
void connect() {
|
||||||
LOGln("Connecting to MQTT broker...");
|
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.");
|
LOGln("Connected.");
|
||||||
mqtt.publish(MQTT_TOPIC "available", "online", true);
|
mqtt.publish(MQTT_TOPIC "available", "online", true);
|
||||||
char buffer[40];
|
char buffer[40];
|
||||||
snprintf(buffer, 40, "online %s", wifi.localIP().toString().c_str());
|
snprintf(buffer, 40, "online %s", wifi.localIP().toString().c_str());
|
||||||
mqtt.publish(MQTT_TOPIC "available_long", buffer, true);
|
mqtt.publish(MQTT_TOPIC "available_long", buffer, true);
|
||||||
mqtt.subscribe(MQTT_TOPIC"cmnd");
|
mqtt.subscribe(MQTT_TOPIC"cmnd");
|
||||||
String discovery_msg = "{"
|
String discovery_msg = "{\""
|
||||||
"\"~\":\"" MQTT_TOPIC "\",\"avty_t\":\"~available\",\"cmd_t\":\"~cmnd\",\"stat_t\":\"~state\","
|
"\"~\":\"" MQTT_TOPIC ",\"avty_t\":\"~available\",\"cmd_t\":\"~cmnd\",\"stat_t\":\"~state\","
|
||||||
"\"name\":\"ESPleaf\",\"schema\":\"json\","
|
"\"name\":\"ESPleaf\",\"schema\":\"json\","
|
||||||
"\"brightness\":true,\"bri_scl\":255,"
|
"\"brightness\":true,\"bri_scl\":255,"
|
||||||
"\"effect\":true,\"effect_list\":[\"off\",\"corners\",\"nodes\",\"flash\",\"static\"],"
|
"\"effect\":true,\"effect_list\":[\"off\",\"corners\",\"nodes\",\"flash\",\"static\"],"
|
||||||
@ -62,7 +62,6 @@ void mqtt_setup() {
|
|||||||
mqtt.setServer(MQTT_SERVER, MQTT_SERVER_PORT);
|
mqtt.setServer(MQTT_SERVER, MQTT_SERVER_PORT);
|
||||||
mqtt.setCallback(callback);
|
mqtt.setCallback(callback);
|
||||||
mqtt.setSocketTimeout(1);
|
mqtt.setSocketTimeout(1);
|
||||||
mqtt.setBufferSize(400);
|
|
||||||
connect();
|
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"
|
#include "tools.h"
|
||||||
|
|
||||||
void wifi_setup() {
|
void wifi_setup() {
|
||||||
Serial.printf("Connecting to WiFi %s...", WIFI_SSID);
|
LOG("Connecting to WiFi %s...", WIFI_SSID);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print(".");
|
LOG(".");
|
||||||
delay(300);
|
delay(300);
|
||||||
}
|
}
|
||||||
Serial.println();
|
LOGln(" Connected as %s", WiFi.localIP().toString().c_str());
|
||||||
LOGln("Connected as %s", WiFi.localIP().toString().c_str());
|
|
||||||
random16_add_entropy(micros());
|
random16_add_entropy(micros());
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user