Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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>
- //#include <Wire.h>
- //#include <Adafruit_GFX.h>
- //#include <Adafruit_SSD1306.h>
- //
- //#define OLED_RESET 4
- //Adafruit_SSD1306 display(OLED_RESET);
- //#define DEBUG_ON
- NTPtime NTPch("0.pool.ntp.org"); // Choose server pool as required
- char *ssid = "Bankausku"; // Set you WiFi SSID
- char *password = "VapeNation"; // Set you WiFi password
- /*
- * The structure contains following fields:
- * struct strDateTime
- {
- byte hour;
- byte minute;
- byte second;
- int year;
- byte month;
- byte day;
- byte dayofWeek;
- boolean valid;
- };
- */
- strDateTime dateTime;
- strDateTime alarmTime;
- 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");
- pinMode(23, OUTPUT);
- digitalWrite(23, LOW);
- }
- bool alarmSet = false;
- void loop() {
- // first parameter: Time zone in floating point (for India);
- // second parameter: 1 for European summer time; 2 for US daylight saving time (contributed by viewwer, not tested by me)
- // check dateTime.valid before using the returned time
- // Use "setSendInterval" or "setRecvTimeout" if required
- dateTime = NTPch.getNTPtime(2.0, 1);
- if(dateTime.valid){
- NTPch.printDateTime(dateTime);
- if(!alarmSet){
- alarmTime = dateTime;
- alarmTime.second = 0;
- alarmTime.hour = 8;
- alarmTime.minute = 45;
- Serial.print("Alarm set!");
- alarmSet = true;
- }
- byte actualHour = dateTime.hour;
- byte actualMinute = dateTime.minute;
- byte actualsecond = dateTime.second;
- int actualyear = dateTime.year;
- byte actualMonth = dateTime.month;
- byte actualday =dateTime.day;
- byte actualdayofWeek = dateTime.dayofWeek;
- if(dateTime.hour >= alarmTime.hour &&
- dateTime.minute >= alarmTime.minute &&
- dateTime.second >= alarmTime.second){
- digitalWrite(23, HIGH);
- }else{
- Serial.println("Sleep time left:"+String(alarmTime.hour - dateTime.hour)+":"+
- String(alarmTime.minute - dateTime.minute)+":"+String(alarmTime.second - dateTime.second));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement