i get the current time with the example code istimneforset, everything works fine.
now i want to get the current time from the function "Serial.println(timeClient.getFormattedTime());" and i am trying to cache the first character of the array.
code:
#include <NTPClient.h>
// Change the next line to use with a different map/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>
const char *ssid =" *";
const char *password = "*";
WiFiUDP ntpUDP;
// initialized to a time offset of 10 hours
NTPClient timeClient(ntpUDP, "pool.ntp.org", 36000, 60000);
// HH:MM:SS
// timeClient is initialized to 10:00:00 if it does not receive an NTP packet
// before the timeout of 100ms is received.
// Without isTimeSet(), the LED would be lit even though the time was
// was not yet set correctly.
const int hour = 10;
const int minute = 0;
void setup(){
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay (500);
Serial.print(".");
}
timeClient.begin();
}
void loop() {
timeClient.update();
//Serial.println(timeClient.getFormattedTime());
int stund2 = (timeClient.getFormattedTime()[0]);
Serial.println(stund2);
}
unfortunately it always gives me a wrong value. my goal is to have the current hour in a variable. can someone help me? thanks!