Browse Source

Get time from Redis, set it to RTC

m5stack
Ryan Joseph 1 year ago
parent
commit
2537979bdf
4 changed files with 27 additions and 7 deletions
  1. +17
    -6
      zero_watch.ino
  2. +1
    -1
      zw_common.h
  3. +7
    -0
      zw_redis.cpp
  4. +2
    -0
      zw_redis.h

+ 17
- 6
zero_watch.ino View File

@@ -262,6 +262,21 @@ void redis_publish_logs_emit(const char *fmt, ...)
free(jbuf);
}

void readAndSetTime()
{
RTC_TimeTypeDef ts;
bzero(&ts, sizeof(ts));
gRedis->getTime(&ts.Hours, &ts.Minutes, &ts.Seconds);
if (!(!ts.Hours && !ts.Minutes && !ts.Seconds)) {
M5.Rtc.SetTime(&ts);
zlog("Set time (from Redis) to %02d:%02d:%02d\n",
ts.Hours, ts.Minutes, ts.Seconds);
}
else {
zlog("Failed to get time from Redis (or it is exactly midnight!)\n");
}
}

void readConfigAndUserKeys()
{
auto curCfg = gRedis->readConfig();
@@ -457,12 +472,6 @@ void setup()
M5.begin();
pinMode(M5_BUTTON_HOME, INPUT_PULLUP);
zlog("Built for M5StickC\n");
/*
RTC_TimeTypeDef TimeStruct;
TimeStruct.Hours = 22;
TimeStruct.Minutes = 40;
TimeStruct.Seconds = 00;
M5.Rtc.SetTime(&TimeStruct);*/
#else
pinMode(LED_BLTIN, OUTPUT);
Serial.begin(SER_BAUD);
@@ -537,6 +546,8 @@ void setup()

zlog("Redis connection established, reading config...\n");

readAndSetTime();

readConfigAndUserKeys();

zlog("Fully initialized! (debug %sabled)\n", gConfig.debug ? "en" : "dis");


+ 1
- 1
zw_common.h View File

@@ -1,7 +1,7 @@
#ifndef __ZW_COMMON__H__
#define __ZW_COMMON__H__

#define ZEROWATCH_VER "0.2.5.0"
#define ZEROWATCH_VER "0.2.5.1"
#define DEBUG 1
#define M5STACKC 1



+ 7
- 0
zw_redis.cpp View File

@@ -225,6 +225,13 @@ void ZWRedis::logCritical(const char* format, ...)
connection.redis->hset(REDIS_KEY(":criticalLog"), String(++__keyCount).c_str(), _buf);
}

void ZWRedis::getTime(uint8_t* hour, uint8_t* minute, uint8_t* second)
{
if (hour) *hour = (uint8_t)connection.redis->hget("rpjios.__meta.time", "hour").toInt();
if (minute) *minute = (uint8_t)connection.redis->hget("rpjios.__meta.time", "minute").toInt();
if (second) *second = (uint8_t)connection.redis->hget("rpjios.__meta.time", "second").toInt();
}

void ZWRedisResponder::setValue(const char *format, ...)
{
#define BUFLEN 2048


+ 2
- 0
zw_redis.h View File

@@ -99,6 +99,8 @@ public:

void logCritical(const char* fmt, ...);

void getTime(uint8_t* hour, uint8_t* minute, uint8_t* second);

private:
ZWAppConfig _lastReadConfig;
};


Loading…
Cancel
Save