diff --git a/controller/tea_poor/lib/CommandProcessor/CommandProcessor.cpp b/controller/tea_poor/lib/CommandProcessor/CommandProcessor.cpp index c776abf..e5ea18b 100644 --- a/controller/tea_poor/lib/CommandProcessor/CommandProcessor.cpp +++ b/controller/tea_poor/lib/CommandProcessor/CommandProcessor.cpp @@ -20,12 +20,14 @@ bool isValidIntNumber(const char *str, const int maxValue, const int minValue=0) std::string CommandProcessor::status() { std::stringstream response; + const auto now = _env->time(); response << "{"; + // send current time in milliseconds to synchronize time on client side + response << "\"time\": " << now << ", "; // send water threshold response << "\"water threshold\": " << _waterPumpSafeThreshold << ", "; // send water pump status const auto waterPumpStatus = _waterPump->status(); - const auto now = _env->time(); const auto timeLeft = waterPumpStatus.isRunning ? waterPumpStatus.stopTime - now : 0; response << "\"pump\": {" diff --git a/controller/tea_poor/test/test_native/tests/CommandProcessor_test.h b/controller/tea_poor/test/test_native/tests/CommandProcessor_test.h index 291f814..c99b5d2 100644 --- a/controller/tea_poor/test/test_native/tests/CommandProcessor_test.h +++ b/controller/tea_poor/test/test_native/tests/CommandProcessor_test.h @@ -46,6 +46,7 @@ TEST(CommandProcessor, status) { CommandProcessor commandProcessor(123, env, waterPump); const auto response = commandProcessor.status(); ASSERT_EQ(response, "{" + "\"time\": 0, " "\"water threshold\": 123, " "\"pump\": {" " \"running\": false, " @@ -69,6 +70,7 @@ TEST(CommandProcessor, status_running) { const auto response = commandProcessor.status(); ASSERT_EQ(response, "{" + "\"time\": 123, " "\"water threshold\": 12345, " "\"pump\": {" " \"running\": true, "