LOGln now logs to a central syslog server, if available.
This commit is contained in:
parent
47cd48d572
commit
11dbea0302
@ -39,4 +39,7 @@
|
|||||||
#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
|
8
include/syslog.h
Normal file
8
include/syslog.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
|
#ifdef SYSLOG_HOST
|
||||||
|
void syslog(String msg, uint8_t severity=7);
|
||||||
|
#endif
|
@ -1,8 +1,15 @@
|
|||||||
#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()
|
||||||
|
|
||||||
|
#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()
|
#define LOGln(...) Serial.printf(__VA_ARGS__); Serial.println()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void clear_leds();
|
void clear_leds();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#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;
|
||||||
@ -173,6 +174,8 @@ void setup() {
|
|||||||
delay(250);
|
delay(250);
|
||||||
show_status(0);
|
show_status(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
syslog("Setup done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
17
src/syslog.cpp
Normal file
17
src/syslog.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "syslog.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef SYSLOG_HOST
|
||||||
|
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 " espleaf 1 1 - ");
|
||||||
|
udp.write(msg.c_str());
|
||||||
|
udp.endPacket();
|
||||||
|
}
|
||||||
|
#endif
|
@ -2,13 +2,14 @@
|
|||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
void wifi_setup() {
|
void wifi_setup() {
|
||||||
LOG("Connecting to WiFi %s...", WIFI_SSID);
|
Serial.printf("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) {
|
||||||
LOG(".");
|
Serial.print(".");
|
||||||
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