Skip to content

Commit

Permalink
Backport from FEMS for 2022.05 (OpenEMS#1824)
Browse files Browse the repository at this point in the history
- InfluxDB
  - Update to latest v6.0
  - Replace internal InfluxDB async write with our own implementation. For some reason the internal implementation sometimes suddenly stops writing
  - Try rewrite after Field-Type-Conflict
  - Split wrapper bundles
- DummyMetadata: Make sure setInitialized() is called when events can be handled
- Reference Target Filter
  - handle 'null'
  - add low-level method for updating filters
- Json-Exception: improve/shorten error message
- Soltaro Battery: remove unnecessary info channels
- Virtual Meter Subtract
  - Minuend can be null; assume '0' power in that case
  - Fire onSetNextValue to avoid loosing one cycle
- SolarEdge: rename Meter and PV-Inverter to be in line with other components
- RRD4j: add missing OpenemsType handlers
- Tibber: fix OKHTTP deprecation warning
  • Loading branch information
sfeilmeier authored May 15, 2022
1 parent 854b880 commit f6b077a
Show file tree
Hide file tree
Showing 37 changed files with 545 additions and 204 deletions.
45 changes: 34 additions & 11 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@
<version>1.12.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb-client -->
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.14.9</version>
<version>4.9.3</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb-client -->
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
<version>4.9.3</version>
</dependency>
<dependency>
<!-- Used by com.squareup.okhttp3: okhttp -->
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.17.2</version>
<version>2.10.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb-client -->
Expand All @@ -81,8 +81,9 @@
<version>2.9.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava2</artifactId>
<artifactId>adapter-rxjava3</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -140,6 +141,12 @@
<artifactId>SDNotify</artifactId>
<version>1.3</version>
</dependency>
<!-- io -->
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.1.4</version>
</dependency>
<!-- javax -->
<dependency>
<groupId>javax.jmdns</groupId>
Expand Down Expand Up @@ -234,28 +241,38 @@
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-core</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-utils</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>flux-dsl</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>1.6.21</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<!-- HTML processing -->
<groupId>org.jsoup</groupId>
Expand Down Expand Up @@ -308,6 +325,12 @@
<artifactId>postgresql</artifactId>
<version>42.3.4</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb -->
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<!-- Used by io.openems.edge.timedata.rrd4j -->
<groupId>org.rrd4j</groupId>
Expand All @@ -325,4 +348,4 @@
<version>1.7.36</version>
</dependency>
</dependencies>
</project>
</project>
17 changes: 12 additions & 5 deletions io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
com.google.gson;version='[2.9.0,2.9.1)',\
com.google.guava;version='[31.1.0,31.1.1)',\
com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\
com.squareup.okio;version='[2.10.0,2.10.1)',\
com.zaxxer.HikariCP;version='[5.0.1,5.0.2)',\
io.gsonfire;version='[1.8.5,1.8.6)',\
io.openems.backend.alerting;version=snapshot,\
Expand All @@ -67,14 +68,19 @@
io.openems.wrapper.aXMLRPC;version=snapshot,\
io.openems.wrapper.fastexcel;version=snapshot,\
io.openems.wrapper.gson;version=snapshot,\
io.openems.wrapper.influxdb-client;version=snapshot,\
io.openems.wrapper.influxdb-client-core;version=snapshot,\
io.openems.wrapper.influxdb-client-java;version=snapshot,\
io.openems.wrapper.influxdb-client-utils;version=snapshot,\
io.openems.wrapper.influxdb-flux-dsl;version=snapshot,\
io.openems.wrapper.kotlinx-coroutines-core-jvm;version=snapshot,\
io.openems.wrapper.okhttp;version=snapshot,\
io.openems.wrapper.okio;version=snapshot,\
io.openems.wrapper.opczip;version=snapshot,\
io.openems.wrapper.retrofit-adapter-rxjava3;version=snapshot,\
io.openems.wrapper.retrofit-converter-gson;version=snapshot,\
io.openems.wrapper.retrofit-converter-scalars;version=snapshot,\
io.openems.wrapper.retrofit2;version=snapshot,\
io.reactivex.rxjava2.rxjava;version='[2.2.19,2.2.20)',\
io.swagger.annotations;version='[1.6.1,1.6.2)',\
org.apache.commons.commons-csv;version='[1.8.0,1.8.1)',\
io.reactivex.rxjava3.rxjava;version='[3.1.4,3.1.5)',\
org.apache.commons.commons-csv;version='[1.9.0,1.9.1)',\
org.apache.commons.commons-fileupload;version='[1.4.0,1.4.1)',\
org.apache.commons.commons-io;version='[2.8.0,2.8.1)',\
org.apache.felix.configadmin;version='[1.9.24,1.9.25)',\
Expand All @@ -86,6 +92,7 @@
org.apache.felix.scr;version='[2.1.30,2.1.31)',\
org.apache.felix.webconsole;version='[4.7.2,4.7.3)',\
org.apache.felix.webconsole.plugins.ds;version='[2.1.0,2.1.1)',\
org.jetbrains.kotlin.osgi-bundle;version='[1.6.21,1.6.22)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.0.14,2.0.15)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.0.14,2.0.15)',\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected AbstractMetadata(String name) {
*/
protected void setInitialized() {
this.isInitialized.set(true);
EventBuilder.post(getEventAdmin(), Events.AFTER_IS_INITIALIZED);
EventBuilder.post(this.getEventAdmin(), Events.AFTER_IS_INITIALIZED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.util.Optional;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -41,6 +44,7 @@
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfigDiff;
import io.openems.common.utils.StringUtils;
import io.openems.common.utils.ThreadPoolUtils;

@Designate(ocd = Config.class, factory = false)
@Component(//
Expand All @@ -57,6 +61,8 @@ public class DummyMetadata extends AbstractMetadata implements Metadata, EventHa

private final Logger log = LoggerFactory.getLogger(DummyMetadata.class);

private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private final EventAdmin eventAdmin;
private final AtomicInteger nextUserId = new AtomicInteger(-1);
private final AtomicInteger nextEdgeId = new AtomicInteger(-1);

Expand All @@ -65,21 +71,21 @@ public class DummyMetadata extends AbstractMetadata implements Metadata, EventHa

private Language defaultLanguage = Language.DE;

@Reference
private EventAdmin eventAdmin;

public DummyMetadata() {
super("Metadata.Dummy");
this.setInitialized();
}

@Activate
private void activate() {
public DummyMetadata(@Reference EventAdmin eventadmin) {
super("Metadata.Dummy");
this.eventAdmin = eventadmin;
this.logInfo(this.log, "Activate");

// Allow the services some time to settle
this.executor.schedule(() -> {
this.setInitialized();
}, 5, TimeUnit.SECONDS);
}

@Deactivate
private void deactivate() {
ThreadPoolUtils.shutdownAndAwaitTermination(this.executor, 0);
this.logInfo(this.log, "Deactivate");
}

Expand Down
3 changes: 2 additions & 1 deletion io.openems.backend.timedata.influx/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Bundle-Version: 1.0.0.${tstamp}
io.openems.backend.common,\
io.openems.common,\
io.openems.shared.influxdb,\
io.openems.wrapper.influxdb-client
io.openems.wrapper.influxdb-client-core,\
io.openems.wrapper.influxdb-client-java,\

-testpath: \
${testpath}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ private void activate(Config config) throws OpenemsException, IllegalArgumentExc
(throwable) -> {
if (throwable instanceof BadRequestException) {
this.fieldTypeConflictHandler.handleException((BadRequestException) throwable);
return true; // retry write
} else {
this.logError(this.log, "Unable to write to InfluxDB. " + throwable.getClass().getSimpleName()
+ ": " + throwable.getMessage());
return false; // dump points
}
});
}
Expand Down
19 changes: 13 additions & 6 deletions io.openems.common/src/io/openems/common/utils/ConfigUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.openems.common.utils;

import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ConfigUtils {

private ConfigUtils() {
Expand Down Expand Up @@ -39,12 +43,15 @@ public static String generateReferenceTargetFilter(String pid, String... ids) {
targetBuilder.append("(!(service.pid=" + pid + "))");
}
// add filter for given Component-IDs
if (ids.length > 0) {
targetBuilder.append("(|");
for (String id : ids) {
targetBuilder.append("(id=" + id + ")");
}
targetBuilder.append(")");
String idsFilter = Stream.of(ids) //
.filter(Objects::nonNull) //
.map(id -> "(id=" + id + ")") //
.collect(Collectors.joining());
if (!idsFilter.isEmpty()) {
targetBuilder //
.append("(|") //
.append(idsFilter) //
.append(")");
}
targetBuilder.append(")");
return targetBuilder.toString();
Expand Down
5 changes: 3 additions & 2 deletions io.openems.common/src/io/openems/common/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,8 @@ public static Object getAsBestType(JsonElement j) throws OpenemsNamedException {
}
return j.getAsString();
} catch (Exception e) {
throw OpenemsError.JSON_PARSE_ELEMENT_FAILED.exception(j.toString().replace("%", "%%"),
throw OpenemsError.JSON_PARSE_ELEMENT_FAILED.exception(//
StringUtils.toShortString(j.toString().replace("%", "%%"), 100), //
e.getClass().getSimpleName(), e.getMessage());
}
}
Expand Down Expand Up @@ -1440,7 +1441,7 @@ public static JsonElement parse(String string) throws OpenemsNamedException {
try {
return JsonParser.parseString(string);
} catch (JsonParseException e) {
throw OpenemsError.JSON_PARSE_FAILED.exception(e.getMessage(), string);
throw OpenemsError.JSON_PARSE_FAILED.exception(e.getMessage(), StringUtils.toShortString(string, 100));
}
}

Expand Down
17 changes: 12 additions & 5 deletions io.openems.edge.application/EdgeApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
com.google.gson;version='[2.9.0,2.9.1)',\
com.google.guava;version='[31.1.0,31.1.1)',\
com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\
com.squareup.okio;version='[2.10.0,2.10.1)',\
com.sun.jna;version='[5.11.0,5.11.1)',\
io.gsonfire;version='[1.8.5,1.8.6)',\
io.openems.common;version=snapshot,\
Expand Down Expand Up @@ -309,18 +310,23 @@
io.openems.wrapper.eu.chargetime.ocpp;version=snapshot,\
io.openems.wrapper.fastexcel;version=snapshot,\
io.openems.wrapper.gson;version=snapshot,\
io.openems.wrapper.influxdb-client;version=snapshot,\
io.openems.wrapper.influxdb-client-core;version=snapshot,\
io.openems.wrapper.influxdb-client-java;version=snapshot,\
io.openems.wrapper.influxdb-client-utils;version=snapshot,\
io.openems.wrapper.influxdb-flux-dsl;version=snapshot,\
io.openems.wrapper.javax.activation;version=snapshot,\
io.openems.wrapper.kotlinx-coroutines-core-jvm;version=snapshot,\
io.openems.wrapper.okhttp;version=snapshot,\
io.openems.wrapper.okio;version=snapshot,\
io.openems.wrapper.opczip;version=snapshot,\
io.openems.wrapper.paho-mqttv5;version=snapshot,\
io.openems.wrapper.retrofit-adapter-rxjava3;version=snapshot,\
io.openems.wrapper.retrofit-converter-gson;version=snapshot,\
io.openems.wrapper.retrofit-converter-scalars;version=snapshot,\
io.openems.wrapper.retrofit2;version=snapshot,\
io.openems.wrapper.sdnotify;version=snapshot,\
io.reactivex.rxjava2.rxjava;version='[2.2.19,2.2.20)',\
io.swagger.annotations;version='[1.6.1,1.6.2)',\
io.reactivex.rxjava3.rxjava;version='[3.1.4,3.1.5)',\
javax.xml.soap-api;version='[1.4.0,1.4.1)',\
org.apache.commons.commons-csv;version='[1.8.0,1.8.1)',\
org.apache.commons.commons-csv;version='[1.9.0,1.9.1)',\
org.apache.commons.commons-fileupload;version='[1.4.0,1.4.1)',\
org.apache.commons.commons-io;version='[2.8.0,2.8.1)',\
org.apache.commons.math3;version='[3.6.1,3.6.2)',\
Expand All @@ -334,6 +340,7 @@
org.apache.felix.webconsole;version='[4.7.2,4.7.3)',\
org.apache.felix.webconsole.plugins.ds;version='[2.1.0,2.1.1)',\
org.eclipse.paho.mqttv5.client;version='[1.2.5,1.2.6)',\
org.jetbrains.kotlin.osgi-bundle;version='[1.6.21,1.6.22)',\
org.jsoup;version='[1.14.3,1.14.4)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
org.openmuc.jmbus;version='[3.3.0,3.3.1)',\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,6 @@ public static enum ChannelId implements io.openems.edge.common.channel.ChannelId
.text("Cell Voltage High Alarm Level 1")), //

// Pre-Alarm
PRE_ALARM_CELL_VOLTAGE_HIGH(Doc.of(Level.INFO) //
.text("Cell Voltage High Pre-Alarm")), //
PRE_ALARM_TOTAL_VOLTAGE_HIGH(Doc.of(Level.INFO) //
.text("Total Voltage High Pre-Alarm")), //
PRE_ALARM_CHARGE_CURRENT_HIGH(Doc.of(Level.INFO) //
.text("Charge Current High Pre-Alarm")), //
PRE_ALARM_CELL_VOLTAGE_LOW(Doc.of(Level.INFO) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,11 @@ protected ModbusProtocol defineModbusProtocol() throws OpenemsException {
.bit(15, SingleRackVersionC.ChannelId.LEVEL1_DISCHARGE_TEMP_LOW) //
), //

// Pre-Alarm: Temperature Alarm will active current limication
// Pre-Alarm: Temperature Alarm will active current limitation
m(new BitsWordElement(0x2142, this) //
.bit(0, SingleRackVersionC.ChannelId.PRE_ALARM_CELL_VOLTAGE_HIGH) //
.bit(1, SingleRackVersionC.ChannelId.PRE_ALARM_TOTAL_VOLTAGE_HIGH) //
// Removed Warning/Info as this is properly covered by Battery Protection
// .bit(0, SingleRackVersionC.ChannelId.PRE_ALARM_CELL_VOLTAGE_HIGH) //
// .bit(1, SingleRackVersionC.ChannelId.PRE_ALARM_TOTAL_VOLTAGE_HIGH) //
.bit(2, SingleRackVersionC.ChannelId.PRE_ALARM_CHARGE_CURRENT_HIGH) //
.bit(3, SingleRackVersionC.ChannelId.PRE_ALARM_CELL_VOLTAGE_LOW) //
.bit(4, SingleRackVersionC.ChannelId.PRE_ALARM_TOTAL_VOLTAGE_LOW) //
Expand Down
Loading

0 comments on commit f6b077a

Please sign in to comment.