mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 21:24:34 +00:00
Formatting
This commit is contained in:
parent
202223236d
commit
ff029ad752
@ -24,218 +24,234 @@ SOFTWARE.*/
|
|||||||
|
|
||||||
#include "DebugConfiguration.h"
|
#include "DebugConfiguration.h"
|
||||||
|
|
||||||
Syslog::Syslog(UDP &client) {
|
Syslog::Syslog(UDP &client)
|
||||||
this->_client = &client;
|
{
|
||||||
this->_server = NULL;
|
this->_client = &client;
|
||||||
this->_port = 0;
|
this->_server = NULL;
|
||||||
this->_deviceHostname = SYSLOG_NILVALUE;
|
this->_port = 0;
|
||||||
this->_appName = SYSLOG_NILVALUE;
|
this->_deviceHostname = SYSLOG_NILVALUE;
|
||||||
this->_priDefault = LOGLEVEL_KERN;
|
this->_appName = SYSLOG_NILVALUE;
|
||||||
|
this->_priDefault = LOGLEVEL_KERN;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::server(const char* server, uint16_t port) {
|
Syslog &Syslog::server(const char *server, uint16_t port)
|
||||||
this->_server = server;
|
{
|
||||||
this->_port = port;
|
this->_server = server;
|
||||||
return *this;
|
this->_port = port;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::server(IPAddress ip, uint16_t port) {
|
Syslog &Syslog::server(IPAddress ip, uint16_t port)
|
||||||
this->_ip = ip;
|
{
|
||||||
this->_server = NULL;
|
this->_ip = ip;
|
||||||
this->_port = port;
|
this->_server = NULL;
|
||||||
return *this;
|
this->_port = port;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::deviceHostname(const char* deviceHostname) {
|
Syslog &Syslog::deviceHostname(const char *deviceHostname)
|
||||||
this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname;
|
{
|
||||||
return *this;
|
this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::appName(const char* appName) {
|
Syslog &Syslog::appName(const char *appName)
|
||||||
this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName;
|
{
|
||||||
return *this;
|
this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::defaultPriority(uint16_t pri) {
|
Syslog &Syslog::defaultPriority(uint16_t pri)
|
||||||
this->_priDefault = pri;
|
{
|
||||||
return *this;
|
this->_priDefault = pri;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog &Syslog::logMask(uint8_t priMask) {
|
Syslog &Syslog::logMask(uint8_t priMask)
|
||||||
this->_priMask = priMask;
|
{
|
||||||
return *this;
|
this->_priMask = priMask;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Syslog::enable() {
|
void Syslog::enable()
|
||||||
this->_enabled = true;
|
{
|
||||||
|
this->_enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Syslog::disable() {
|
void Syslog::disable()
|
||||||
this->_enabled = false;
|
{
|
||||||
|
this->_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::isEnabled()
|
bool Syslog::isEnabled()
|
||||||
{
|
{
|
||||||
return this->_enabled;
|
return this->_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) {
|
bool Syslog::log(uint16_t pri, const __FlashStringHelper *message)
|
||||||
return this->_sendLog(pri, message);
|
{
|
||||||
|
return this->_sendLog(pri, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const String &message) {
|
bool Syslog::log(uint16_t pri, const String &message)
|
||||||
return this->_sendLog(pri, message.c_str());
|
{
|
||||||
|
return this->_sendLog(pri, message.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const char *message) {
|
bool Syslog::log(uint16_t pri, const char *message)
|
||||||
return this->_sendLog(pri, message);
|
{
|
||||||
|
return this->_sendLog(pri, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) {
|
bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args)
|
||||||
char *message;
|
{
|
||||||
size_t initialLen;
|
char *message;
|
||||||
size_t len;
|
size_t initialLen;
|
||||||
bool result;
|
size_t len;
|
||||||
|
bool result;
|
||||||
|
|
||||||
initialLen = strlen(fmt);
|
initialLen = strlen(fmt);
|
||||||
|
|
||||||
message = new char[initialLen + 1];
|
message = new char[initialLen + 1];
|
||||||
|
|
||||||
|
len = vsnprintf(message, initialLen + 1, fmt, args);
|
||||||
|
if (len > initialLen) {
|
||||||
|
delete[] message;
|
||||||
|
message = new char[len + 1];
|
||||||
|
|
||||||
|
vsnprintf(message, len + 1, fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = this->_sendLog(pri, message);
|
||||||
|
|
||||||
len = vsnprintf(message, initialLen + 1, fmt, args);
|
|
||||||
if (len > initialLen) {
|
|
||||||
delete[] message;
|
delete[] message;
|
||||||
message = new char[len + 1];
|
return result;
|
||||||
|
|
||||||
vsnprintf(message, len + 1, fmt, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = this->_sendLog(pri, message);
|
|
||||||
|
|
||||||
delete[] message;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) {
|
bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args)
|
||||||
char *message;
|
{
|
||||||
size_t initialLen;
|
char *message;
|
||||||
size_t len;
|
size_t initialLen;
|
||||||
bool result;
|
size_t len;
|
||||||
|
bool result;
|
||||||
|
|
||||||
initialLen = strlen_P(fmt_P);
|
initialLen = strlen_P(fmt_P);
|
||||||
|
|
||||||
message = new char[initialLen + 1];
|
message = new char[initialLen + 1];
|
||||||
|
|
||||||
|
len = vsnprintf_P(message, initialLen + 1, fmt_P, args);
|
||||||
|
if (len > initialLen) {
|
||||||
|
delete[] message;
|
||||||
|
message = new char[len + 1];
|
||||||
|
|
||||||
|
vsnprintf(message, len + 1, fmt_P, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = this->_sendLog(pri, message);
|
||||||
|
|
||||||
len = vsnprintf_P(message, initialLen + 1, fmt_P, args);
|
|
||||||
if (len > initialLen) {
|
|
||||||
delete[] message;
|
delete[] message;
|
||||||
message = new char[len + 1];
|
return result;
|
||||||
|
|
||||||
vsnprintf(message, len + 1, fmt_P, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = this->_sendLog(pri, message);
|
|
||||||
|
|
||||||
delete[] message;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Syslog::logf(uint16_t pri, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
bool result;
|
||||||
|
|
||||||
bool Syslog::logf(uint16_t pri, const char *fmt, ...) {
|
va_start(args, fmt);
|
||||||
va_list args;
|
result = this->vlogf(pri, fmt, args);
|
||||||
bool result;
|
va_end(args);
|
||||||
|
return result;
|
||||||
va_start(args, fmt);
|
|
||||||
result = this->vlogf(pri, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) {
|
bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...)
|
||||||
va_list args;
|
{
|
||||||
bool result;
|
va_list args;
|
||||||
|
bool result;
|
||||||
|
|
||||||
va_start(args, fmt_P);
|
va_start(args, fmt_P);
|
||||||
result = this->vlogf_P(pri, fmt_P, args);
|
result = this->vlogf_P(pri, fmt_P, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Syslog::_sendLog(uint16_t pri, const char *message) {
|
inline bool Syslog::_sendLog(uint16_t pri, const char *message)
|
||||||
int result;
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
if (!this->_enabled)
|
if (!this->_enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
|
if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Check priority against priMask values.
|
||||||
|
if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Set default facility if none specified.
|
||||||
|
if ((pri & LOG_FACMASK) == 0)
|
||||||
|
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);
|
||||||
|
|
||||||
|
if (this->_server != NULL) {
|
||||||
|
result = this->_client->beginPacket(this->_server, this->_port);
|
||||||
|
} else {
|
||||||
|
result = this->_client->beginPacket(this->_ip, this->_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this->_client->print('<');
|
||||||
|
this->_client->print(pri);
|
||||||
|
this->_client->print(F(">1 - "));
|
||||||
|
this->_client->print(this->_deviceHostname);
|
||||||
|
this->_client->print(' ');
|
||||||
|
this->_client->print(this->_appName);
|
||||||
|
this->_client->print(F(" - - - \xEF\xBB\xBF"));
|
||||||
|
this->_client->print(F("[0]: "));
|
||||||
|
this->_client->print(message);
|
||||||
|
this->_client->endPacket();
|
||||||
|
|
||||||
// Check priority against priMask values.
|
|
||||||
if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Set default facility if none specified.
|
|
||||||
if ((pri & LOG_FACMASK) == 0)
|
|
||||||
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);
|
|
||||||
|
|
||||||
if (this->_server != NULL) {
|
|
||||||
result = this->_client->beginPacket(this->_server, this->_port);
|
|
||||||
} else {
|
|
||||||
result = this->_client->beginPacket(this->_ip, this->_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->_client->print('<');
|
|
||||||
this->_client->print(pri);
|
|
||||||
this->_client->print(F(">1 - "));
|
|
||||||
this->_client->print(this->_deviceHostname);
|
|
||||||
this->_client->print(' ');
|
|
||||||
this->_client->print(this->_appName);
|
|
||||||
this->_client->print(F(" - - - \xEF\xBB\xBF"));
|
|
||||||
this->_client->print(F("[0]: "));
|
|
||||||
this->_client->print(message);
|
|
||||||
this->_client->endPacket();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) {
|
inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message)
|
||||||
int result;
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
if (!this->_enabled)
|
if (!this->_enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
|
if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Check priority against priMask values.
|
||||||
|
if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Set default facility if none specified.
|
||||||
|
if ((pri & LOG_FACMASK) == 0)
|
||||||
|
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);
|
||||||
|
|
||||||
|
if (this->_server != NULL) {
|
||||||
|
result = this->_client->beginPacket(this->_server, this->_port);
|
||||||
|
} else {
|
||||||
|
result = this->_client->beginPacket(this->_ip, this->_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this->_client->print('<');
|
||||||
|
this->_client->print(pri);
|
||||||
|
this->_client->print(F(">1 - "));
|
||||||
|
this->_client->print(this->_deviceHostname);
|
||||||
|
this->_client->print(' ');
|
||||||
|
this->_client->print(this->_appName);
|
||||||
|
this->_client->print(F(" - - - \xEF\xBB\xBF"));
|
||||||
|
this->_client->print(message);
|
||||||
|
this->_client->endPacket();
|
||||||
|
|
||||||
// Check priority against priMask values.
|
|
||||||
if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Set default facility if none specified.
|
|
||||||
if ((pri & LOG_FACMASK) == 0)
|
|
||||||
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);
|
|
||||||
|
|
||||||
if (this->_server != NULL) {
|
|
||||||
result = this->_client->beginPacket(this->_server, this->_port);
|
|
||||||
} else {
|
|
||||||
result = this->_client->beginPacket(this->_ip, this->_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->_client->print('<');
|
|
||||||
this->_client->print(pri);
|
|
||||||
this->_client->print(F(">1 - "));
|
|
||||||
this->_client->print(this->_deviceHostname);
|
|
||||||
this->_client->print(' ');
|
|
||||||
this->_client->print(this->_appName);
|
|
||||||
this->_client->print(F(" - - - \xEF\xBB\xBF"));
|
|
||||||
this->_client->print(message);
|
|
||||||
this->_client->endPacket();
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef SYSLOG_H
|
#ifndef SYSLOG_H
|
||||||
#define SYSLOG_H
|
#define SYSLOG_H
|
||||||
|
|
||||||
// DEBUG LED
|
// DEBUG LED
|
||||||
#ifndef LED_INVERTED
|
#ifndef LED_INVERTED
|
||||||
@ -17,10 +17,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MESHTASTIC_LOG_LEVEL_DEBUG "DEBUG"
|
#define MESHTASTIC_LOG_LEVEL_DEBUG "DEBUG"
|
||||||
#define MESHTASTIC_LOG_LEVEL_INFO "INFO "
|
#define MESHTASTIC_LOG_LEVEL_INFO "INFO "
|
||||||
#define MESHTASTIC_LOG_LEVEL_WARN "WARN "
|
#define MESHTASTIC_LOG_LEVEL_WARN "WARN "
|
||||||
#define MESHTASTIC_LOG_LEVEL_ERROR "ERROR"
|
#define MESHTASTIC_LOG_LEVEL_ERROR "ERROR"
|
||||||
#define MESHTASTIC_LOG_LEVEL_CRIT "CRIT "
|
#define MESHTASTIC_LOG_LEVEL_CRIT "CRIT "
|
||||||
#define MESHTASTIC_LOG_LEVEL_TRACE "TRACE"
|
#define MESHTASTIC_LOG_LEVEL_TRACE "TRACE"
|
||||||
|
|
||||||
#include "SerialConsole.h"
|
#include "SerialConsole.h"
|
||||||
@ -54,49 +54,49 @@
|
|||||||
|
|
||||||
#define SYSLOG_NILVALUE "-"
|
#define SYSLOG_NILVALUE "-"
|
||||||
|
|
||||||
#define SYSLOG_CRIT 2 /* critical conditions */
|
#define SYSLOG_CRIT 2 /* critical conditions */
|
||||||
#define SYSLOG_ERR 3 /* error conditions */
|
#define SYSLOG_ERR 3 /* error conditions */
|
||||||
#define SYSLOG_WARN 4 /* warning conditions */
|
#define SYSLOG_WARN 4 /* warning conditions */
|
||||||
#define SYSLOG_INFO 6 /* informational */
|
#define SYSLOG_INFO 6 /* informational */
|
||||||
#define SYSLOG_DEBUG 7 /* debug-level messages */
|
#define SYSLOG_DEBUG 7 /* debug-level messages */
|
||||||
// trace does not go out to syslog (yet?)
|
// trace does not go out to syslog (yet?)
|
||||||
|
|
||||||
#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
|
#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
|
||||||
/* extract priority */
|
/* extract priority */
|
||||||
#define LOG_PRI(p) ((p) & LOG_PRIMASK)
|
#define LOG_PRI(p) ((p)&LOG_PRIMASK)
|
||||||
#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
|
#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
|
||||||
|
|
||||||
/* facility codes */
|
/* facility codes */
|
||||||
#define LOGLEVEL_KERN (0<<3) /* kernel messages */
|
#define LOGLEVEL_KERN (0 << 3) /* kernel messages */
|
||||||
#define LOGLEVEL_USER (1<<3) /* random user-level messages */
|
#define LOGLEVEL_USER (1 << 3) /* random user-level messages */
|
||||||
#define LOGLEVEL_MAIL (2<<3) /* mail system */
|
#define LOGLEVEL_MAIL (2 << 3) /* mail system */
|
||||||
#define LOGLEVEL_DAEMON (3<<3) /* system daemons */
|
#define LOGLEVEL_DAEMON (3 << 3) /* system daemons */
|
||||||
#define LOGLEVEL_AUTH (4<<3) /* security/authorization messages */
|
#define LOGLEVEL_AUTH (4 << 3) /* security/authorization messages */
|
||||||
#define LOGLEVEL_SYSLOG (5<<3) /* messages generated internally by syslogd */
|
#define LOGLEVEL_SYSLOG (5 << 3) /* messages generated internally by syslogd */
|
||||||
#define LOGLEVEL_LPR (6<<3) /* line printer subsystem */
|
#define LOGLEVEL_LPR (6 << 3) /* line printer subsystem */
|
||||||
#define LOGLEVEL_NEWS (7<<3) /* network news subsystem */
|
#define LOGLEVEL_NEWS (7 << 3) /* network news subsystem */
|
||||||
#define LOGLEVEL_UUCP (8<<3) /* UUCP subsystem */
|
#define LOGLEVEL_UUCP (8 << 3) /* UUCP subsystem */
|
||||||
#define LOGLEVEL_CRON (9<<3) /* clock daemon */
|
#define LOGLEVEL_CRON (9 << 3) /* clock daemon */
|
||||||
#define LOGLEVEL_AUTHPRIV (10<<3) /* security/authorization messages (private) */
|
#define LOGLEVEL_AUTHPRIV (10 << 3) /* security/authorization messages (private) */
|
||||||
#define LOGLEVEL_FTP (11<<3) /* ftp daemon */
|
#define LOGLEVEL_FTP (11 << 3) /* ftp daemon */
|
||||||
|
|
||||||
/* other codes through 15 reserved for system use */
|
/* other codes through 15 reserved for system use */
|
||||||
#define LOGLEVEL_LOCAL0 (16<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL0 (16 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL1 (17<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL1 (17 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL2 (18<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL2 (18 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL3 (19<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL3 (19 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL4 (20<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL4 (20 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL5 (21<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL5 (21 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL6 (22<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL6 (22 << 3) /* reserved for local use */
|
||||||
#define LOGLEVEL_LOCAL7 (23<<3) /* reserved for local use */
|
#define LOGLEVEL_LOCAL7 (23 << 3) /* reserved for local use */
|
||||||
|
|
||||||
#define LOG_NFACILITIES 24 /* current number of facilities */
|
#define LOG_NFACILITIES 24 /* current number of facilities */
|
||||||
#define LOG_FACMASK 0x03f8 /* mask to extract facility part */
|
#define LOG_FACMASK 0x03f8 /* mask to extract facility part */
|
||||||
/* facility of pri */
|
/* facility of pri */
|
||||||
#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
|
#define LOG_FAC(p) (((p)&LOG_FACMASK) >> 3)
|
||||||
|
|
||||||
#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
|
#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
|
||||||
#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
|
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1) /* all priorities through pri */
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// AXP192 (Rev1-specific options)
|
// AXP192 (Rev1-specific options)
|
||||||
@ -108,14 +108,15 @@
|
|||||||
// Default Bluetooth PIN
|
// Default Bluetooth PIN
|
||||||
#define defaultBLEPin 123456
|
#define defaultBLEPin 123456
|
||||||
|
|
||||||
class Syslog {
|
class Syslog
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
UDP* _client;
|
UDP *_client;
|
||||||
IPAddress _ip;
|
IPAddress _ip;
|
||||||
const char* _server;
|
const char *_server;
|
||||||
uint16_t _port;
|
uint16_t _port;
|
||||||
const char* _deviceHostname;
|
const char *_deviceHostname;
|
||||||
const char* _appName;
|
const char *_appName;
|
||||||
uint16_t _priDefault;
|
uint16_t _priDefault;
|
||||||
uint8_t _priMask = 0xff;
|
uint8_t _priMask = 0xff;
|
||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
@ -126,10 +127,10 @@ class Syslog {
|
|||||||
public:
|
public:
|
||||||
Syslog(UDP &client);
|
Syslog(UDP &client);
|
||||||
|
|
||||||
Syslog &server(const char* server, uint16_t port);
|
Syslog &server(const char *server, uint16_t port);
|
||||||
Syslog &server(IPAddress ip, uint16_t port);
|
Syslog &server(IPAddress ip, uint16_t port);
|
||||||
Syslog &deviceHostname(const char* deviceHostname);
|
Syslog &deviceHostname(const char *deviceHostname);
|
||||||
Syslog &appName(const char* appName);
|
Syslog &appName(const char *appName);
|
||||||
Syslog &defaultPriority(uint16_t pri = LOGLEVEL_KERN);
|
Syslog &defaultPriority(uint16_t pri = LOGLEVEL_KERN);
|
||||||
Syslog &logMask(uint8_t priMask);
|
Syslog &logMask(uint8_t priMask);
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ class Syslog {
|
|||||||
|
|
||||||
bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0)));
|
bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0)));
|
||||||
bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0)));
|
bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0)));
|
||||||
|
|
||||||
bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4)));
|
bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "RTC.h"
|
#include "RTC.h"
|
||||||
#include "concurrency/Periodic.h"
|
#include "concurrency/Periodic.h"
|
||||||
#include <SPI.h>
|
|
||||||
#include <RAK13800_W5100S.h>
|
|
||||||
#include "target_specific.h"
|
|
||||||
#include "mesh/api/ethServerAPI.h"
|
#include "mesh/api/ethServerAPI.h"
|
||||||
#include "mqtt/MQTT.h"
|
#include "mqtt/MQTT.h"
|
||||||
|
#include "target_specific.h"
|
||||||
|
#include <RAK13800_W5100S.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
@ -38,9 +38,9 @@ static int32_t reconnectETH()
|
|||||||
LOG_INFO("Starting NTP time client\n");
|
LOG_INFO("Starting NTP time client\n");
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
timeClient.setUpdateInterval(60 * 60); // Update once an hour
|
timeClient.setUpdateInterval(60 * 60); // Update once an hour
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(config.network.rsyslog_server[0]) {
|
if (config.network.rsyslog_server[0]) {
|
||||||
LOG_INFO("Starting Syslog client\n");
|
LOG_INFO("Starting Syslog client\n");
|
||||||
// Defaults
|
// Defaults
|
||||||
int serverPort = 514;
|
int serverPort = 514;
|
||||||
@ -74,7 +74,7 @@ static int32_t reconnectETH()
|
|||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
if (isEthernetAvailable() && (ntp_renew < millis())) {
|
if (isEthernetAvailable() && (ntp_renew < millis())) {
|
||||||
|
|
||||||
LOG_INFO("Updating NTP time from %s\n", config.network.ntp_server);
|
LOG_INFO("Updating NTP time from %s\n", config.network.ntp_server);
|
||||||
if (timeClient.update()) {
|
if (timeClient.update()) {
|
||||||
LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n");
|
LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n");
|
||||||
@ -104,12 +104,12 @@ bool initEthernet()
|
|||||||
|
|
||||||
#ifdef PIN_ETHERNET_RESET
|
#ifdef PIN_ETHERNET_RESET
|
||||||
pinMode(PIN_ETHERNET_RESET, OUTPUT);
|
pinMode(PIN_ETHERNET_RESET, OUTPUT);
|
||||||
digitalWrite(PIN_ETHERNET_RESET, LOW); // Reset Time.
|
digitalWrite(PIN_ETHERNET_RESET, LOW); // Reset Time.
|
||||||
delay(100);
|
delay(100);
|
||||||
digitalWrite(PIN_ETHERNET_RESET, HIGH); // Reset Time.
|
digitalWrite(PIN_ETHERNET_RESET, HIGH); // Reset Time.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Ethernet.init( ETH_SPI_PORT, PIN_ETHERNET_SS );
|
Ethernet.init(ETH_SPI_PORT, PIN_ETHERNET_SS);
|
||||||
|
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ bool initEthernet()
|
|||||||
// createSSLCert();
|
// createSSLCert();
|
||||||
|
|
||||||
getMacAddr(mac); // FIXME use the BLE MAC for now...
|
getMacAddr(mac); // FIXME use the BLE MAC for now...
|
||||||
mac[0] &= 0xfe; // Make sure this is not a multicast MAC
|
mac[0] &= 0xfe; // Make sure this is not a multicast MAC
|
||||||
|
|
||||||
if (config.network.address_mode == Config_NetworkConfig_AddressMode_DHCP) {
|
if (config.network.address_mode == Config_NetworkConfig_AddressMode_DHCP) {
|
||||||
LOG_INFO("starting Ethernet DHCP\n");
|
LOG_INFO("starting Ethernet DHCP\n");
|
||||||
@ -138,15 +138,19 @@ bool initEthernet()
|
|||||||
} else if (Ethernet.linkStatus() == LinkOFF) {
|
} else if (Ethernet.linkStatus() == LinkOFF) {
|
||||||
LOG_ERROR("Ethernet cable is not connected.\n");
|
LOG_ERROR("Ethernet cable is not connected.\n");
|
||||||
return false;
|
return false;
|
||||||
} else{
|
} else {
|
||||||
LOG_ERROR("Unknown Ethernet error.\n");
|
LOG_ERROR("Unknown Ethernet error.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Local IP %u.%u.%u.%u\n",Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]);
|
LOG_INFO("Local IP %u.%u.%u.%u\n", Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2],
|
||||||
LOG_INFO("Subnet Mask %u.%u.%u.%u\n",Ethernet.subnetMask()[0], Ethernet.subnetMask()[1], Ethernet.subnetMask()[2], Ethernet.subnetMask()[3]);
|
Ethernet.localIP()[3]);
|
||||||
LOG_INFO("Gateway IP %u.%u.%u.%u\n",Ethernet.gatewayIP()[0], Ethernet.gatewayIP()[1], Ethernet.gatewayIP()[2], Ethernet.gatewayIP()[3]);
|
LOG_INFO("Subnet Mask %u.%u.%u.%u\n", Ethernet.subnetMask()[0], Ethernet.subnetMask()[1], Ethernet.subnetMask()[2],
|
||||||
LOG_INFO("DNS Server IP %u.%u.%u.%u\n",Ethernet.dnsServerIP()[0], Ethernet.dnsServerIP()[1], Ethernet.dnsServerIP()[2], Ethernet.dnsServerIP()[3]);
|
Ethernet.subnetMask()[3]);
|
||||||
|
LOG_INFO("Gateway IP %u.%u.%u.%u\n", Ethernet.gatewayIP()[0], Ethernet.gatewayIP()[1], Ethernet.gatewayIP()[2],
|
||||||
|
Ethernet.gatewayIP()[3]);
|
||||||
|
LOG_INFO("DNS Server IP %u.%u.%u.%u\n", Ethernet.dnsServerIP()[0], Ethernet.dnsServerIP()[1],
|
||||||
|
Ethernet.dnsServerIP()[2], Ethernet.dnsServerIP()[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ethEvent = new Periodic("ethConnect", reconnectETH);
|
ethEvent = new Periodic("ethConnect", reconnectETH);
|
||||||
@ -159,7 +163,8 @@ bool initEthernet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEthernetAvailable() {
|
bool isEthernetAvailable()
|
||||||
|
{
|
||||||
|
|
||||||
if (!config.network.eth_enabled) {
|
if (!config.network.eth_enabled) {
|
||||||
syslog.disable();
|
syslog.disable();
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
|
#include "mesh/http/WiFiAPClient.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "RTC.h"
|
#include "RTC.h"
|
||||||
#include "concurrency/Periodic.h"
|
#include "concurrency/Periodic.h"
|
||||||
#include "mesh/http/WiFiAPClient.h"
|
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mesh/http/WebServer.h"
|
|
||||||
#include "mesh/api/WiFiServerAPI.h"
|
#include "mesh/api/WiFiServerAPI.h"
|
||||||
|
#include "mesh/http/WebServer.h"
|
||||||
#include "mqtt/MQTT.h"
|
#include "mqtt/MQTT.h"
|
||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include <esp_wifi.h>
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
#include <esp_wifi.h>
|
||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
#include <NTPClient.h>
|
#include <NTPClient.h>
|
||||||
@ -50,7 +50,7 @@ static int32_t reconnectWiFi()
|
|||||||
const char *wifiPsw = config.network.wifi_psk;
|
const char *wifiPsw = config.network.wifi_psk;
|
||||||
|
|
||||||
if (config.network.wifi_enabled && needReconnect) {
|
if (config.network.wifi_enabled && needReconnect) {
|
||||||
|
|
||||||
if (!*wifiPsw) // Treat empty password as no password
|
if (!*wifiPsw) // Treat empty password as no password
|
||||||
wifiPsw = NULL;
|
wifiPsw = NULL;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ static int32_t reconnectWiFi()
|
|||||||
|
|
||||||
// Make sure we clear old connection credentials
|
// Make sure we clear old connection credentials
|
||||||
WiFi.disconnect(false, true);
|
WiFi.disconnect(false, true);
|
||||||
LOG_INFO("Reconnecting to WiFi access point %s\n",wifiName);
|
LOG_INFO("Reconnecting to WiFi access point %s\n", wifiName);
|
||||||
|
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ static int32_t reconnectWiFi()
|
|||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
if (WiFi.isConnected() && (((millis() - lastrun_ntp) > 43200000) || (lastrun_ntp == 0))) { // every 12 hours
|
if (WiFi.isConnected() && (((millis() - lastrun_ntp) > 43200000) || (lastrun_ntp == 0))) { // every 12 hours
|
||||||
LOG_DEBUG("Updating NTP time from %s\n",config.network.ntp_server);
|
LOG_DEBUG("Updating NTP time from %s\n", config.network.ntp_server);
|
||||||
if (timeClient.update()) {
|
if (timeClient.update()) {
|
||||||
LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n");
|
LOG_DEBUG("NTP Request Success - Setting RTCQualityNTP if needed\n");
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ static void onNetworkConnected()
|
|||||||
timeClient.setUpdateInterval(60 * 60); // Update once an hour
|
timeClient.setUpdateInterval(60 * 60); // Update once an hour
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(config.network.rsyslog_server[0]) {
|
if (config.network.rsyslog_server[0]) {
|
||||||
LOG_INFO("Starting Syslog client\n");
|
LOG_INFO("Starting Syslog client\n");
|
||||||
// Defaults
|
// Defaults
|
||||||
int serverPort = 514;
|
int serverPort = 514;
|
||||||
@ -195,10 +195,8 @@ bool initWifi()
|
|||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
if (config.network.address_mode == Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) {
|
if (config.network.address_mode == Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) {
|
||||||
WiFi.config(config.network.ipv4_config.ip,
|
WiFi.config(config.network.ipv4_config.ip, config.network.ipv4_config.gateway, config.network.ipv4_config.subnet,
|
||||||
config.network.ipv4_config.gateway,
|
config.network.ipv4_config.dns,
|
||||||
config.network.ipv4_config.subnet,
|
|
||||||
config.network.ipv4_config.dns,
|
|
||||||
config.network.ipv4_config.dns); // Wifi wants two DNS servers... set both to the same value
|
config.network.ipv4_config.dns); // Wifi wants two DNS servers... set both to the same value
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +205,6 @@ bool initWifi()
|
|||||||
|
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(
|
||||||
[](WiFiEvent_t event, WiFiEventInfo_t info) {
|
[](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
|
|
||||||
LOG_WARN("WiFi lost connection. Reason: %d\n", info.wifi_sta_disconnected.reason);
|
LOG_WARN("WiFi lost connection. Reason: %d\n", info.wifi_sta_disconnected.reason);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user