mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
sysLog fixed, added logging library (for serial & syslog)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
-DW5500_CS_PIN=53
|
#-DW5500_CS_PIN=53
|
||||||
-DDMX_SMOOTH
|
-DDMX_SMOOTH
|
||||||
#-DSYSLOG_ENABLE
|
-DSYSLOG_ENABLE
|
||||||
-DMODBUS_DIMMER_PARAM=SERIAL_8E1
|
-DMODBUS_DIMMER_PARAM=SERIAL_8E1
|
||||||
#-DARTNET_ENABLE
|
-DARTNET_ENABLE
|
||||||
-DOTA
|
-DOTA
|
||||||
#-DWiz5500
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
-DWiz5500
|
|
||||||
-DW5500_CS_PIN=53
|
-DW5500_CS_PIN=53
|
||||||
-DARTNET_ENABLE
|
-DARTNET_ENABLE
|
||||||
-DDMX_SMOOTH
|
-DDMX_SMOOTH
|
||||||
-DMODBUS_DIMMER_PARAM=SERIAL_8N1
|
-DMODBUS_DIMMER_PARAM=SERIAL_8N1
|
||||||
-DMODBUS_SERIAL_BAUD=9600
|
-DMODBUS_SERIAL_BAUD=9600
|
||||||
|
-DOTA
|
||||||
|
-DSYSLOG_ENABLE
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ PWM Out
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
#include <Dhcp.h>
|
#include <Dhcp.h>
|
||||||
#if defined(OTA)
|
#if defined(OTA)
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@@ -109,13 +110,27 @@ NRFFlashStorage EEPROM;
|
|||||||
EthernetClient ethClient;
|
EthernetClient ethClient;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
#include <Syslog.h>
|
#include <Syslog.h>
|
||||||
EthernetUDP udpSyslogClient;
|
EthernetUDP udpSyslogClient;
|
||||||
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_IETF);
|
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD);
|
||||||
unsigned long nextSyslogPingTime;
|
unsigned long nextSyslogPingTime;
|
||||||
|
|
||||||
|
Streamlog debugSerial(&debugSerialPort,LOG_DEBUG,&udpSyslog);
|
||||||
|
Streamlog errorSerial(&debugSerialPort,LOG_ERROR,&udpSyslog);
|
||||||
|
Streamlog infoSerial (&debugSerialPort,LOG_INFO,&udpSyslog);
|
||||||
|
#else
|
||||||
|
Streamlog debugSerial(&debugSerialPort,LOG_DEBUG);
|
||||||
|
Streamlog errorSerial(&debugSerialPort,LOG_ERROR);
|
||||||
|
Streamlog infoSerial (&debugSerialPort,LOG_INFO);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lan_status lanStatus = INITIAL_STATE;
|
lan_status lanStatus = INITIAL_STATE;
|
||||||
|
|
||||||
|
|
||||||
@@ -598,8 +613,9 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
||||||
}
|
}
|
||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
//debugSerial<<"debugSerial:";
|
|
||||||
delay(100);
|
udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
|
||||||
|
|
||||||
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
|
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
|
||||||
char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
|
char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
|
||||||
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
|
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
|
||||||
@@ -620,7 +636,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
||||||
// char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
// char *client_id = aJson.getArrayItemartnet(mqttArr, 0)->valuestring;
|
||||||
char *servername = getStringFromConfig(mqttArr, 1);
|
char *servername = getStringFromConfig(mqttArr, 1);
|
||||||
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
|
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
|
||||||
if (n >= 4) user = getStringFromConfig(mqttArr, 3);
|
if (n >= 4) user = getStringFromConfig(mqttArr, 3);
|
||||||
@@ -1231,7 +1247,7 @@ void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
|||||||
for (int i = OFFSET_MAC; i < OFFSET_MAC+EEPROM_FIX_PART_LEN; i++)
|
for (int i = OFFSET_MAC; i < OFFSET_MAC+EEPROM_FIX_PART_LEN; i++)
|
||||||
EEPROM.write(i, 0);
|
EEPROM.write(i, 0);
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(EEPROM_signature); i++)
|
for (int i = 0; i < EEPROM_SIGNATURE_LENGTH; i++)
|
||||||
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
||||||
|
|
||||||
debugSerial<<F("EEPROM cleared\n");
|
debugSerial<<F("EEPROM cleared\n");
|
||||||
@@ -1483,8 +1499,6 @@ void postTransmission() {
|
|||||||
|
|
||||||
void setup_main() {
|
void setup_main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
memset(&UniqueID,0,sizeof(UniqueID));
|
memset(&UniqueID,0,sizeof(UniqueID));
|
||||||
#endif
|
#endif
|
||||||
@@ -1498,8 +1512,8 @@ void setup_main() {
|
|||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
|
|
||||||
//Checkin EEPROM integrity (signature)
|
//Checkin EEPROM integrity (signature)
|
||||||
for (int i=OFFSET_SIGNATURE;i<OFFSET_SIGNATURE+sizeof(EEPROM_SIGNATURE);i++)
|
for (int i=0;i<EEPROM_SIGNATURE_LENGTH;i++)
|
||||||
if (EEPROM.read(i)!=EEPROM_signature[i])
|
if (EEPROM.read(i+OFFSET_SIGNATURE)!=EEPROM_signature[i])
|
||||||
{
|
{
|
||||||
cmdFunctionClearEEPROM(0,NULL);
|
cmdFunctionClearEEPROM(0,NULL);
|
||||||
break;
|
break;
|
||||||
@@ -1813,11 +1827,6 @@ void loop_main() {
|
|||||||
dmxout.update();
|
dmxout.update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SYSLOG_ENABLE
|
|
||||||
// debugSerial<<F("#"));
|
|
||||||
// udpSyslog.log(LOG_INFO, "Ping syslog:");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void owIdle(void) {
|
void owIdle(void) {
|
||||||
|
|||||||
@@ -64,6 +64,9 @@
|
|||||||
//#include <EEPROM.h>
|
//#include <EEPROM.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "streamlog.h"
|
||||||
|
extern Streamlog debugSerial;
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
#define wdt_res() watchdogReset()
|
#define wdt_res() watchdogReset()
|
||||||
#define wdt_en()
|
#define wdt_en()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
#include <M5Stack.h>
|
#include <M5Stack.h>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "textconst.h"
|
#include "textconst.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#ifndef AC_Serial
|
#ifndef AC_Serial
|
||||||
#define AC_Serial Serial3
|
#define AC_Serial Serial3
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
extern aJsonObject *modbusObj;
|
extern aJsonObject *modbusObj;
|
||||||
extern ModbusMaster node;
|
extern ModbusMaster node;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
static int driverStatus = CST_UNKNOWN;
|
static int driverStatus = CST_UNKNOWN;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Streaming.h"
|
#include "Streaming.h"
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#ifdef ADAFRUIT_LED
|
#ifdef ADAFRUIT_LED
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// Configuration of drivers enabled
|
// Configuration of drivers enabled
|
||||||
|
#define SYSLOG_LOCAL_SOCKET 514
|
||||||
|
|
||||||
#ifndef FASTLED
|
#ifndef FASTLED
|
||||||
#define ADAFRUIT_LED
|
#define ADAFRUIT_LED
|
||||||
@@ -39,6 +40,8 @@
|
|||||||
|
|
||||||
#define MAXFLASHSTR 32
|
#define MAXFLASHSTR 32
|
||||||
#define PWDFLASHSTR 16
|
#define PWDFLASHSTR 16
|
||||||
|
#define EEPROM_SIGNATURE "LHCF"
|
||||||
|
#define EEPROM_SIGNATURE_LENGTH 4
|
||||||
|
|
||||||
#define OFFSET_MAC 0
|
#define OFFSET_MAC 0
|
||||||
#define OFFSET_IP OFFSET_MAC+6
|
#define OFFSET_IP OFFSET_MAC+6
|
||||||
@@ -48,10 +51,10 @@
|
|||||||
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
|
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
|
||||||
#define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+MAXFLASHSTR
|
#define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+MAXFLASHSTR
|
||||||
#define OFFSET_SIGNATURE OFFSET_MQTT_PWD+PWDFLASHSTR
|
#define OFFSET_SIGNATURE OFFSET_MQTT_PWD+PWDFLASHSTR
|
||||||
#define EEPROM_offset_NotAlligned OFFSET_SIGNATURE+4
|
#define EEPROM_offset_NotAlligned OFFSET_SIGNATURE+EEPROM_SIGNATURE_LENGTH
|
||||||
#define EEPROM_offsetJSON EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3))
|
#define EEPROM_offsetJSON EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3))
|
||||||
#define EEPROM_FIX_PART_LEN EEPROM_offsetJSON-OFFSET_MAC
|
#define EEPROM_FIX_PART_LEN EEPROM_offsetJSON-OFFSET_MAC
|
||||||
#define EEPROM_SIGNATURE "LHCF"
|
|
||||||
|
|
||||||
#ifndef INTERVAL_CHECK_INPUT
|
#ifndef INTERVAL_CHECK_INPUT
|
||||||
#define INTERVAL_CHECK_INPUT 15
|
#define INTERVAL_CHECK_INPUT 15
|
||||||
@@ -218,10 +221,11 @@
|
|||||||
//#define debugSerial M5.Lcd
|
//#define debugSerial M5.Lcd
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
#ifndef debugSerial
|
#ifndef debugSerialPort
|
||||||
#define debugSerial Serial
|
#define debugSerialPort Serial
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef Wiz5500
|
#ifndef Wiz5500
|
||||||
#define W5100_ETHERNET_SHIELD
|
#define W5100_ETHERNET_SHIELD
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
OneWire *oneWire = NULL;
|
OneWire *oneWire = NULL;
|
||||||
|
|||||||
63
lighthub/streamlog.cpp
Normal file
63
lighthub/streamlog.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "streamlog.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
Streamlog::Streamlog (UARTClass * _serialPort, int _severity , Syslog * _syslog )
|
||||||
|
{
|
||||||
|
serialPort=_serialPort;
|
||||||
|
severity=_severity;
|
||||||
|
syslog=_syslog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Streamlog::begin(unsigned long speed)
|
||||||
|
{
|
||||||
|
if (serialPort) serialPort->begin(speed);
|
||||||
|
};
|
||||||
|
|
||||||
|
void Streamlog::end()
|
||||||
|
{
|
||||||
|
if (serialPort) serialPort->end();
|
||||||
|
};
|
||||||
|
|
||||||
|
int Streamlog::available(void)
|
||||||
|
{
|
||||||
|
if (serialPort) return serialPort->available();
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Streamlog::peek(void)
|
||||||
|
{
|
||||||
|
if (serialPort) return serialPort->peek();
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Streamlog::read(void)
|
||||||
|
{
|
||||||
|
if (serialPort) return serialPort->read();
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void Streamlog::flush(void)
|
||||||
|
{
|
||||||
|
if (serialPort) serialPort->flush();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t Streamlog::write(uint8_t ch)
|
||||||
|
{
|
||||||
|
#ifdef SYSLOG_ENABLE
|
||||||
|
if (ch=='\n')
|
||||||
|
{
|
||||||
|
logBuffer[logBufferPos]=0;
|
||||||
|
if (syslog) syslog->log(severity,(char *)logBuffer);
|
||||||
|
logBufferPos=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (logBufferPos<LOGBUFFER_SIZE-1 && (ch!='\r')) logBuffer[logBufferPos++]=ch;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (serialPort) return serialPort->write(ch);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
41
lighthub/streamlog.h
Normal file
41
lighthub/streamlog.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include <Print.h>
|
||||||
|
#include <UARTClass.h>
|
||||||
|
#include <Syslog.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define LOG_DEBUG 7
|
||||||
|
#define LOG_INFO 6
|
||||||
|
#define LOG_ERROR 3
|
||||||
|
|
||||||
|
#ifndef LOGBUFFER_SIZE
|
||||||
|
#define LOGBUFFER_SIZE 80
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint8_t serialDebugLevel = 7;
|
||||||
|
static uint8_t udpDebugLevel =7;
|
||||||
|
|
||||||
|
#ifdef SYSLOG_ENABLE
|
||||||
|
static char logBuffer[LOGBUFFER_SIZE];
|
||||||
|
static int logBufferPos=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Streamlog : public Print
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Streamlog (UARTClass * _serialPort, int _severity = LOG_DEBUG, Syslog * _syslog = NULL);
|
||||||
|
// {serialPort=_serialPort;severity=_severity; syslog=_syslog; }
|
||||||
|
void begin(unsigned long speed);
|
||||||
|
void end() ;
|
||||||
|
|
||||||
|
int available(void);
|
||||||
|
int peek(void);
|
||||||
|
int read(void);
|
||||||
|
void flush(void);
|
||||||
|
size_t write(uint8_t ch);
|
||||||
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||||
|
operator bool() {return true;};
|
||||||
|
private:
|
||||||
|
uint16_t severity;
|
||||||
|
UARTClass *serialPort;
|
||||||
|
Syslog * syslog;
|
||||||
|
};
|
||||||
@@ -22,6 +22,7 @@ e-mail anklimov@gmail.com
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|||||||
@@ -264,6 +264,11 @@ platform = atmelsam
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
board = due
|
board = due
|
||||||
build_flags = !python get_build_flags.py due
|
build_flags = !python get_build_flags.py due
|
||||||
|
; Need to place arduinoOTA utility from Arduino IDE distribution to folder in your PATH
|
||||||
|
;fix address and password
|
||||||
|
;upload_flags =
|
||||||
|
upload_command = arduinoOTA -address 192.168.88.21 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
||||||
|
upload_protocol = custom
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
@@ -546,6 +551,8 @@ platform = atmelsam
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
board = due
|
board = due
|
||||||
build_flags = !python get_build_flags.py lighthub21
|
build_flags = !python get_build_flags.py lighthub21
|
||||||
|
;upload_command = arduinoOTA -address 192.168.88.34 -port 65280 -username arduino -password password -b -upload /sketch -sketch $SOURCE
|
||||||
|
;upload_protocol = custom
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
@@ -555,7 +562,7 @@ lib_ignore =
|
|||||||
WifiManager
|
WifiManager
|
||||||
DmxSimple
|
DmxSimple
|
||||||
httpClient
|
httpClient
|
||||||
Ethernet
|
Ethernet2
|
||||||
Ethernet3
|
Ethernet3
|
||||||
NRFFlashStorage
|
NRFFlashStorage
|
||||||
WebServer
|
WebServer
|
||||||
@@ -573,7 +580,7 @@ lib_deps =
|
|||||||
https://github.com/anklimov/aJson
|
https://github.com/anklimov/aJson
|
||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
https://github.com/anklimov/Ethernet2
|
https://github.com/anklimov/Ethernet
|
||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
https://github.com/anklimov/Artnet.git
|
https://github.com/anklimov/Artnet.git
|
||||||
FastLED@3.3.2
|
FastLED@3.3.2
|
||||||
|
|||||||
Reference in New Issue
Block a user