Skip to content
Snippets Groups Projects
Commit 7cd79a3f authored by fxk8y's avatar fxk8y :spider:
Browse files

Finishing and testing SNTP and birth-metrics code

parent a63a460d
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,9 @@
#include <climits>
#include <cinttypes>
// project specific
#include "../SpiderLib/SNTP.hpp"
using namespace qthing;
using json = nlohmann::json;
......@@ -53,6 +56,33 @@ namespace SiliconTorch {
lifeTimeSaved = uptime_ms();
nvs_get_u64(this->nvs, "birth", &this->birth);
lifeTimeSaved = uptime_ms();
if (this->birth > 0) {
ESP_LOGI(TAG, "Found my birth timestamp[ %lld ]", this->birth);
SpiderLib::SNTP::instance().registerTimeSyncHandler([&](){
uint64_t now = (uint64_t)std::time(NULL);
float age = (float)(now - this->birth);
age /= 24.0f * 60.0f * 60.0f;
ESP_LOGI(TAG, "I'm at least days[ %.2f ] old", age);
});
} else {
SpiderLib::SNTP::instance().registerTimeSyncHandler([&](){
this->birth = (uint64_t)std::time(NULL);
esp_err_t err = nvs_set_u64(this->nvs, "birth", this->birth);
if (err == ESP_OK) ESP_LOGI(TAG, "Just carved my birth timestamp[ %lld ] 🎂 into silicon", this->birth);
else ESP_LOGE(TAG, "Couldn't save birth time: error[ %d ]", err);
});
}
char taskName[64];
snprintf(taskName, sizeof(taskName), "Metrics[%i]", nextTask++); // TODO: increment thread-safe!
......
......@@ -56,8 +56,12 @@ namespace SpiderLib {
SNTP::SNTP() {
const char* server = "pool.ntp.org"; // TODO: make configurable!
ESP_LOGI(TAG, "Starting synchronization against server[ %s ]", server);
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org"); // TODO: make configurable!
sntp_setservername(0, server);
sntp_init();
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); // germany
......@@ -91,5 +95,4 @@ namespace SpiderLib {
}
......@@ -12,7 +12,7 @@
// ### LIBS FOR TESTING ###
#include <cstdlib>
#include "SpiderLib/SNTP.hpp"
//#include "SpiderLib/SNTP.hpp"
#include "SiliconTorch/CyanBusCRC.hpp"
#include "SiliconTorch/CyanBusTOUT.hpp"
// ### END LIBS ###
......@@ -25,13 +25,8 @@ CyanLight::CyanLightControl* ctrl;
void device_main() {
SpiderLib::SNTP& ntp = SpiderLib::SNTP::instance();
ntp.registerTimeSyncHandler([](){
ESP_LOGE("EVENT…", "…HANDLER()!");
});
qthing::enable_wifi();
/*qthing::enable_wifi();
cfg.apply();
return;
......@@ -50,16 +45,16 @@ void device_main() {
ESP_LOGW("CheckCRC", "CRC of str[ %s ] is crc[ %s ]", buffer, SiliconTorch::Impl::checkCRC(buffer, L) ? "true" : "false");
return;
return; */
SiliconTorch::CyanBusTOUT::CyanBus cyanBus(13, 14, 12, 15); // Pinout of CyanStripe
/* SiliconTorch::CyanBusTOUT::CyanBus cyanBus(13, 14, 12, 15); // Pinout of CyanStripe
// TODO: ???
cfg.apply();
return;
return; */
ctrl = new CyanLight::CyanLightControl(1);
ctrl->addChannel(26);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment