I have a project I have been doing to control some of the features of my pool. I have used the Syslog library to send syslog messages over UDP to my rsyslog server.
I am instantiating an PoolLight object and passing in an instance of Syslog. The problem I am seeing is each member function of PoolLight only sends one log message, even with multiple calls.
I haven't a clue what I have done wrong.
poolduino_wemos.ino. N.B. truncated after the object instantiations
#include <Homie.h>
#include <WiFiUdp.h>
#include <Syslog.h>
#define firmwareVersion "2.3.0"
#define LIGHT_RELAY_PIN 5 // D1
#define LIGHT_RELAY_PULSE_INTERVAL 250
#define FLOAT_SENSOR_PIN 4 // D2
#define FLOAT_LOW_LED 14 // D5
#define THERMISTOR_PIN A0
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udpClient;
// Private Libraries
#include <PoolLight.h>
// Syslog server connection info
#define SYSLOG_SERVER "mediastore"
#define SYSLOG_PORT 514
// This device info
#define DEVICE_HOSTNAME "poolduino"
#define DEFAULT_APP_NAME "PoolMain"
Syslog logger(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, DEFAULT_APP_NAME, LOG_LOCAL0);
PoolLight poolLight(LIGHT_RELAY_PIN, LIGHT_RELAY_PULSE_INTERVAL, logger);
...
PoolLight.h
#ifndef PoolLight_h
#define PoolLight_h
#include <Syslog.h>
class PoolLight
{
public:
String current_color;
PoolLight(int pin, int interval, Syslog const &logger);
void set_light_color(String color);
void set_light_state(bool state);
bool get_light_state();
void loop();
private:
Syslog _logger;
bool _light_state;
void _log();
void _logf();
int _pin;
int _pulse_count;
int _interval;
long _PreviousMillis = 0;
int _color_pulses(String color);
bool _active_color_change();
void _pulse_light();
};
#endif
PoolLight.cpp
#include <Arduino.h>
#include <PoolLight.h>
#include <Syslog.h>
#define APP_NAME "PoolLight"
PoolLight::PoolLight(int pin, int interval, Syslog const &logger) : _logger(logger) {
current_color = "Blue";
_pin = pin;
_interval = interval;
_pulse_count = 0;
_logger.appName(APP_NAME);
_logger.log(LOG_DEBUG, "Setting up light relay");
pinMode(pin, OUTPUT);
set_light_state(false);
}
void PoolLight::set_light_state(bool state) {
if (state) {
if (!_active_color_change()) {
_logger.log(LOG_DEBUG, "Switching the light ON, and pin to High");
}
_light_state = true;
} else {
if (!_active_color_change()) {
_logger.log(LOG_DEBUG, "Switching the light OFF, and pin to Low");
}
_light_state = false;
}
digitalWrite(_pin, _light_state);
}
int PoolLight::_color_pulses(String color) {
_logger.logf(LOG_INFO, "Setting color to .%s.", color.c_str());
_logger.log(LOG_INFO, "This line never gets sent");
Serial.print("Setting color to ");
Serial.println(color.c_str());
if (color == "Blue") {
_logger.log(LOG_DEBUG, "Color Blue returns 8");
return 8;
} else if (color == "Green"){
_logger.log(LOG_DEBUG, "Color Green returns 9");
return 9;
} else if (color == "Red"){
_logger.log(LOG_DEBUG, "Color Red returns 10");
return 10;
} else if (color == "White"){
_logger.log(LOG_DEBUG, "Color White returns 11");
return 11;
} else if (color == "Magenta"){
_logger.log(LOG_DEBUG, "Color White returns 12");
return 12;
}
_logger.logf(LOG_DEBUG, "Nothing matched [%s]. Returning 0", color.c_str());
Serial.println(color);
return 0;
}
in the call to color_pulses
only the first log line gets sent. And the logging call in the constructor does not send anything to the syslog server.