-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrtc_test.h
More file actions
76 lines (59 loc) · 1.57 KB
/
Copy pathrtc_test.h
File metadata and controls
76 lines (59 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef RTC_TEST_H
#define RTC_TEST_H
#include <Wire.h>
#include <RTClib.h>
#include <time.h>
#include "config.h"
RTC_DS3231 rtc; // rtc object
void rtc_test()
{
Serial.println("RTC Test Started");
CHECK_ABORT();
bool pass = false;
if (WiFi.status() != WL_CONNECTED)
wifi_test();
Wire.begin(I2C_SDA, I2C_SCL);
ABORTABLE_DELAY(100);
if (!rtc.begin())
{
update_test_result(TEST_RTC, false);
Serial.println("$,RTC,2,FAIL,RTC NOT DETECTED,#");
Serial.println("Try With Appropriate I2C Pins or Check RTC Connection");
return;
}
configTime(GMT_OFFSET_SEC, DAYLIGHT_OFFSET, NTP_SERVER);
struct tm timeinfo;
if (!getLocalTime(&timeinfo))
{
update_test_result(TEST_RTC, false);
Serial.println("$,RTC,2,FAIL,NTP SERVER,#");
return;
}
// Convert NTP → RTC
DateTime ntpTime
(
timeinfo.tm_year + 1900,
timeinfo.tm_mon + 1,
timeinfo.tm_mday,
timeinfo.tm_hour,
timeinfo.tm_min,
timeinfo.tm_sec
);
rtc.adjust(ntpTime);
DateTime t1 = rtc.now();
ABORTABLE_DELAY(5000);
DateTime t2 = rtc.now();
int diff = t2.second() - t1.second();
if (diff < 0) diff += 60;
if (diff >= 5) // respond passs with current time
{
pass = true;
Serial.printf("$,RTC,1,PASS,%02d:%02d:%02d,#\n",t2.hour(), t2.minute(), t2.second());
}
else
Serial.println("$,RTC,2,FAIL,RTC NOT WORKING,#");
update_test_result(TEST_RTC, pass);
CHECK_ABORT();
ABORTABLE_DELAY(100);
}
#endif