Timezone / Location
Device can request advanced timezone / location information:
1
Timezone: Europe/Kiev
2
ISO-8601 time: 2020-10-06T10:16:26+03:00
3
Unix time (UTC): 1601968586694
4
TZ offset: 120 minutes
5
DST offset: 60 minutes
6
POSIX TZ rule: EET-2EEST,M3.5.0/3,M10.5.0/4
7
Next offset changes: 120min. on 1603587600, 180min. on 1616893200
8
Location: 41.941692,-88.390674
Copied!
Example:
1
BLYNK_CONNECTED() {
2
// Send requests for different internal data
3
// Request what is actually needed for your use-case
4
Blynk.sendInternal("utc", "tz_name"); // Name of timezone
5
Blynk.sendInternal("utc", "iso"); // ISO-8601 formatted time
6
Blynk.sendInternal("utc", "time"); // Unix timestamp (with msecs)
7
Blynk.sendInternal("utc", "tz"); // Timezone and DST offsets
8
Blynk.sendInternal("utc", "tz_rule"); // POSIX TZ rule
9
Blynk.sendInternal("utc", "dst_next"); // Up to 2 next time offset changes (due to DST)
10
}
11
12
// Receive UTC data
13
BLYNK_WRITE(InternalPinUTC) {
14
String cmd = param[0].asStr();
15
if (cmd == "time") {
16
uint64_t utc_time = param[1].asLongLong();
17
Serial.print("Unix time (UTC): "); Serial.println(utc_time);
18
19
} else if (cmd == "iso") {
20
String iso_time = param[1].asStr();
21
Serial.print("ISO-8601 time: "); Serial.println(iso_time);
22
23
} else if (cmd == "tz") {
24
long tz_offset = param[1].asInt();
25
long dst_offset = param[2].asInt();
26
Serial.print("TZ offset: "); Serial.print(tz_offset); Serial.println(" minutes");
27
Serial.print("DST offset: "); Serial.print(dst_offset); Serial.println(" minutes");
28
29
} else if (cmd == "tz_name") {
30
String tz_name = param[1].asStr();
31
Serial.print("Timezone: "); Serial.println(tz_name);
32
33
} else if (cmd == "tz_rule") {
34
String tz_rule = param[1].asStr();
35
Serial.print("POSIX TZ rule: "); Serial.println(tz_rule);
36
37
} else if (cmd == "dst_next") {
38
uint32_t next1_ts = param[1].asLong();
39
int next1_off = param[2].asInt();
40
41
uint32_t next2_ts = param[3].asLong();
42
int next2_off = param[4].asInt();
43
44
Serial.print("Next offset changes: ");
45
Serial.print(next1_off); Serial.print("min. on "); Serial.print(next1_ts);
46
Serial.print(", ");
47
Serial.print(next2_off); Serial.print("min. on "); Serial.print(next2_ts);
48
Serial.println();
49
}
50
}
Copied!
Last modified 6mo ago
Copy link