Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. /*
  2. This sketch shows an example of sending a reading to data.sparkfun.com once per day.
  3. It uses the Sparkfun testing stream so the only customizing required is the WiFi SSID and password.
  4. The Harringay Maker Space
  5. License: Apache License v2
  6. */
  7. #include <NTPtimeESP.h>
  8.  
  9. //#include <Wire.h>
  10. //#include <Adafruit_GFX.h>
  11. //#include <Adafruit_SSD1306.h>
  12. //
  13. //#define OLED_RESET 4
  14. //Adafruit_SSD1306 display(OLED_RESET);
  15.  
  16. //#define DEBUG_ON
  17.  
  18.  
  19. NTPtime NTPch("0.pool.ntp.org"); // Choose server pool as required
  20. char *ssid = "Bankausku"; // Set you WiFi SSID
  21. char *password = "VapeNation"; // Set you WiFi password
  22.  
  23. /*
  24. * The structure contains following fields:
  25. * struct strDateTime
  26. {
  27. byte hour;
  28. byte minute;
  29. byte second;
  30. int year;
  31. byte month;
  32. byte day;
  33. byte dayofWeek;
  34. boolean valid;
  35. };
  36. */
  37. strDateTime dateTime;
  38. strDateTime alarmTime;
  39. void setup() {
  40. Serial.begin(115200);
  41. Serial.println();
  42. Serial.println("Booted");
  43. Serial.println("Connecting to Wi-Fi");
  44. //WiFi.mode(WIFI_STA);
  45. WiFi.begin(ssid, password);
  46. while (WiFi.status() != WL_CONNECTED) {
  47. Serial.print(".");
  48. delay(500);
  49. }
  50. Serial.println("WiFi connected");
  51. pinMode(23, OUTPUT);
  52. digitalWrite(23, LOW);
  53.  
  54. }
  55.  
  56. bool alarmSet = false;
  57.  
  58. void loop() {
  59. // first parameter: Time zone in floating point (for India);
  60. // second parameter: 1 for European summer time; 2 for US daylight saving time (contributed by viewwer, not tested by me)
  61.  
  62. // check dateTime.valid before using the returned time
  63. // Use "setSendInterval" or "setRecvTimeout" if required
  64. dateTime = NTPch.getNTPtime(2.0, 1);
  65. if(dateTime.valid){
  66. NTPch.printDateTime(dateTime);
  67. if(!alarmSet){
  68. alarmTime = dateTime;
  69. alarmTime.second = 0;
  70. alarmTime.hour = 8;
  71. alarmTime.minute = 45;
  72. Serial.print("Alarm set!");
  73. alarmSet = true;
  74. }
  75. byte actualHour = dateTime.hour;
  76. byte actualMinute = dateTime.minute;
  77. byte actualsecond = dateTime.second;
  78. int actualyear = dateTime.year;
  79. byte actualMonth = dateTime.month;
  80. byte actualday =dateTime.day;
  81. byte actualdayofWeek = dateTime.dayofWeek;
  82.  
  83. if(dateTime.hour >= alarmTime.hour &&
  84. dateTime.minute >= alarmTime.minute &&
  85. dateTime.second >= alarmTime.second){
  86. digitalWrite(23, HIGH);
  87. }else{
  88. Serial.println("Sleep time left:"+String(alarmTime.hour - dateTime.hour)+":"+
  89. String(alarmTime.minute - dateTime.minute)+":"+String(alarmTime.second - dateTime.second));
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement