[SYS] Add timestamp for messages (#1677)
* add timestamp for RTL_433 messages - add timestamp when puglishing - add "GMT" as timezone for timestamp * move timestamp publishing to main.ino
This commit is contained in:
2 files changed
+12
-18
No files matched your search
@@ -692,14 +692,6 @@ void procBLETask(void* pvParameters) {
|
|||||||
String mac_adress = advertisedDevice->getAddress().toString().c_str();
|
String mac_adress = advertisedDevice->getAddress().toString().c_str();
|
||||||
mac_adress.toUpperCase();
|
mac_adress.toUpperCase();
|
||||||
BLEdata["id"] = (char*)mac_adress.c_str();
|
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["mac_type"] = advertisedDevice->getAddress().getType();
|
||||||
BLEdata["adv_type"] = advertisedDevice->getAdvType();
|
BLEdata["adv_type"] = advertisedDevice->getAdvType();
|
||||||
Log.notice(F("Device detected: %s" CR), (char*)mac_adress.c_str());
|
Log.notice(F("Device detected: %s" CR), (char*)mac_adress.c_str());
|
||||||
|
|||||||
+12
-10
@@ -400,6 +400,16 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {
|
|||||||
*/
|
*/
|
||||||
void pub(const char* topicori, JsonObject& data) {
|
void pub(const char* topicori, JsonObject& data) {
|
||||||
String dataAsString = "";
|
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);
|
serializeJson(data, dataAsString);
|
||||||
Log.notice(F("Send on %s msg %s" CR), topicori, dataAsString.c_str());
|
Log.notice(F("Send on %s msg %s" CR), topicori, dataAsString.c_str());
|
||||||
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
|
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
|
||||||
@@ -1953,8 +1963,8 @@ int unixtimestamp() {
|
|||||||
String UTCtimestamp() {
|
String UTCtimestamp() {
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
char buffer[sizeof "yyyy-MM-ddThh:mm:ssZ"];
|
char buffer[sizeof "yyyy-MM-ddThh:mm:ssZGMT"];
|
||||||
strftime(buffer, sizeof buffer, "%FT%TZ", gmtime(&now));
|
strftime(buffer, sizeof buffer, "%FT%TZGMT", gmtime(&now));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1984,14 +1994,6 @@ String stateMeasures() {
|
|||||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
JsonObject SYSdata = jsonBuffer.to<JsonObject>();
|
JsonObject SYSdata = jsonBuffer.to<JsonObject>();
|
||||||
SYSdata["uptime"] = uptime();
|
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;
|
SYSdata["version"] = OMG_VERSION;
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
|
|||||||
Reference in new issue
Block a user