Skip to content

Commit

Permalink
added timezone check
Browse files Browse the repository at this point in the history
  • Loading branch information
DustSwiffer committed May 14, 2022
1 parent 106b5fe commit 6214422
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
24 changes: 24 additions & 0 deletions timer/timeCalculator.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
int getTimeZone(String date){
int month = getMonth(date, '-', 1).toInt();

if(month > 3 && month < 11){
return 1;
}
return 0;
}


String getMonth(String data, char separator, int index){
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;

for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
31 changes: 18 additions & 13 deletions timer.ino → timer/timer.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

#include <NewRemoteTransmitter.h>

WiFiUDP ntpUDP;

#define WLAN_SSID ""
#define WLAN_PASS ""

NTPClient timeClient(ntpUDP);
NTPClient timeClient(ntpUDP, "pool.ntp.org");
NewRemoteTransmitter transmitter(33233314, 14, 232);

void setup() {
Serial.begin(115200);
Expand All @@ -26,29 +26,34 @@ void setup() {

Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());

timeClient.begin();

// Give timeClient the time to wake-up
delay(1000);
}

void loop() {
NewRemoteTransmitter transmitter(33233314, 14, 232);

timeClient.setTimeOffset(3600);
timeClient.update();

String formattedTime = timeClient.getFormattedTime();
String date = timeClient.getFormattedDate();

if(formattedTime == "20:00:00"){
Serial.println("Release the dragon!");
if(getTimeZone(date) == 0){
timeClient.setTimeOffset(3600);
} else{
timeClient.setTimeOffset(7200);
}

String ntpTime = timeClient.getFormattedTime();
Serial.println(date + " time: " + ntpTime);

if(ntpTime == "21:00:00"){
transmitter.sendUnit(1, 0);
}

if(formattedTime == "08:00:00"){
Serial.println("Bed time for spot");
if(ntpTime == "09:00:00"){
transmitter.sendUnit(1, 1);
}

delay(500);


}

0 comments on commit 6214422

Please sign in to comment.