Wifi Clock + Wifi Manager with timezone selection in wifi manager

Hi,
I am looking at making a wifi clock + wifi manager similar to the one with the code below.
I want to make the timezone offset a variable which is entered via the wifi manager screen, any pointers how to do this?
I assume I need to save a variable from wifi manager but not sure how to do that, looks like i need to modify the library code....

Any help appreciated

#include <NTPClient.h>
#include <ESP8266WiFi.h>  
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> 

#include <WiFiUdp.h> //handles sending and receiving of UDP packages
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMono9pt7b.h>

Adafruit_SSD1306 display(128, 64,&Wire, D0);
WiFiUDP ntpUDP;
/*
 * for INDIA 5:30
 * 5X60X60 = 18000
 * 30x60 = 1800
 * 1800+18000 = 198000
 */
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800,60000);
String voidloop[] ={"v","o","i","d"," ","L","o","o","p"};
String arr_days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
String date_time;

void setup(){
  Serial.begin(115200);
 
  if(!display.begin(SSD1306_SWITCHCAPVCC,0x3C))
  {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  display.clearDisplay();
  display.setFont(&FreeMono9pt7b);
  display.setTextSize(1); 
  display.setTextColor(WHITE);
  display.setCursor(10, 30);
  for(int i=0; i<=8; i++)
  {
  display.print(voidloop[i]);
  display.display();
  delay(250);
  
  }

  WiFiManager wifiManager;
  wifiManager.autoConnect("AutoConnectAP");
  Serial.println("connected... :)");
  timeClient.begin();
  display.clearDisplay();
  
  
}

void loop() {
  timeClient.update();  // time update from NTP server
  display.clearDisplay();
  Serial.println(timeClient.getFormattedTime());
  display.setFont(&FreeMono9pt7b);
  display.setTextSize(1); 
  display.setTextColor(WHITE);
  display.setCursor(4, 12);      
  date_time = timeClient.getFormattedDate();
  int index_date = date_time.indexOf("T");
  String date = date_time.substring(0, index_date);
  Serial.println(date);
  display.println(date);  // date will print on oled display
  display.print(" ");
  display.println(timeClient.getFormattedTime());  // time will be printed on oled display
  /*
  int hh = timeClient.getHours();
  int mm = timeClient.getMinutes();
  int ss = timeClient.getSeconds();
  
  if(hh>12)
  {
    hh=hh-12;
    display.print(hh);
    display.print(":");
    display.print(mm);
    display.print(":");
    display.print(ss);
    display.println(" PM");
  }
  else
  {
    display.print(hh);
    display.print(":");
    display.print(mm);
    display.print(":");
    display.print(ss);
    display.println(" AM");   
  }
*/
  int day = timeClient.getDay();
  display.print("    ");
  display.print(arr_days[day]);  //  it will print day

  display.display();
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.