ISO Time Timezone
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- goveil1
- Posts: 21
- Joined: Wed May 08, 2019 10:28 am
ISO Time Timezone
I am using Adafruit IO to remotely display the status of a garage door. I subscribed to the Arduino library ISO Time feed and it works just fine, except I do not see a way using the Arduino library to indicate a timezone. Documentation says it will 'guess' based upon IP location, but I am getting UTC instead. It would be great if I could solve it and also wondering if local timezone (if I can get it!) auto-adjusts for Daylight Savings time in the zone
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: ISO Time Timezone
I see some examples of manually overriding UTC with a few lines of code to compensate for TimeZone.
https://github.com/adafruit/Adafruit_MQ ... sp8266.ino
Code: Select all
// set timezone offset from UTC
int timeZone = -4; // UTC - 4 eastern daylight time (nyc)
int interval = 4; // trigger every X hours
int hour = 0; // current hour
void timecallback(uint32_t current) {
// stash previous hour
int previous = hour;
// adjust to local time zone
current += (timeZone * 60 * 60);
// calculate current hour
hour = (current / 60 / 60) % 24;
// only trigger on interval
if((hour != previous) && (hour % interval) == 0) {
Serial.println("Run your code here");
}
}
- goveil1
- Posts: 21
- Joined: Wed May 08, 2019 10:28 am
Re: ISO Time Timezone
Thanks! Pretty similar to what I ended up doing. The documentation makes it seem like you can add a timezone parameter to the Time_ISO call, but I can't figure out how.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: ISO Time Timezone
I found this example code for getting started with Time_ISO.
https://github.com/adafruit/Adafruit_IO ... scribe.ino
Code: Select all
// Adafruit IO Time Topic Subscription Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Adam Bachman, Brent Rubell for Adafruit Industries
// Copyright (c) 2018 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
/************************** Configuration ***********************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"
/************************ Example Starts Here *******************************/
// set up the 'time/seconds' topic
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);
// set up the 'time/milliseconds' topic
AdafruitIO_Time *msecs = io.time(AIO_TIME_MILLIS);
// set up the 'time/ISO-8601' topic
AdafruitIO_Time *iso = io.time(AIO_TIME_ISO);
void setup() {
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// start MQTT connection to io.adafruit.com
io.connect();
// attach message handler for the seconds feed
seconds->onMessage(handleSecs);
// attach a message handler for the msecs feed
msecs->onMessage(handleMillis);
// attach a message handler for the ISO feed
iso->onMessage(handleISO);
// wait for an MQTT connection
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
// method to check on MQTT connection status specifically
while(io.mqttStatus() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// Because this sketch isn't publishing, we don't need
// a delay() in the main program loop.
}
// message handler for the seconds feed
void handleSecs(char *data, uint16_t len) {
Serial.print("Seconds Feed: ");
Serial.println(data);
}
// message handler for the milliseconds feed
void handleMillis(char *data, uint16_t len) {
Serial.print("Millis Feed: ");
Serial.println(data);
}
// message handler for the ISO-8601 feed
void handleISO(char *data, uint16_t len) {
Serial.print("ISO Feed: ");
Serial.println(data);
}
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.