Search in sources :

Example 1 with TimedataService

use of io.openems.backend.timedata.api.TimedataService in project openems by OpenEMS.

the class EdgeWebsocketHandler method historicData.

private void historicData(JsonObject jMessageId, JsonObject jHistoricData) {
    // select first QueryablePersistence (by default the running InfluxdbPersistence)
    TimedataService timedataSource = null;
    for (QueryablePersistence queryablePersistence : ThingRepository.getInstance().getQueryablePersistences()) {
        timedataSource = queryablePersistence;
        break;
    }
    if (timedataSource == null) {
        WebSocketUtils.sendNotificationOrLogError(this.websocket, new JsonObject(), LogBehaviour.WRITE_TO_LOG, Notification.NO_TIMEDATA_SOURCE_AVAILABLE);
        return;
    }
    JsonArray jData;
    try {
        jData = timedataSource.queryHistoricData(jHistoricData);
        WebSocketUtils.send(this.websocket, DefaultMessages.historicDataQueryReply(jMessageId, jData));
    } catch (OpenemsException e) {
        WebSocketUtils.sendNotificationOrLogError(this.websocket, jMessageId, LogBehaviour.WRITE_TO_LOG, Notification.UNABLE_TO_QUERY_HISTORIC_DATA, e.getMessage());
    }
    return;
}
Also used : JsonArray(com.google.gson.JsonArray) QueryablePersistence(io.openems.api.persistence.QueryablePersistence) JsonObject(com.google.gson.JsonObject) WriteJsonObject(io.openems.core.utilities.api.WriteJsonObject) OpenemsException(io.openems.common.exceptions.OpenemsException) TimedataService(io.openems.backend.timedata.api.TimedataService)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 QueryablePersistence (io.openems.api.persistence.QueryablePersistence)1 TimedataService (io.openems.backend.timedata.api.TimedataService)1 OpenemsException (io.openems.common.exceptions.OpenemsException)1 WriteJsonObject (io.openems.core.utilities.api.WriteJsonObject)1