#include <WiFi.h>
// #include <TimeLib.h>
#include "time.h"
#include "secrets.h"
tm timeInfo;
time_t s_tm;
time_t now1;
unsigned long epochTime;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S2!");
connectWiFi();
configTime(GMT_OFFSET_SEC, DAY_LIGHT_OFFSET_SEC, NTP_SERVER);
getLocalTime(&timeInfo);
Serial.println(&timeInfo, "%A, %d %B %Y %H:%M:%S");
// setTime(&timeInfo);
// time(&timeInfo);
// setTime(15, 52, 20, 2, 11, 2023);
time(&now1);
}
void loop() {
// s_tm = now();
// Serial.println(s_tm);
epochTime = time(&now1);
Serial.println(epochTime);
delay(2000);
}
// -----------------------------------------------------------------------------
void connectWiFi() {
int counter = 0;
Serial.print(F("Connecting to network: "));
Serial.println(SSID);
WiFi.disconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
counter++;
if (counter >= 60) {
ESP.restart();
}
}
}
// -----------------------------------------------------------------------------
// StaticJsonDocument<2048> doc;
// // DynamicJsonDocument doc(2048);
// deserializeJson(doc, response);
// // Get a reference to the array
// JsonArray repos = doc.as<JsonArray>();
// // // Print the values
// for (JsonObject repo : repos) {
// Serial.print(" - ");
// Serial.print(repo["status"].as<String>());
// // Serial.print(doc["status"].as<String>());
// }
// uint8_t dow(unsigned long t)
// {
// return ((t / 86400) + 4) % 7;
// }Loading
wemos-s2-mini
wemos-s2-mini