Compare commits
9 Commits
abe0cb0839
...
DEPLOYED
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a1e944ea2 | ||
|
|
a1a66ebf8e | ||
|
|
b19ed89158 | ||
|
|
25251785fa | ||
| 0e842294be | |||
| 57957740d9 | |||
|
|
25aa2d6cb6 | ||
|
|
eaa643bf3c | ||
| fa1b288f4d |
BIN
docs/ESP32_clock_adjust.xlsx
Normal file
BIN
docs/ESP32_clock_adjust.xlsx
Normal file
Binary file not shown.
@@ -56,7 +56,7 @@ public:
|
|||||||
file.close(); // close config file before unmounting filesystem
|
file.close(); // close config file before unmounting filesystem
|
||||||
};
|
};
|
||||||
|
|
||||||
ArduinoJson::JsonDocument& getConfig()
|
ArduinoJson::JsonDocument &getConfig()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
serialize();
|
serialize();
|
||||||
@@ -152,6 +152,7 @@ private:
|
|||||||
ntp["timezone"] = m_ntpTimezone;
|
ntp["timezone"] = m_ntpTimezone;
|
||||||
ntp["updateInterval"] = m_ntpUpdateInterval;
|
ntp["updateInterval"] = m_ntpUpdateInterval;
|
||||||
ntp["retries"] = m_ntpRetries;
|
ntp["retries"] = m_ntpRetries;
|
||||||
|
ntp["ntpRtcOffsetRegister"] = m_ntpRtcOffsetRegister;
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -220,9 +221,10 @@ private:
|
|||||||
{
|
{
|
||||||
auto ntp = m_configJson["ntp"];
|
auto ntp = m_configJson["ntp"];
|
||||||
m_ntpPool = ntp["pool"].as<std::string>();
|
m_ntpPool = ntp["pool"].as<std::string>();
|
||||||
m_ntpTimezone = ntp["timezone"].as<uint16_t>();
|
m_ntpTimezone = ntp["timezone"].as<int8_t>();
|
||||||
m_ntpUpdateInterval = ntp["updateInterval"].as<uint16_t>();
|
m_ntpUpdateInterval = ntp["updateInterval"].as<uint16_t>();
|
||||||
m_ntpRetries = ntp["retries"].as<uint8_t>();
|
m_ntpRetries = ntp["retries"].as<uint8_t>();
|
||||||
|
m_ntpRtcOffsetRegister = ntp["ntpRtcOffsetRegister"].as<uint8_t>();
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -272,9 +274,10 @@ public:
|
|||||||
|
|
||||||
// NTP
|
// NTP
|
||||||
std::string m_ntpPool = "pool.ntp.org";
|
std::string m_ntpPool = "pool.ntp.org";
|
||||||
uint16_t m_ntpTimezone = 3600; // GTM +1
|
int8_t m_ntpTimezone = +1; // GMT +1
|
||||||
uint16_t m_ntpUpdateInterval = 3600; // every hour
|
uint16_t m_ntpUpdateInterval = 3600; // every hour
|
||||||
uint8_t m_ntpRetries = 5;
|
uint8_t m_ntpRetries = 5;
|
||||||
|
uint8_t m_ntpRtcOffsetRegister = 0xE7; // -25 pulses in fast mode
|
||||||
|
|
||||||
// MQTT
|
// MQTT
|
||||||
std::string m_mqttHost = "10.0.2.249";
|
std::string m_mqttHost = "10.0.2.249";
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
namespace drivers
|
namespace drivers
|
||||||
{
|
{
|
||||||
|
|
||||||
Ethernet::Ethernet(const std::string hostname) : m_hostname(hostname), m_connected(false), m_localIP(IPAddress()), m_udp(NetworkUDP()), m_timeClient(m_udp)
|
Ethernet::Ethernet(const std::string &hostname, const std::string &ntpPool, const int8_t tz, const uint16_t updateInterval) : m_hostname(hostname), m_ntpPool(ntpPool), m_connected(false), m_localIP(IPAddress()), m_udp(NetworkUDP()), m_timeClient(m_udp)
|
||||||
{
|
{
|
||||||
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
|
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
|
||||||
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
|
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
|
||||||
|
|
||||||
m_timeClient = std::move(NTPClient(m_udp, "pool.ntp.org", 0, 3600)); // NTP server, time offset in seconds, update interval
|
m_timeClient = std::move(NTPClient(m_udp, m_ntpPool.c_str(), tz * 3600, updateInterval)); // NTP server, time offset in seconds, update interval
|
||||||
m_timeClient.begin();
|
m_timeClient.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +30,17 @@ namespace drivers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Ethernet::setNtpTimeOffset(const int8_t tz)
|
||||||
|
{
|
||||||
|
if (m_connected)
|
||||||
|
{
|
||||||
|
m_timeClient.setTimeOffset(tz * 3600);
|
||||||
|
LOG_DEBUG("Time zone UTC ", tz);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const bool Ethernet::isConnected()
|
const bool Ethernet::isConnected()
|
||||||
{
|
{
|
||||||
return m_connected;
|
return m_connected;
|
||||||
|
|||||||
@@ -30,15 +30,17 @@ namespace drivers
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Ethernet(const std::string hostname);
|
Ethernet(const std::string &hostname, const std::string &ntpPool, const int8_t tz, const uint16_t updateInterval);
|
||||||
~Ethernet();
|
~Ethernet();
|
||||||
|
|
||||||
void onEvent(arduino_event_id_t event, arduino_event_info_t info);
|
void onEvent(arduino_event_id_t event, arduino_event_info_t info);
|
||||||
const bool isConnected();
|
const bool isConnected();
|
||||||
const bool getNtpTime(time_t &time);
|
const bool getNtpTime(time_t &time);
|
||||||
|
const bool setNtpTimeOffset(const int8_t tz);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string m_hostname;
|
const std::string m_hostname;
|
||||||
|
const std::string m_ntpPool;
|
||||||
bool m_connected;
|
bool m_connected;
|
||||||
NetworkUDP m_udp;
|
NetworkUDP m_udp;
|
||||||
IPAddress m_localIP;
|
IPAddress m_localIP;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace drivers
|
|||||||
{
|
{
|
||||||
LOG_INFO("Inizializing RGB Led");
|
LOG_INFO("Inizializing RGB Led");
|
||||||
pinMode(c_ledPin, OUTPUT);
|
pinMode(c_ledPin, OUTPUT);
|
||||||
m_lp.pin = c_ledPin;
|
m_blinkTask = NULL;
|
||||||
m_lp.blinkTask = NULL;
|
m_flashTimer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Led::~Led()
|
Led::~Led()
|
||||||
@@ -22,54 +22,89 @@ namespace drivers
|
|||||||
|
|
||||||
void Led::setColor(const color_t color)
|
void Led::setColor(const color_t color)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_ledMutex);
|
||||||
blinkStop();
|
blinkStop();
|
||||||
|
m_colorDefault = color;
|
||||||
rgbLedWrite(c_ledPin, color.g, color.r, color.b);
|
rgbLedWrite(c_ledPin, color.g, color.r, color.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Led::flashHandle(TimerHandle_t th)
|
||||||
|
{
|
||||||
|
Led *led = (Led *)pvTimerGetTimerID(th);
|
||||||
|
rgbLedWrite(led->c_ledPin, led->m_colorDefault.g, led->m_colorDefault.r, led->m_colorDefault.b); // reset color to saved color
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Led::flashColor(const uint16_t tOn, const color_t color)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_ledMutex);
|
||||||
|
rgbLedWrite(c_ledPin, color.g, color.r, color.b); // set color to flash
|
||||||
|
if (m_flashTimer == NULL)
|
||||||
|
{
|
||||||
|
m_flashTimer = xTimerCreate("flasher", pdMS_TO_TICKS(tOn), pdFALSE, NULL, flashHandle);
|
||||||
|
xTimerStart(m_flashTimer, 0);
|
||||||
|
LOG_INFO("Led Flash timer created");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xTimerStop(m_flashTimer, 0);
|
||||||
|
if (!xTimerChangePeriod(m_flashTimer, pdMS_TO_TICKS(tOn), pdMS_TO_TICKS(1)) || !xTimerReset(m_flashTimer, pdMS_TO_TICKS(1)))
|
||||||
|
{
|
||||||
|
LOG_ERROR("Led Flash timer failed reset");
|
||||||
|
xTimerDelete(m_flashTimer, 0);
|
||||||
|
m_flashTimer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Led::blinkColor(const uint16_t tOn, const uint16_t tOff, const color_t color)
|
void Led::blinkColor(const uint16_t tOn, const uint16_t tOff, const color_t color)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_ledMutex);
|
||||||
blinkStop();
|
blinkStop();
|
||||||
m_lp.color1 = color;
|
m_color1 = color;
|
||||||
m_lp.color2 = {0, 0, 0};
|
m_color2 = {0, 0, 0};
|
||||||
m_lp.tOn = tOn;
|
m_tOn = tOn;
|
||||||
m_lp.tOff = tOff;
|
m_tOff = tOff;
|
||||||
xTaskCreate(blinkTask, "blinker", TASK_STACK, static_cast<void *>(&m_lp), TASK_PRIORITY, &m_lp.blinkTask);
|
xTaskCreate(blinkTask, "blinker", TASK_STACK, this, TASK_PRIORITY, &m_blinkTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Led::blinkAlternate(const uint16_t tOn, const uint16_t tOff, const color_t color1, const color_t color2)
|
void Led::blinkAlternate(const uint16_t tOn, const uint16_t tOff, const color_t color1, const color_t color2)
|
||||||
{
|
{
|
||||||
{
|
std::lock_guard<std::mutex> lock(m_ledMutex);
|
||||||
blinkStop();
|
blinkStop();
|
||||||
m_lp.color1 = color1;
|
m_color1 = color1;
|
||||||
m_lp.color2 = color2;
|
m_color2 = color2;
|
||||||
m_lp.tOn = tOn;
|
m_tOn = tOn;
|
||||||
m_lp.tOff = tOff;
|
m_tOff = tOff;
|
||||||
xTaskCreate(blinkTask, "blinker", TASK_STACK, static_cast<void *>(&m_lp), TASK_PRIORITY, &m_lp.blinkTask);
|
xTaskCreate(blinkTask, "blinker", TASK_STACK, this, TASK_PRIORITY, &m_blinkTask);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Led::blinkStop()
|
void Led::blinkStop()
|
||||||
{
|
{
|
||||||
if (m_lp.blinkTask != NULL)
|
if (m_blinkTask != NULL)
|
||||||
vTaskDelete(m_lp.blinkTask);
|
vTaskDelete(m_blinkTask);
|
||||||
m_lp.blinkTask = NULL;
|
m_blinkTask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Led::blinkTask(void *params)
|
void Led::blinkTask(void *params)
|
||||||
{
|
{
|
||||||
|
Led *led = static_cast<Led *>(params);
|
||||||
LOG_DEBUG("Blinker Task Created");
|
LOG_DEBUG("Blinker Task Created");
|
||||||
led_params_t *lPar = static_cast<led_params_t *>(params);
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
rgbLedWrite(lPar->pin, lPar->color1.g, lPar->color1.r, lPar->color1.b);
|
{
|
||||||
delay(lPar->tOn);
|
std::lock_guard<std::mutex> lock(led->m_ledMutex);
|
||||||
rgbLedWrite(lPar->pin, lPar->color2.g, lPar->color2.r, lPar->color2.b); // off
|
rgbLedWrite(led->c_ledPin, led->m_color1.g, led->m_color1.r, led->m_color1.b);
|
||||||
if (lPar->tOff == 0)
|
}
|
||||||
|
delay(led->m_tOn);
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(led->m_ledMutex);
|
||||||
|
rgbLedWrite(led->c_ledPin, led->m_color2.g, led->m_color2.r, led->m_color2.b); // off
|
||||||
|
}
|
||||||
|
if (led->m_tOff == 0)
|
||||||
break;
|
break;
|
||||||
delay(lPar->tOff);
|
delay(led->m_tOff);
|
||||||
}
|
}
|
||||||
LOG_DEBUG("Blinker Task Ended");
|
LOG_DEBUG("Blinker Task Ended");
|
||||||
lPar->blinkTask = NULL;
|
led->m_blinkTask = NULL;
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,21 +5,22 @@
|
|||||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
|
||||||
#include <DebugLog.h>
|
#include <DebugLog.h>
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace drivers
|
namespace drivers
|
||||||
{
|
{
|
||||||
|
|
||||||
class Led
|
class Led
|
||||||
{
|
{
|
||||||
const uint8_t c_ledPin = 38;
|
|
||||||
|
public:
|
||||||
public:
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t g;
|
uint8_t g;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
} color_t;
|
} color_t;
|
||||||
|
|
||||||
const color_t COLOR_RED = {255, 0, 0};
|
const color_t COLOR_RED = {255, 0, 0};
|
||||||
const color_t COLOR_ORANGE = {255, 127, 0};
|
const color_t COLOR_ORANGE = {255, 127, 0};
|
||||||
const color_t COLOR_YELLOW = {255, 255, 0};
|
const color_t COLOR_YELLOW = {255, 255, 0};
|
||||||
@@ -30,32 +31,37 @@ namespace drivers
|
|||||||
const color_t COLOR_BLUE = {0, 0, 255};
|
const color_t COLOR_BLUE = {0, 0, 255};
|
||||||
const color_t COLOR_VIOLET = {127, 0, 255};
|
const color_t COLOR_VIOLET = {127, 0, 255};
|
||||||
const color_t COLOR_MAGENTA = {255, 0, 255};
|
const color_t COLOR_MAGENTA = {255, 0, 255};
|
||||||
|
|
||||||
private:
|
public:
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
color_t color1;
|
|
||||||
color_t color2;
|
|
||||||
uint8_t pin;
|
|
||||||
uint16_t tOn;
|
|
||||||
uint16_t tOff;
|
|
||||||
TaskHandle_t blinkTask;
|
|
||||||
} led_params_t;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Led();
|
Led();
|
||||||
~Led();
|
~Led();
|
||||||
|
|
||||||
void setColor(const color_t color);
|
void setColor(const color_t color);
|
||||||
|
void flashColor(const uint16_t tOn, const color_t color);
|
||||||
void blinkColor(const uint16_t tOn, const uint16_t tOff, const color_t color);
|
void blinkColor(const uint16_t tOn, const uint16_t tOff, const color_t color);
|
||||||
void blinkAlternate(const uint16_t tOn, const uint16_t tOff, const color_t color1, const color_t color2);
|
void blinkAlternate(const uint16_t tOn, const uint16_t tOff, const color_t color1, const color_t color2);
|
||||||
void blinkStop();
|
void blinkStop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void flashHandle(TimerHandle_t th);
|
||||||
static void blinkTask(void *params);
|
static void blinkTask(void *params);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const uint8_t c_ledPin = 38;
|
||||||
|
|
||||||
|
color_t m_color1;
|
||||||
|
color_t m_color2;
|
||||||
|
color_t m_colorDefault;
|
||||||
|
|
||||||
private:
|
uint16_t m_tOn;
|
||||||
led_params_t m_lp;
|
uint16_t m_tOff;
|
||||||
|
|
||||||
|
TaskHandle_t m_blinkTask;
|
||||||
|
TimerHandle_t m_flashTimer;
|
||||||
|
|
||||||
|
bool m_flashing;
|
||||||
|
|
||||||
|
std::mutex m_ledMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "PCF85063_Driver.h"
|
#include "PCF85063_Driver.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
namespace drivers
|
namespace drivers
|
||||||
{
|
{
|
||||||
@@ -157,6 +158,23 @@ namespace drivers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool PCF85063::setOffset(const uint8_t ofst)
|
||||||
|
{
|
||||||
|
LOG_DEBUG("RTC set offset [", printHex(ofst).c_str(), "]");
|
||||||
|
return m_i2c.write(m_address, RTC_OFFSET_ADDR, {ofst});
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t PCF85063::getOffset()
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> buf;
|
||||||
|
if (m_i2c.read(m_address, RTC_OFFSET_ADDR, 1, buf))
|
||||||
|
{
|
||||||
|
LOG_DEBUG("RTC get offset [", printHex(buf.front()).c_str(), "]");
|
||||||
|
return buf.front();
|
||||||
|
}
|
||||||
|
return UINT8_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string PCF85063::getTimeStr()
|
const std::string PCF85063::getTimeStr()
|
||||||
{
|
{
|
||||||
datetime_t dt;
|
datetime_t dt;
|
||||||
@@ -182,16 +200,17 @@ namespace drivers
|
|||||||
{
|
{
|
||||||
tm dtime = datetime2tm(datetime);
|
tm dtime = datetime2tm(datetime);
|
||||||
const std::string buf(std::asctime(&dtime));
|
const std::string buf(std::asctime(&dtime));
|
||||||
return buf.substr(0, std::min(buf.find('\n'),buf.find('\r')));
|
return buf.substr(0, std::min(buf.find('\n'), buf.find('\r')));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string PCF85063::tm2str(const std::tm &datetime)
|
const std::string PCF85063::tm2str(const std::tm &datetime)
|
||||||
{
|
{
|
||||||
const std::string buf(std::asctime(&datetime));
|
const std::string buf(std::asctime(&datetime));
|
||||||
return buf.substr(0, std::min(buf.find('\n'),buf.find('\r')));
|
return buf.substr(0, std::min(buf.find('\n'), buf.find('\r')));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::tm PCF85063::datetime2tm(const datetime_t& datetime) {
|
const std::tm PCF85063::datetime2tm(const datetime_t &datetime)
|
||||||
|
{
|
||||||
tm dtime;
|
tm dtime;
|
||||||
dtime.tm_sec = datetime.second;
|
dtime.tm_sec = datetime.second;
|
||||||
dtime.tm_min = datetime.minute;
|
dtime.tm_min = datetime.minute;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace drivers
|
|||||||
} datetime_t;
|
} datetime_t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PCF85063(I2C &i2c, const uint8_t address, const uint8_t ctrl1 = RTC_CTRL_1_DEFAULT, const uint8_t ctrl2 = RTC_CTRL_2_DEFAULT);
|
PCF85063(I2C &i2c, const uint8_t address = PCF85063_ADDRESS, const uint8_t ctrl1 = RTC_CTRL_1_DEFAULT, const uint8_t ctrl2 = RTC_CTRL_2_DEFAULT);
|
||||||
|
|
||||||
const bool reset(void);
|
const bool reset(void);
|
||||||
|
|
||||||
@@ -100,6 +100,9 @@ namespace drivers
|
|||||||
const bool readAlarm(datetime_t &time);
|
const bool readAlarm(datetime_t &time);
|
||||||
const bool getAlarmFlag(uint8_t &flags);
|
const bool getAlarmFlag(uint8_t &flags);
|
||||||
|
|
||||||
|
const bool setOffset(const uint8_t ofst);
|
||||||
|
const uint8_t getOffset();
|
||||||
|
|
||||||
const std::string getTimeStr();
|
const std::string getTimeStr();
|
||||||
|
|
||||||
static const std::string datetime2str(const datetime_t &datetime);
|
static const std::string datetime2str(const datetime_t &datetime);
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ namespace commands
|
|||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ArduinoJson::JsonDocument Commands::setBuzz(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||||
|
{
|
||||||
|
ArduinoJson::JsonDocument response;
|
||||||
|
dev.buzzer.beep(500, NOTE_Bb);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
// CONFIG //
|
// CONFIG //
|
||||||
// CONFIG //
|
// CONFIG //
|
||||||
const ArduinoJson::JsonDocument Commands::setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
const ArduinoJson::JsonDocument Commands::setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||||
@@ -74,13 +81,13 @@ namespace commands
|
|||||||
const auto &eventName = params["name"].as<std::string>();
|
const auto &eventName = params["name"].as<std::string>();
|
||||||
const auto &timeStr = params["cronExpr"].as<std::string>();
|
const auto &timeStr = params["cronExpr"].as<std::string>();
|
||||||
const auto &actionStr = params["action"].as<std::string>();
|
const auto &actionStr = params["action"].as<std::string>();
|
||||||
response["value"]["name"] = eventName;
|
response["values"]["name"] = eventName;
|
||||||
|
|
||||||
ArduinoJson::JsonDocument action;
|
ArduinoJson::JsonDocument action;
|
||||||
if (ArduinoJson::deserializeJson(action, actionStr) != ArduinoJson::DeserializationError::Ok)
|
if (ArduinoJson::deserializeJson(action, actionStr) != ArduinoJson::DeserializationError::Ok)
|
||||||
{
|
{
|
||||||
LOG_ERROR("setCronJob unable to deserialize cron job [", actionStr.c_str(), "]");
|
LOG_ERROR("setCronJob unable to deserialize cron job [", actionStr.c_str(), "]");
|
||||||
response["value"]["status"] = "invalid";
|
response["values"]["status"] = "invalid";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,11 +95,11 @@ namespace commands
|
|||||||
if (!cron.addEvent(eventName, timeStr, action))
|
if (!cron.addEvent(eventName, timeStr, action))
|
||||||
{
|
{
|
||||||
LOG_ERROR("setCronJob unable to add job [", actionStr.c_str(), "]");
|
LOG_ERROR("setCronJob unable to add job [", actionStr.c_str(), "]");
|
||||||
response["value"]["status"] = "invalid";
|
response["values"]["status"] = "invalid";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
LOG_INFO("setCronJob added job [", actionStr.c_str(), "]");
|
LOG_INFO("setCronJob added job [", actionStr.c_str(), "]");
|
||||||
response["value"]["status"] = "valid";
|
response["values"]["status"] = "valid";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
const ArduinoJson::JsonDocument Commands::getCronJob(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
const ArduinoJson::JsonDocument Commands::getCronJob(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms)
|
||||||
@@ -101,7 +108,6 @@ namespace commands
|
|||||||
response["cmd"] = "getCronJob";
|
response["cmd"] = "getCronJob";
|
||||||
auto &cron = Cron::getInstance(dev);
|
auto &cron = Cron::getInstance(dev);
|
||||||
auto eventName = params["name"].as<std::string>();
|
auto eventName = params["name"].as<std::string>();
|
||||||
response["values"]["name"] = eventName;
|
|
||||||
|
|
||||||
if (eventName.empty())
|
if (eventName.empty())
|
||||||
{
|
{
|
||||||
@@ -125,6 +131,7 @@ namespace commands
|
|||||||
}
|
}
|
||||||
|
|
||||||
Cron::CronEvent event;
|
Cron::CronEvent event;
|
||||||
|
response["values"]["name"] = eventName;
|
||||||
if (!cron.getEvent(eventName, event))
|
if (!cron.getEvent(eventName, event))
|
||||||
{
|
{
|
||||||
LOG_ERROR("getCronJob failed to get job [", eventName.c_str(), "]");
|
LOG_ERROR("getCronJob failed to get job [", eventName.c_str(), "]");
|
||||||
@@ -488,7 +495,7 @@ namespace commands
|
|||||||
response["values"]["drift"] = (uint32_t)timeDiff.count();
|
response["values"]["drift"] = (uint32_t)timeDiff.count();
|
||||||
response["values"]["direction"] = "RTC is [" + std::string(direction) + "] NTP time";
|
response["values"]["direction"] = "RTC is [" + std::string(direction) + "] NTP time";
|
||||||
|
|
||||||
LOG_INFO("getTimeDrift -> RTC is [", (uint32_t)timeDiff.count(), "] sec, [", std::string(direction).c_str(), "] NTP time");
|
LOG_INFO("getTimeDrift -> RTC is [", (int32_t)timeDiff.count(), "] sec, [", std::string(direction).c_str(), "] NTP time");
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ namespace commands
|
|||||||
Commands() = delete;
|
Commands() = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// TEST //
|
||||||
|
static const ArduinoJson::JsonDocument setBuzz(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms);
|
||||||
|
|
||||||
// CONFIG //
|
// CONFIG //
|
||||||
static const ArduinoJson::JsonDocument setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms);
|
static const ArduinoJson::JsonDocument setConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms);
|
||||||
static const ArduinoJson::JsonDocument getConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms);
|
static const ArduinoJson::JsonDocument getConfig(const devices_t &dev, const ArduinoJson::JsonDocument ¶ms);
|
||||||
@@ -94,6 +97,9 @@ namespace commands
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const std::map<const std::string, Command> s_commandMap = {
|
static const std::map<const std::string, Command> s_commandMap = {
|
||||||
|
|
||||||
|
{"setBuzz", Commands::setBuzz},
|
||||||
|
|
||||||
{"setConfig", Commands::setConfig},
|
{"setConfig", Commands::setConfig},
|
||||||
{"getConfig", Commands::getConfig},
|
{"getConfig", Commands::getConfig},
|
||||||
|
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -34,14 +34,17 @@ void loop()
|
|||||||
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
|
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
|
||||||
auto i2c = drivers::I2C();
|
auto i2c = drivers::I2C();
|
||||||
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
|
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
|
||||||
auto rtc = drivers::PCF85063(i2c, PCF85063_ADDRESS);
|
auto rtc = drivers::PCF85063(i2c);
|
||||||
auto eth = drivers::Ethernet(conf.m_ethHostname);
|
auto eth = drivers::Ethernet(conf.m_ethHostname, conf.m_ntpPool, conf.m_ntpTimezone, conf.m_ntpUpdateInterval);
|
||||||
auto tmp = drivers::R4DCB08(bus, conf.m_modbusTemperatureAddr);
|
auto tmp = drivers::R4DCB08(bus, conf.m_modbusTemperatureAddr);
|
||||||
auto seneca = drivers::S50140(bus, conf.m_modbusSenecaAddr);
|
auto seneca = drivers::S50140(bus, conf.m_modbusSenecaAddr);
|
||||||
auto buzzer = drivers::Buzzer();
|
auto buzzer = drivers::Buzzer();
|
||||||
auto led = drivers::Led();
|
auto led = drivers::Led();
|
||||||
delay(500);
|
delay(500);
|
||||||
auto io = digitalIO(i2c, bus, {conf.m_modbusRelayAddr});
|
auto io = digitalIO(i2c, bus, {conf.m_modbusRelayAddr});
|
||||||
|
// get RTC time drift offset value
|
||||||
|
rtc.setOffset(conf.m_ntpRtcOffsetRegister);
|
||||||
|
LOG_INFO("RTC offset register -> ", printHex(rtc.getOffset()).c_str());
|
||||||
// Initialize temperature sensors
|
// Initialize temperature sensors
|
||||||
sensors = tmp.getNum();
|
sensors = tmp.getNum();
|
||||||
tmp.setCorrection(conf.m_tempCorrectionValues);
|
tmp.setCorrection(conf.m_tempCorrectionValues);
|
||||||
@@ -83,12 +86,14 @@ void loop()
|
|||||||
|
|
||||||
MQTTwrapper::MessageCallback onMessage = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
MQTTwrapper::MessageCallback onMessage = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
||||||
{
|
{
|
||||||
// devices.led.flashColor(250, devices.led.COLOR_BLUE);
|
LOG_DEBUG("onMessage callback [", topic.c_str(), "]");
|
||||||
|
devices.led.setColor(devices.led.COLOR_MAGENTA);
|
||||||
};
|
};
|
||||||
|
|
||||||
MQTTwrapper::MessageCallback onPublish = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
MQTTwrapper::MessageCallback onPublish = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
||||||
{
|
{
|
||||||
// devices.led.flashColor(250, devices.led.COLOR_ORANGE);
|
LOG_DEBUG("onPublish callback [", topic.c_str(), "]");
|
||||||
|
devices.led.setColor(devices.led.COLOR_SKYBLUE);
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////// CRONJOB //////////////
|
///////////// CRONJOB //////////////
|
||||||
@@ -124,6 +129,8 @@ void loop()
|
|||||||
uint8_t mqttRetries(0);
|
uint8_t mqttRetries(0);
|
||||||
while (timeRetries++ < conf.m_ntpRetries)
|
while (timeRetries++ < conf.m_ntpRetries)
|
||||||
{
|
{
|
||||||
|
eth.setNtpTimeOffset(conf.m_ntpTimezone);
|
||||||
|
LOG_INFO("NTP Timezone UTC", conf.m_ntpTimezone >= 0 ? "+" : "", conf.m_ntpTimezone);
|
||||||
if (eth.getNtpTime(ntpTime))
|
if (eth.getNtpTime(ntpTime))
|
||||||
{ // skip NTP update for drift testing
|
{ // skip NTP update for drift testing
|
||||||
buzzer.beep(250, NOTE_A);
|
buzzer.beep(250, NOTE_A);
|
||||||
|
|||||||
Reference in New Issue
Block a user