#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "config.h"
struct {
int id;
int loc;
} data[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
/* float x = 11.2223;
uint32_t f = *(unsigned int*)&x;
Serial.println(f, HEX);
PrintHex32(f);
Serial.println(sizeof(x));
Serial.print(x, 4);
Serial.println("");
char l[sizeof(x)];
sprintf(l, "%4.4f", x);
Serial.println(sizeof(l));
Serial.print(l);
Serial.println("");
for (int i = 0; i < sizeof(l); i++) {
PrintHex(l[i]);
Serial.print(" ");
};
Serial.println(""); */
setenv("TZ", "3", 1);
tzset();
struct tm timeinfo;
struct tm rtcinfo;
rtcinfo.tm_year = 2023 - 1900;
rtcinfo.tm_mon = 10 - 1;
rtcinfo.tm_mday = 18;
rtcinfo.tm_hour = 14;
rtcinfo.tm_min = 12;
rtcinfo.tm_sec = 21;
rtcinfo.tm_isdst = -1;
time_t rtcnow = mktime(&rtcinfo);
localtime_r(&rtcnow, &timeinfo);
struct timeval tset = {.tv_sec = rtcnow};
settimeofday(&tset, NULL);
char strftime_buf[64];
strftime(strftime_buf, sizeof(strftime_buf), "%d-%m-%y %H:%M:%S", &timeinfo);
Serial.printf("The current date/time in: %s\n", strftime_buf);
char time_buf[14];
sprintf(time_buf, "%04d%02d%02d%02d%02d%02d", timeinfo.tm_year + 1900, timeinfo.tm_mon + 1,timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
Serial.printf("The current date/time in: %s sizeof: %d\n", time_buf, sizeof(time_buf));
int year, mon, mday, hour, minute, sec;
sscanf(time_buf,"%04d%02d%02d%02d%02d%02d", &year, &mon, &mday, &hour, &minute, &sec);
struct tm info;
info.tm_year = year - 1900;
info.tm_mon = mon - 1;
info.tm_mday = mday;
info.tm_hour = hour;
info.tm_min = minute;
info.tm_sec = sec;
info.tm_isdst = -1;
time_t infonow = mktime(&info);
struct tm timeeinfo;
localtime_r(&infonow, &timeeinfo);
char infotime_buf[64];
strftime(infotime_buf, sizeof(infotime_buf), "%d-%m-%y %H:%M:%S", &timeeinfo);
Serial.printf("The current date/time new in: %s\n", infotime_buf);
for (int i = 0; i < 5; i++) {
delay(65000);
time_t now;
struct tm timeinfo;
char strftime_buf[64];
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%d-%m-%y %H:%M:%S", &timeinfo);
Serial.printf("The current date/time in: %s\n", strftime_buf);
};
/* struct timeval now = { .tv_sec = t };
settimeofday(&now, NULL);
time(&now);
now = now + (3*60*60);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%m-%d-%y %H:%M:%S", &timeinfo);
Serial.printf("The current date/time in New York is: %s\n", strftime_buf); */
/* strftime(strftime_buf, sizeof(strftime_buf), "%m-%d-%y %H:%M:%S", &timeinfo);
Serial.printf("The current date/time in New York is: %s\n", strftime_buf); */
/* strftime(strftime_buf, sizeof(strftime_buf), "%04d-%02d-%02d %02d:%02d:%02d", timeinfo.tm_year, timeinfo.tm_mon + 1,
timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec); */
/* strftime(strftime_buf, sizeof(strftime_buf), "%m-%d-%y %H:%M:%S", &timeinfo); */
//Serial.printf("The current date/time in New York is: %s\n", strftime_buf);
/* data[0].id = 1;
data[0].loc = 2;
for (int i = 0; i < 10; i++) {
Serial.print("id: ");
Serial.print((int)data[i].id);
Serial.print(", loc: ");
Serial.print((int)data[i].loc);
Serial.println("");
}; */
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
/* void PrintHex(uint8_t str)
{
Serial.print("0x");
Serial.print(str < 16 ? "0" : "");
Serial.print(str, HEX);
}
void PrintHex16(uint16_t data) // prints 16-bit data in hex with leading zeroes
{
Serial.print("0x");
uint8_t MSB=byte(data>>8);
uint8_t LSB=byte(data);
if (MSB<0x10) {Serial.print("0");} Serial.print(MSB,HEX);
if (LSB<0x10) {Serial.print("0");} Serial.print(LSB,HEX);
}
void PrintHex32(uint32_t str) // prints 16-bit data in hex with leading zeroes
{
Serial.print("0x");
test[0] = (int)((str & 0xF00000) >> 16);
test[1] = (int)((str & 0x0F0000) >> 16);
test[2] = (int)((str & 0x00F000) >> 16);
test[3] = (int)((str & 0x00F00) >> 16);
test[4] = (int)((str & 0x000F0));
test[5] = (int)((str & 0x0000F));
for (int i = 0; i < sizeof(test); i++) {
Serial.print((int)test[i]);
}
Serial.println("");
} */