Skip to content

Commit

Permalink
Improve time handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DoomHammer committed Jun 16, 2024
1 parent 85df453 commit f4e31e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Empty file added data/.gitkeep
Empty file.
19 changes: 9 additions & 10 deletions src/odessa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ DynamicJsonDocument doc(MAX_PAYLOAD);

AsyncWebServer server(80);

Timezone tz;

unsigned long ota_progress_millis = 0;

unsigned long mqtt_reconnection_progress_millis = 0;
Expand Down Expand Up @@ -96,18 +98,15 @@ void drawText() {
dma_display->setCursor(0, 1);
}

Timezone tz;
tz.setLocation("Europe/Warsaw");

dma_display->clearScreen();

dma_display->setTextColor(myWHITE);

dma_display->setCursor(0, 8);
dma_display->printf("%04d-%02d-%02d", tz.year(), tz.month(), tz.day());
dma_display->println(tz.dateTime("y-M-d"));

dma_display->setCursor(86, 8);
dma_display->printf("%02d:%02d:%02d", tz.hour(), tz.minute(), tz.second());
dma_display->println(tz.dateTime("H-i-s"));

uint8_t w = 1;
char buffer[100];
Expand Down Expand Up @@ -205,7 +204,6 @@ void sendHassDiscoveryMessage() {
doc["state_topic"] = switchStateTopic;
doc["command_topic"] = switchSetTopic;
doc["availability_topic"] = availabilityTopic;
doc["device"]["name"] = "Tramwajomat";
doc["unique_id"] = client_id;

serializeJson(doc, serialized_json);
Expand Down Expand Up @@ -293,8 +291,6 @@ void setupWifi() {
void setupMqtt() {
client.setServer(MQTT_BROKER, MQTT_BROKER_PORT);
client.setBufferSize(MAX_PAYLOAD);

waitForSync();
}

void setupOta() {
Expand All @@ -318,6 +314,9 @@ void setup() {
setupMqtt();
setupOta();

tz.setLocation("Europe/Warsaw");
waitForSync();

// Setup placeholders
transport_times.emplace_back(std::make_tuple("5", "żółty", "2"));
transport_times.emplace_back(std::make_tuple("12", "Hackerspace", "12"));
Expand Down Expand Up @@ -350,6 +349,8 @@ void mqttLoop() {
sendGratuitiousMessages();
last_gratuitious_message_send_time = millis();
}

client.loop();
}

void loop() {
Expand All @@ -363,8 +364,6 @@ void loop() {
mqttLoop();
}

client.loop();

drawText();

delay(50);
Expand Down

0 comments on commit f4e31e4

Please sign in to comment.