Skip to content

Commit

Permalink
parse local time in callback example
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtreece authored Jul 8, 2016
1 parent 8287305 commit 63d86e2
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions examples/mqtt_esp8266_callback/mqtt_esp8266_callback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,47 @@ Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAM

/*************************** Sketch Code ************************************/

void timecallback(uint32_t x) {
Serial.print("Hey we're in a time callback, the epoch time is: ");
Serial.println(x);
int sec;
int min;
int hour;

int timeZone = -4; // utc-4 eastern daylight time (nyc)

void timecallback(uint32_t current) {

// adjust to local time zone
current += (timeZone * 60 * 60);

// calculate current time
sec = current % 60;
current /= 60;
min = current % 60;
current /= 60;
hour = current % 24;

// print hour
if(hour == 0 || hour == 12)
Serial.print("12");
if(hour < 12)
Serial.print(hour);
else
Serial.print(hour - 12);

// print mins
Serial.print(":");
if(min < 10) Serial.print("0");
Serial.print(min);

// print seconds
Serial.print(":");
if(sec < 10) Serial.print("0");
Serial.print(sec);

if(hour < 12)
Serial.println(" am");
else
Serial.println(" pm");

}

void slidercallback(double x) {
Expand Down Expand Up @@ -144,4 +182,4 @@ void MQTT_connect() {
}
}
Serial.println("MQTT Connected!");
}
}

0 comments on commit 63d86e2

Please sign in to comment.