Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYS] Add timestamp for messages #1677

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,6 @@ void procBLETask(void* pvParameters) {
String mac_adress = advertisedDevice->getAddress().toString().c_str();
mac_adress.toUpperCase();
BLEdata["id"] = (char*)mac_adress.c_str();
# if defined(ESP8266) || defined(ESP32)
# if message_UTCtimestamp == true
BLEdata["UTCtime"] = UTCtimestamp();
# endif
# if message_unixtimestamp == true
BLEdata["unixtime"] = unixtimestamp();
# endif
# endif
BLEdata["mac_type"] = advertisedDevice->getAddress().getType();
BLEdata["adv_type"] = advertisedDevice->getAdvType();
Log.notice(F("Device detected: %s" CR), (char*)mac_adress.c_str());
Expand Down
22 changes: 12 additions & 10 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {
*/
void pub(const char* topicori, JsonObject& data) {
String dataAsString = "";

#if defined(ESP8266) || defined(ESP32)
# if message_UTCtimestamp == true
data["UTCtime"] = UTCtimestamp();
# endif
# if message_unixtimestamp == true
data["unixtime"] = unixtimestamp();
# endif
#endif

serializeJson(data, dataAsString);
Log.notice(F("Send on %s msg %s" CR), topicori, dataAsString.c_str());
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
Expand Down Expand Up @@ -1953,8 +1963,8 @@ int unixtimestamp() {
String UTCtimestamp() {
time_t now;
time(&now);
char buffer[sizeof "yyyy-MM-ddThh:mm:ssZ"];
strftime(buffer, sizeof buffer, "%FT%TZ", gmtime(&now));
char buffer[sizeof "yyyy-MM-ddThh:mm:ssZGMT"];
strftime(buffer, sizeof buffer, "%FT%TZGMT", gmtime(&now));
return buffer;
}

Expand Down Expand Up @@ -1984,14 +1994,6 @@ String stateMeasures() {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject SYSdata = jsonBuffer.to<JsonObject>();
SYSdata["uptime"] = uptime();
# if defined(ESP8266) || defined(ESP32)
# if message_UTCtimestamp == true
SYSdata["UTCtime"] = UTCtimestamp();
# endif
# if message_unixtimestamp == true
SYSdata["unixtime"] = unixtimestamp();
# endif
# endif

SYSdata["version"] = OMG_VERSION;
# ifdef ZmqttDiscovery
Expand Down