diff --git a/ChangeLog.md b/ChangeLog.md index 25d2d78e..2ecfb5b5 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -13,7 +13,7 @@ * changed docker image to be smaller size and fixed missing library dependencies * added automatic reconnect to MQTT broker * changed logging for messages from "updated" to "received" and "sent" depending on who initiated the request -* added support for serving .csv files to HTTP/JSON port +* added support for serving .csv files and new argument maxage to HTTP/JSON port # 3.1 (2017-12-26) diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 63594433..f4e68c3a 100755 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -1602,6 +1602,7 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri bool numeric = false, valueName = false, required = false, full = false, withWrite = false, raw = false; bool withDefinition = false; OutputFormat verbosity = OF_NAMES; + time_t maxAge = -1; size_t argPos = 1; string uri = args[argPos++]; int type = -1; @@ -1655,6 +1656,9 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri full = parseBoolQuery(value); } else if (qname == "required") { required = parseBoolQuery(value); + } else if (qname == "maxage") { + maxAge = parseInt(value.c_str(), 10, 0, 24*60*60, &ret); + required = true; } else if (qname == "write") { withWrite = parseBoolQuery(value); } else if (qname == "raw") { @@ -1677,6 +1681,8 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri *ostream << "{"; string lastCircuit; + time_t now; + time(&now); time_t maxLastUp = 0; if (ret == RESULT_OK) { bool first = true; @@ -1696,7 +1702,7 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri m_messages->addPollMessage(false, message); } time_t lastup = message->getLastUpdateTime(); - if (lastup == 0 && required) { + if (required && (lastup == 0 || (maxAge >=0 && lastup + maxAge > now))) { // read directly from bus if (message->isPassive()) { continue; // not possible to actively read this message