Class InfluxConnector


  • public class InfluxConnector
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String MEASUREMENT  
    • Constructor Summary

      Constructors 
      Constructor Description
      InfluxConnector​(java.lang.String ip, int port, java.lang.String username, java.lang.String password, java.lang.String database, java.lang.String retentionPolicy, boolean isReadOnly, java.util.function.BiConsumer<java.lang.Iterable<org.influxdb.dto.Point>,​java.lang.Throwable> onWriteError)
      The Constructor.
    • Constructor Detail

      • InfluxConnector

        public InfluxConnector​(java.lang.String ip,
                               int port,
                               java.lang.String username,
                               java.lang.String password,
                               java.lang.String database,
                               java.lang.String retentionPolicy,
                               boolean isReadOnly,
                               java.util.function.BiConsumer<java.lang.Iterable<org.influxdb.dto.Point>,​java.lang.Throwable> onWriteError)
        The Constructor.
        Parameters:
        ip - IP-Address of the InfluxDB-Server
        port - Port of the InfluxDB-Server
        username - The username
        password - The password
        database - The database name. If it does not exist, it will be created
        isReadOnly - If true, a 'Read-Only-Mode' is activated, where no data is actually written to the database
        onWriteError - A callback for write-errors, i.e. '(failedPoints, throwable) -> {}'
    • Method Detail

      • getDatabase

        public java.lang.String getDatabase()
      • deactivate

        public void deactivate()
      • executeQuery

        public org.influxdb.dto.QueryResult executeQuery​(java.lang.String query)
                                                  throws OpenemsException
        Copied from backend.timedata.influx.provider.
        Parameters:
        query - the Query
        Returns:
        the QueryResult
        Throws:
        OpenemsException - on error
      • queryHistoricEnergy

        public java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement> queryHistoricEnergy​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                         java.time.ZonedDateTime fromDate,
                                                                                                         java.time.ZonedDateTime toDate,
                                                                                                         java.util.Set<ChannelAddress> channels)
                                                                                                  throws OpenemsError.OpenemsNamedException
        Queries historic energy.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        Returns:
        a map between ChannelAddress and value
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • queryHistoricEnergyPerPeriod

        public java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricEnergyPerPeriod​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                                                                                     java.time.ZonedDateTime fromDate,
                                                                                                                                                                     java.time.ZonedDateTime toDate,
                                                                                                                                                                     java.util.Set<ChannelAddress> channels,
                                                                                                                                                                     int resolution)
                                                                                                                                                              throws OpenemsError.OpenemsNamedException
        Queries historic energy per period.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        resolution - the resolution in seconds
        Returns:
        the historic data as Map
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • queryHistoricData

        public java.util.SortedMap<java.time.ZonedDateTime,​java.util.SortedMap<ChannelAddress,​com.google.gson.JsonElement>> queryHistoricData​(java.util.Optional<java.lang.Integer> influxEdgeId,
                                                                                                                                                          java.time.ZonedDateTime fromDate,
                                                                                                                                                          java.time.ZonedDateTime toDate,
                                                                                                                                                          java.util.Set<ChannelAddress> channels,
                                                                                                                                                          int resolution)
                                                                                                                                                   throws OpenemsError.OpenemsNamedException
        Queries historic data.
        Parameters:
        influxEdgeId - the unique, numeric Edge-ID; or Empty to query all Edges
        fromDate - the From-Date
        toDate - the To-Date
        channels - the Channels to query
        resolution - the resolution in seconds
        Returns:
        the historic data as Map
        Throws:
        OpenemsException - on error
        OpenemsError.OpenemsNamedException
      • write

        public void write​(org.influxdb.dto.Point point)
                   throws OpenemsException
        Actually write the Point to InfluxDB.
        Parameters:
        point - the InfluxDB Point
        Throws:
        OpenemsException - on error