sysLog fixed, added logging library (for serial & syslog)

This commit is contained in:
2020-05-31 18:14:10 +03:00
parent 00e631515f
commit 8c95732164
16 changed files with 161 additions and 26 deletions

View File

@@ -1,7 +1,6 @@
-DW5500_CS_PIN=53
#-DW5500_CS_PIN=53
-DDMX_SMOOTH
#-DSYSLOG_ENABLE
-DSYSLOG_ENABLE
-DMODBUS_DIMMER_PARAM=SERIAL_8E1
#-DARTNET_ENABLE
-DARTNET_ENABLE
-DOTA
#-DWiz5500

View File

@@ -1,6 +1,7 @@
-DWiz5500
-DW5500_CS_PIN=53
-DARTNET_ENABLE
-DDMX_SMOOTH
-DMODBUS_DIMMER_PARAM=SERIAL_8N1
-DMODBUS_SERIAL_BAUD=9600
-DOTA
-DSYSLOG_ENABLE

View File

@@ -22,6 +22,7 @@ e-mail anklimov@gmail.com
#include "item.h"
#include "utils.h"
#include <PubSubClient.h>
#include "main.h"
#ifndef DHT_DISABLE
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)

View File

@@ -66,6 +66,7 @@ PWM Out
*/
#include "main.h"
#include <Dhcp.h>
#if defined(OTA)
#include <ArduinoOTA.h>
@@ -109,13 +110,27 @@ NRFFlashStorage EEPROM;
EthernetClient ethClient;
#endif
#ifdef SYSLOG_ENABLE
#include <Syslog.h>
EthernetUDP udpSyslogClient;
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_IETF);
Syslog udpSyslog(udpSyslogClient, SYSLOG_PROTO_BSD);
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
lan_status lanStatus = INITIAL_STATE;
@@ -598,8 +613,9 @@ void ip_ready_config_loaded_connecting_to_broker() {
debugSerial<<F("Device Name:")<<deviceName<<endl;
}
#ifdef SYSLOG_ENABLE
//debugSerial<<"debugSerial:";
delay(100);
udpSyslogClient.begin(SYSLOG_LOCAL_SOCKET);
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
@@ -620,7 +636,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
#endif
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);
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
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++)
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]);
debugSerial<<F("EEPROM cleared\n");
@@ -1483,8 +1499,6 @@ void postTransmission() {
void setup_main() {
#if defined(__SAM3X8E__)
memset(&UniqueID,0,sizeof(UniqueID));
#endif
@@ -1498,8 +1512,8 @@ void setup_main() {
printFirmwareVersionAndBuildOptions();
//Checkin EEPROM integrity (signature)
for (int i=OFFSET_SIGNATURE;i<OFFSET_SIGNATURE+sizeof(EEPROM_SIGNATURE);i++)
if (EEPROM.read(i)!=EEPROM_signature[i])
for (int i=0;i<EEPROM_SIGNATURE_LENGTH;i++)
if (EEPROM.read(i+OFFSET_SIGNATURE)!=EEPROM_signature[i])
{
cmdFunctionClearEEPROM(0,NULL);
break;
@@ -1813,11 +1827,6 @@ void loop_main() {
dmxout.update();
#endif
#ifdef SYSLOG_ENABLE
// debugSerial<<F("#"));
// udpSyslog.log(LOG_INFO, "Ping syslog:");
#endif
}
void owIdle(void) {

View File

@@ -64,6 +64,9 @@
//#include <EEPROM.h>
#endif
#include "streamlog.h"
extern Streamlog debugSerial;
#if defined(__SAM3X8E__)
#define wdt_res() watchdogReset()
#define wdt_en()

View File

@@ -3,6 +3,7 @@
#include "options.h"
#include "Streaming.h"
#include "item.h"
#include "main.h"
#if defined(M5STACK)
#include <M5Stack.h>

View File

@@ -6,6 +6,7 @@
#include "Streaming.h"
#include "item.h"
#include "textconst.h"
#include "main.h"
#ifndef AC_Serial
#define AC_Serial Serial3

View File

@@ -8,6 +8,7 @@
#include "item.h"
#include <ModbusMaster.h>
#include "main.h"
extern aJsonObject *modbusObj;
extern ModbusMaster node;

View File

@@ -6,6 +6,7 @@
#include "Streaming.h"
#include "item.h"
#include "main.h"
static int driverStatus = CST_UNKNOWN;

View File

@@ -6,6 +6,7 @@
#include "Streaming.h"
#include "item.h"
#include "main.h"
#ifdef ADAFRUIT_LED

View File

@@ -1,4 +1,5 @@
// Configuration of drivers enabled
#define SYSLOG_LOCAL_SOCKET 514
#ifndef FASTLED
#define ADAFRUIT_LED
@@ -39,6 +40,8 @@
#define MAXFLASHSTR 32
#define PWDFLASHSTR 16
#define EEPROM_SIGNATURE "LHCF"
#define EEPROM_SIGNATURE_LENGTH 4
#define OFFSET_MAC 0
#define OFFSET_IP OFFSET_MAC+6
@@ -48,10 +51,10 @@
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
#define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+MAXFLASHSTR
#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_FIX_PART_LEN EEPROM_offsetJSON-OFFSET_MAC
#define EEPROM_SIGNATURE "LHCF"
#ifndef INTERVAL_CHECK_INPUT
#define INTERVAL_CHECK_INPUT 15
@@ -218,10 +221,11 @@
//#define debugSerial M5.Lcd
//#endif
#ifndef debugSerial
#define debugSerial Serial
#ifndef debugSerialPort
#define debugSerialPort Serial
#endif
#ifndef Wiz5500
#define W5100_ETHERNET_SHIELD
#else

View File

@@ -24,6 +24,7 @@ e-mail anklimov@gmail.com
#include <Arduino.h>
#include "utils.h"
#include "options.h"
#include "main.h"
OneWire *oneWire = NULL;

63
lighthub/streamlog.cpp Normal file
View 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
View 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;
};

View File

@@ -22,6 +22,7 @@ e-mail anklimov@gmail.com
#include "options.h"
#include "stdarg.h"
#include <Wire.h>
#include "main.h"
#include "item.h"
#include <PubSubClient.h>

View File

@@ -264,6 +264,11 @@ platform = atmelsam
framework = arduino
board = 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 =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
DHT sensor library for ESPx
@@ -546,6 +551,8 @@ platform = atmelsam
framework = arduino
board = due
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 =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
DHT sensor library for ESPx
@@ -555,7 +562,7 @@ lib_ignore =
WifiManager
DmxSimple
httpClient
Ethernet
Ethernet2
Ethernet3
NRFFlashStorage
WebServer
@@ -573,7 +580,7 @@ lib_deps =
https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster
https://github.com/anklimov/Ethernet2
https://github.com/anklimov/Ethernet
https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git
FastLED@3.3.2