#include <ArduinoJson.h>
char timestamp[15] = "";
void setup() {
Serial.begin(115200);
char buffer[100];
toJsonObject(buffer, sizeof(buffer));
Serial.println(buffer);
}
void loop()
{
timeToString(timestamp, sizeof(timestamp));
Serial.printf("%s: New preset loaded: %u\n", timestamp, 1);
delay(1000);
}
void toJsonObject(char * outputBuffer, size_t bufSize) {
uint8_t fgPalette = 185;
StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
object["fgPalette"] = fgPalette;
serializeJson(doc, outputBuffer, bufSize);
}
void timeToString(char* string, size_t size)
{
unsigned long nowMillis = millis();
unsigned long seconds = nowMillis / 1000;
int days = seconds / 86400;
seconds %= 86400;
byte hours = seconds / 3600;
seconds %= 3600;
byte minutes = seconds / 60;
seconds %= 60;
snprintf(string, size, "%02d:%02d:%02d:%02d", days, hours, minutes, seconds);
}