1616#include " SinricProStrings.h"
1717#include " SinricProUDP.h"
1818#include " SinricProWebsocket.h"
19+ #include " Timestamp.h"
1920namespace SINRICPRO_NAMESPACE {
2021
2122/* *
@@ -107,7 +108,7 @@ class SinricProClass : public SinricProInterface {
107108 SinricProQueue_t receiveQueue;
108109 SinricProQueue_t sendQueue;
109110
110- unsigned long baseTimestamp = 0 ;
111+ Timestamp timestamp ;
111112
112113 bool _begin = false ;
113114 String responseMessageStr = " " ;
@@ -356,7 +357,7 @@ void SinricProClass::handleReceiveQueue() {
356357
357358void SinricProClass::handleSendQueue () {
358359 if (!isConnected ()) return ;
359- if (!baseTimestamp ) return ;
360+ if (!timestamp. getTimestamp () ) return ;
360361 while (sendQueue.size () > 0 ) {
361362 DEBUG_SINRIC (" [SinricPro:handleSendQueue()]: %i message(s) in sendQueue\r\n " , sendQueue.size ());
362363 DEBUG_SINRIC (" [SinricPro:handleSendQueue()]: Sending message...\r\n " );
@@ -366,7 +367,7 @@ void SinricProClass::handleSendQueue() {
366367
367368 DynamicJsonDocument jsonMessage (1024 );
368369 deserializeJson (jsonMessage, rawMessage->getMessage ());
369- jsonMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_createdAt] = getTimestamp ();
370+ jsonMessage[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_createdAt] = timestamp. getTimestamp ();
370371 signMessage (appSecret, jsonMessage);
371372
372373 String messageStr;
@@ -467,7 +468,7 @@ void SinricProClass::extractTimestamp(JsonDocument& message) {
467468 // extract timestamp from timestamp message right after websocket connection is established
468469 tempTimestamp = message[" timestamp" ] | 0 ;
469470 if (tempTimestamp) {
470- baseTimestamp = tempTimestamp - ( millis () / 1000 );
471+ timestamp. setTimestamp (tempTimestamp );
471472 DEBUG_SINRIC (" [SinricPro:extractTimestamp(): Got Timestamp %lu\r\n " , tempTimestamp);
472473 return ;
473474 }
@@ -476,7 +477,7 @@ void SinricProClass::extractTimestamp(JsonDocument& message) {
476477 tempTimestamp = message[FSTR_SINRICPRO_payload][FSTR_SINRICPRO_createdAt] | 0 ;
477478 if (tempTimestamp) {
478479 DEBUG_SINRIC (" [SinricPro:extractTimestamp(): Got Timestamp %lu\r\n " , tempTimestamp);
479- baseTimestamp = tempTimestamp - ( millis () / 1000 );
480+ timestamp. setTimestamp (tempTimestamp );
480481 return ;
481482 }
482483}
@@ -535,7 +536,7 @@ void SinricProClass::setResponseMessage(String&& message) {
535536 * @return unsigned long current timestamp (unix epoch time)
536537 */
537538unsigned long SinricProClass::getTimestamp () {
538- return baseTimestamp + ( millis () / 1000 );
539+ return timestamp. getTimestamp ( );
539540}
540541
541542DynamicJsonDocument SinricProClass::prepareResponse (JsonDocument& requestMessage) {
0 commit comments