Last active
September 14, 2017 16:23
-
-
Save hocarm/270293c1420d67049f3c69d5c02e8afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This sketch shows an example of sending a reading to data.sparkfun.com once per day. | |
It uses the Sparkfun testing stream so the only customizing required is the WiFi SSID and password. | |
The Harringay Maker Space | |
License: Apache License v2 | |
*/ | |
#include <NTPtimeESP.h> | |
NTPtime NTPch("ch.pool.ntp.org"); // Server NTP | |
char *ssid = "ten_wifi"; // Ten WiFi SSID | |
char *password = "password"; // Mat khau wifi | |
/* | |
* Cac truong co trong struct DateTime: | |
* struct strDateTime | |
{ | |
byte hour; | |
byte minute; | |
byte second; | |
int year; | |
byte month; | |
byte day; | |
byte dayofWeek; | |
boolean valid; | |
}; | |
*/ | |
strDateTime dateTime; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println(); | |
Serial.println("Booted"); | |
Serial.println("Connecting to Wi-Fi"); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin (ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println("WiFi connected"); | |
} | |
void loop() { | |
// Tham so dau tien la Time zone duoi dang floating point (7.0 la VN); | |
// Tham so thu hai la DayLightSaving: 1 voi thoi gian; 2 la thoi gian US (o VN khong su dung) | |
dateTime = NTPch.getNTPtime(7.0, 0); | |
// Kiem tra dateTime.valid truoc khi dua ra gia tri thoi gian | |
if(dateTime.valid){ | |
NTPch.printDateTime(dateTime); | |
byte actualHour = dateTime.hour; // Gio | |
byte actualMinute = dateTime.minute; // Phut | |
byte actualsecond = dateTime.second; // Giay | |
int actualyear = dateTime.year; // Nam | |
byte actualMonth = dateTime.month; // Thang | |
byte actualday =dateTime.day; // Ngay | |
byte actualdayofWeek = dateTime.dayofWeek; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment