Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Tibber Meter with SML Parsing and Enhance HttpBridge for Byte Requests #2597

Open
wants to merge 68 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0ab6166
Create update_script.sh
Sn0w3y Feb 4, 2024
197065f
Implement Shelly Plus1PM
Sn0w3y Feb 4, 2024
7fcb40f
Delete io.openems.edge.io.shelly/src/io/openems/edge/io/shelly/shelly…
Sn0w3y Feb 4, 2024
c23e44d
Implement Shelly Plus1PM
Sn0w3y Feb 4, 2024
adc9091
Merge pull request #1 from Sn0w3y/Sn0w3y-ShellyPlus1PM
Sn0w3y Feb 4, 2024
d2430aa
Delete io.openems.edge.io.shelly/src/io/openems/edge/io/shelly/shelly…
Sn0w3y Feb 4, 2024
e81f0ea
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Feb 7, 2024
c40eba8
Delete io.openems.edge.meter.microcare.sdm630 directory
Sn0w3y Feb 13, 2024
6fdcca5
Changed naming from Microcare to Eastron (#4)
Sn0w3y Feb 13, 2024
4d68320
Samsung ESS (#5)
Sn0w3y Feb 16, 2024
ed771d1
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Feb 17, 2024
929cd00
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Feb 24, 2024
baab3ad
Add files via upload
Sn0w3y Feb 24, 2024
3de883f
Delete src/io/openems/edge/io/opendtu directory
Sn0w3y Feb 24, 2024
86988f9
openDTU Implementation first commit
Sn0w3y Feb 24, 2024
5bf4eda
Update EdgeApp.bndrun
Sn0w3y Feb 24, 2024
3423a74
Delete bnd.bnd
Sn0w3y Feb 24, 2024
0485674
Delete readme.adoc
Sn0w3y Feb 24, 2024
ac0748d
Merge branch 'develop' into feature/openDTU
Sn0w3y Feb 24, 2024
5c971cd
Feature/open dtu (#6)
Sn0w3y Feb 24, 2024
f32dbe4
Merge branch 'feature/openDTU' into develop
Sn0w3y Feb 24, 2024
d5415ce
Fix Themrmometer add Humidity
Sn0w3y Feb 24, 2024
809a68e
Fix Encoding
Sn0w3y Feb 24, 2024
f6b80c9
Fix Encoding
Sn0w3y Feb 24, 2024
e9748f6
Update EdgeApp.bndrun
Sn0w3y Feb 24, 2024
759ce96
Update OpendtuImpl.java
Sn0w3y Feb 24, 2024
4433d4b
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Feb 26, 2024
75aecac
Delete io.openems.edge.io.opendtu directory
Sn0w3y Mar 1, 2024
34f1df7
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 4, 2024
7a08785
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 5, 2024
42eb5e5
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 9, 2024
4150530
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 11, 2024
52237f3
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 13, 2024
62b1185
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 15, 2024
ed1ba59
Create .gitignore
Sn0w3y Mar 17, 2024
f1d03ff
Updates in SamsungESS
Sn0w3y Mar 17, 2024
976d514
Update EdgeApp.bndrun
Sn0w3y Mar 17, 2024
fcf6a55
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Mar 26, 2024
bf49aa5
Initial Commit
Sn0w3y Mar 30, 2024
2609c22
Update EdgeApp.bndrun
Sn0w3y Mar 30, 2024
cc14105
Delete io.openems.edge.meter.tibber/test/.gitignore
Sn0w3y Mar 30, 2024
309673e
Create .gitignore
Sn0w3y Mar 30, 2024
add9109
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Apr 1, 2024
780715e
Delete .github/workflows/docker.yml
Sn0w3y Apr 1, 2024
1376317
Update build.yml
Sn0w3y Apr 2, 2024
d2c7763
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Apr 4, 2024
26cebce
Merge branch 'OpenEMS:develop' into develop
Sn0w3y Apr 8, 2024
4ce00b7
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y Apr 8, 2024
166cb2c
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y Apr 23, 2024
cf86fe4
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y May 10, 2024
c269d58
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y Jun 7, 2024
f4f8885
Updates HttpBridge
Sn0w3y Jun 16, 2024
5c19ae4
Revert "Updates HttpBridge"
Sn0w3y Jun 16, 2024
b7957ee
Merge branch 'develop' into feature/meter-tibber
Sn0w3y Jun 16, 2024
5490950
Revert "Merge branch 'develop' into feature/meter-tibber"
Sn0w3y Jun 16, 2024
aaf6424
Merge remote-tracking branch 'upstream/develop' into feature/meter-ti…
Sn0w3y Jun 16, 2024
2c63a0b
Updates
Sn0w3y Jun 16, 2024
be35a0a
Delete io.openems.edge.meter.tibber/test/.gitignore
Sn0w3y Jun 16, 2024
ef58659
Update NetworkEndpointFetcher.java
Sn0w3y Jun 16, 2024
d6a7433
Merge branch 'feature/meter-tibber' of https://github.com/Sn0w3y/open…
Sn0w3y Jun 16, 2024
cd128f2
Apply prepare-commit.sh
Sn0w3y Jun 16, 2024
b3438a0
Fix
Sn0w3y Jun 16, 2024
9beee76
Revert "Fix"
Sn0w3y Jun 16, 2024
bbb80a5
Revert "Apply prepare-commit.sh"
Sn0w3y Jun 16, 2024
4f091a8
Reapply "Apply prepare-commit.sh"
Sn0w3y Jun 16, 2024
5578b31
Reapply "Fix"
Sn0w3y Jun 16, 2024
874ed6d
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y Jul 3, 2024
5fdb5c1
Merge branch 'OpenEMS:develop' into feature/meter-tibber
Sn0w3y Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.openmuc</groupId>
<artifactId>jsml</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<!-- Apache Felix Configuration Admin Service -->
<!-- Changelog: https://github.com/apache/felix-dev/blob/master/configadmin/changelog.txt -->
Expand Down
4 changes: 4 additions & 0 deletions io.openems.edge.application/EdgeApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
bnd.identity;id='io.openems.edge.timeofusetariff.hassfurt',\
bnd.identity;id='io.openems.edge.timeofusetariff.rabotcharge',\
bnd.identity;id='io.openems.edge.timeofusetariff.tibber',\
bnd.identity;id='io.openems.edge.meter.tibber'

-runbundles: \
Java-WebSocket;version='[1.5.4,1.5.5)',\
Expand Down Expand Up @@ -337,6 +338,7 @@
io.openems.edge.meter.siemens;version=snapshot,\
io.openems.edge.meter.sma.shm20;version=snapshot,\
io.openems.edge.meter.socomec;version=snapshot,\
io.openems.edge.meter.tibber;version=snapshot,\
io.openems.edge.meter.sunspec;version=snapshot,\
io.openems.edge.meter.virtual;version=snapshot,\
io.openems.edge.meter.weidmueller;version=snapshot,\
Expand Down Expand Up @@ -399,6 +401,7 @@
org.apache.commons.commons-compress;version='[1.26.2,1.26.3)',\
org.apache.commons.commons-csv;version='[1.10.0,1.10.1)',\
org.apache.commons.math3;version='[3.6.1,3.6.2)',\
org.apache.commons.codec;version='[1.11.0,1.11.1)',\
org.apache.felix.configadmin;version='[1.9.26,1.9.27)',\
org.apache.felix.eventadmin;version='[1.6.4,1.6.5)',\
org.apache.felix.fileinstall;version='[3.7.4,3.7.5)',\
Expand All @@ -419,6 +422,7 @@
org.jsr-305;version='[3.0.2,3.0.3)',\
org.openmuc.jmbus;version='[3.3.0,3.3.1)',\
org.openmuc.jrxtx;version='[1.0.1,1.0.2)',\
org.openmuc.jsml;version='[1.1.2,1.1.3)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.2.1,2.2.2)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.2.1,2.2.2)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,20 @@ public Collection<CycleEndpoint> removeCycleEndpointIf(Predicate<CycleEndpoint>
.toList();
}

@Override
public CompletableFuture<byte[]> requestRaw(Endpoint endpoint) {
final CompletableFuture<byte[]> future = new CompletableFuture<>();
this.pool.execute(() -> {
try {
// Assuming `fetchEndpointRaw` is a method in `EndpointFetcher` that returns a
// byte array
final byte[] result = this.urlFetcher.fetchEndpointRaw(endpoint);
future.complete(result);
} catch (Exception e) {
future.completeExceptionally(e);
}
});
return future;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static java.util.stream.Collectors.joining;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URI;
Expand Down Expand Up @@ -59,4 +62,37 @@ public HttpResponse<String> fetchEndpoint(final Endpoint endpoint) throws HttpEr
}
}

}
@Override
public byte[] fetchEndpointRaw(Endpoint endpoint) throws HttpError {
try {
var url = URI.create(endpoint.url()).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(endpoint.method().name());
// Set request properties
endpoint.properties().forEach(connection::setRequestProperty);
// Handle request body for POST and PUT methods
if ("POST".equals(endpoint.method().name()) || "PUT".equals(endpoint.method().name())) {
connection.setDoOutput(true);
try (OutputStream os = connection.getOutputStream()) {
byte[] input = endpoint.body().getBytes("utf-8");
os.write(input, 0, input.length);
}
}
// Read response
try (InputStream in = connection.getInputStream()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kann man die zwei methoden nicht zusammen führen, die sehen ja sehr ähnlich aus

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = in.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
} finally {
connection.disconnect();
}
} catch (IOException e) {
throw new HttpError.UnknownError(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,12 @@ private static <I, R> CompletableFuture<R> mapFuture(//
return future;
}

/**
* Fetches the url once and returns the raw byte array of the response.
*
* @param endpoint the {@link Endpoint} to fetch
* @return the result response future containing the raw byte array
*/
CompletableFuture<byte[]> requestRaw(Endpoint endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wahrscheinlich wäre auch hier besser einen HttpResponse zu returnen


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ public interface EndpointFetcher {
*/
public HttpResponse<String> fetchEndpoint(Endpoint endpoint) throws HttpError;

/**
* Executes an HTTP request for the given endpoint and returns the raw response
* body as a byte array.
*
* @param endpoint the {@link Endpoint} to fetch
* @return the raw response body as a byte array
* @throws OpenemsNamedException on error
*/
public byte[] fetchEndpointRaw(Endpoint endpoint) throws HttpError;

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public Collection<TimeEndpoint> removeTimeEndpointIf(Predicate<TimeEndpoint> con
return emptyList();
}

@Override
public CompletableFuture<byte[]> requestRaw(Endpoint endpoint) {
// TODO Auto-generated method stub
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ public void setOnTaskFinished(Runnable onTaskFinished) {
this.onTaskFinished = onTaskFinished == null ? FunctionUtils::doNothing : onTaskFinished;
}

@Override
public byte[] fetchEndpointRaw(Endpoint endpoint) throws HttpError {
// TODO Auto-generated method stub
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ private void nextCycle() {
.handleEvent(new Event(EdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE, new HashMap<>()));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ private static JsonElement successJson() {
.build();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ public void testSubscribeTime() throws Exception {
assertEquals(3, counter.get());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ public void testPlusRandomDelayDelayTimeProviderChainIntTimeUnit() {
assertTrue(durationDelay.getDuration().toSeconds() < 15);
}

}
}
12 changes: 12 additions & 0 deletions io.openems.edge.meter.tibber/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="src" output="bin_test" path="test">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions io.openems.edge.meter.tibber/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin_test/
/generated/
23 changes: 23 additions & 0 deletions io.openems.edge.meter.tibber/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>io.openems.edge.meter.tibber</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
18 changes: 18 additions & 0 deletions io.openems.edge.meter.tibber/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Bundle-Name: OpenEMS Edge Meter Tibber Pulse
Bundle-Vendor: Haller Johannes
Bundle-License: https://opensource.org/licenses/EPL-2.0
Bundle-Version: 1.0.0.${tstamp}

-buildpath: \
${buildpath},\
bcprov,\
io.openems.edge.common,\
io.openems.edge.meter.api,\
io.openems.edge.timedata.api,\
io.openems.common,\
org.openmuc.jsml,\
org.apache.commons.codec,\
io.openems.edge.bridge.http,\

-testpath: \
${testpath}
20 changes: 20 additions & 0 deletions io.openems.edge.meter.tibber/readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
= Meter Tibber Pulse

Implementation of a Tibber Pulse as Grid Meter.

== How to Set Up Pulse:


Since the device has no port available in normal mode and all traffic is encrypted,go back to Setup-Mode. This mode can easily be entered by unplugging the device, plug it and repeat this once. As soon as the green LED lights up, the device opens an access point named „Tibber Bridge“. The password is printed on the QR-Code on the device itself.

This time do not use the tibber app to connect but you Smartphone or Laptop instead. It gets a connection and an IP address assigned from the Tibber Bridge. The Tibber Pulse Bridge itself has the IP 10.133.70.1 and provides a web interface. The credentials are „admin“ and the password printed on the Plug (only can be seen if unplugged).

Open the IP 10.133.70.1 in a Web-Browser and provide the Credentials User: "admin" and Password: "XX12-X123".

Search for the key: "webserver_force_enable" and set it to "true". Scroll down to the end of the Page and click "Store params to flash".

Now again set up the Pulse Bridge with the Tibber App and continue using it. The IP needed is then assigned from your local DHCP-Server.

Done !

https://github.com/OpenEMS/openems/tree/develop/io.openems.edge.meter.tibber[Source Code icon:github[]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.openems.edge.meter.tibber.pulse;

import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import io.openems.edge.meter.api.MeterType;

@ObjectClassDefinition(//
name = "Meter Tibber Pulse", //
description = "Implements the Tibber Pulse as Meter")
@interface Config {

@AttributeDefinition(name = "Component-ID", description = "Unique ID of this Component")
String id() default "meter0";

@AttributeDefinition(name = "Alias", description = "Human-readable name of this Component; defaults to Component-ID")
String alias() default "";

@AttributeDefinition(name = "Is enabled?", description = "Is this Component enabled?")
boolean enabled() default true;

@AttributeDefinition(name = "IP", description = "IP of the Tibber bridge.")
String ip() default "";

@AttributeDefinition(name = "Password", description = "Password of the Tibber bridge", type = AttributeType.PASSWORD)
String password() default "";

@AttributeDefinition(name = "Meter-Type", description = "What is measured by this Meter?")
MeterType type() default MeterType.GRID;

String webconsole_configurationFactory_nameHint() default "Meter Tibber Pulse [{id}]";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.openems.edge.meter.tibber.pulse;

import org.osgi.service.event.EventHandler;

import io.openems.common.channel.Level;
import io.openems.edge.common.channel.Doc;
import io.openems.edge.common.channel.StateChannel;
import io.openems.edge.common.channel.value.Value;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.meter.api.ElectricityMeter;

public interface MeterTibberPulse extends ElectricityMeter, OpenemsComponent, EventHandler {

public static enum ChannelId implements io.openems.edge.common.channel.ChannelId {
/**
* Slave Communication Failed Fault.
*
* <ul>
* <li>Interface: MeterTibberPulse
* <li>Type: State
* </ul>
*/
SLAVE_COMMUNICATION_FAILED(Doc.of(Level.FAULT)); //

private final Doc doc;

private ChannelId(Doc doc) {
this.doc = doc;
}

@Override
public Doc doc() {
return this.doc;
}
}

/**
* Gets the Channel for {@link ChannelId#SLAVE_COMMUNICATION_FAILED}.
*
* @return the Channel
*/
public default StateChannel getSlaveCommunicationFailedChannel() {
return this.channel(ChannelId.SLAVE_COMMUNICATION_FAILED);
}

/**
* Gets the Slave Communication Failed State. See
* {@link ChannelId#SLAVE_COMMUNICATION_FAILED}.
*
* @return the Channel {@link Value}
*/
public default Value<Boolean> getSlaveCommunicationFailed() {
return this.getSlaveCommunicationFailedChannel().value();
}

/**
* Internal method to set the 'nextValue' on
* {@link ChannelId#SLAVE_COMMUNICATION_FAILED} Channel.
*
* @param value the next value
*/
public default void _setSlaveCommunicationFailed(boolean value) {
this.getSlaveCommunicationFailedChannel().setNextValue(value);
}
}
Loading
Loading