#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "fixed_number.h"
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET -18000
#define UTC_OFFSET_DST 0
#define PIN_FLAG_MINUTES 14
#define PIN_FLAG_WEEKS 12
#define PIN_ENABLE 18
#define PIN_STEP 2
#define PIN_DIR 15
#define PRINT_REFRESH 1000
int last_print = 0;
int last_step = 0;
void printLocalTime() {
}
void setup() {
Serial.begin(115200);
pinMode(PIN_FLAG_MINUTES, INPUT_PULLUP);
pinMode(PIN_FLAG_WEEKS, INPUT_PULLUP);
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_STEP, OUTPUT);
pinMode(PIN_DIR, OUTPUT);
digitalWrite(PIN_ENABLE, LOW);
digitalWrite(PIN_STEP, LOW);
digitalWrite(PIN_DIR, LOW);
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
// Your HTTP request
HTTPClient http;
http.begin("http://www.google.com"); // Specify the URL
// Send the request
int httpResponseCode = http.GET();
// Read the response
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
} else {
Serial.print("HTTP Request failed. Error code: ");
Serial.println(httpResponseCode);
}
http.end(); // Close connection
last_step = millis();
}
void loop() {
int current_time = millis();
if (current_time - last_print > PRINT_REFRESH) {
last_print = current_time;
struct tm timeinfo;
if (getLocalTime(&timeinfo)) {
Serial.println(&timeinfo, "%H:%M:%S");
Serial.println(&timeinfo, "%d/%m/%Y %Z");
}
}
if (current_time - last_step > 3000) {
last_step = current_time;
digitalWrite(PIN_STEP, !digitalRead(PIN_STEP));
}
delay(10);
}