Erste Version in gitea
This commit is contained in:
commit
286e025067
40
.classpath
Normal file
40
.classpath
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target/
|
||||
/dependency-reduced-pom.xml
|
||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>meter-to-influx</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
58
pom.xml
Normal file
58
pom.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>info.peper</groupId>
|
||||
<artifactId>meter-to-influx</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.fazecast/jSerialComm -->
|
||||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>
|
||||
info.peper.serialtest.SerialTestMain</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
45
src/main/java/info/peper/serialtest/DecodeSmlMain.java
Normal file
45
src/main/java/info/peper/serialtest/DecodeSmlMain.java
Normal file
@ -0,0 +1,45 @@
|
||||
package info.peper.serialtest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class DecodeSmlMain {
|
||||
|
||||
private static final int[] SEQ = new int[] {0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0x00};
|
||||
|
||||
public static void decode(final InputStream is, final NewValueListener listener) throws IOException {
|
||||
int curPos = 0;
|
||||
int readStatus = 0;
|
||||
int value = 0;
|
||||
int readByte;
|
||||
do {
|
||||
readByte = is.read();
|
||||
if (readByte != -1) {
|
||||
if (readStatus == 0) {
|
||||
if (readByte == SEQ[curPos]) {
|
||||
curPos++;
|
||||
} else {
|
||||
curPos = 0;
|
||||
}
|
||||
if (curPos == SEQ.length) {
|
||||
curPos = 0;
|
||||
readStatus = Integer.MAX_VALUE;
|
||||
}
|
||||
} else if (readStatus == Integer.MAX_VALUE) {
|
||||
if ((readByte & 0xF0) == 80) {
|
||||
readStatus = readByte & 0x0F - 1;
|
||||
}
|
||||
} else {
|
||||
value *= 256;
|
||||
value += readByte;
|
||||
readStatus--;
|
||||
if (readStatus == 0) {
|
||||
listener.newValue(value);
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (readByte != -1);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package info.peper.serialtest;
|
||||
|
||||
public interface NewValueListener {
|
||||
void newValue(int value);
|
||||
}
|
||||
39
src/main/java/info/peper/serialtest/SerialTestMain.java
Normal file
39
src/main/java/info/peper/serialtest/SerialTestMain.java
Normal file
@ -0,0 +1,39 @@
|
||||
package info.peper.serialtest;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.fazecast.jSerialComm.SerialPort;
|
||||
|
||||
public class SerialTestMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (SerialPort port : SerialPort.getCommPorts()) {
|
||||
System.out.println(port.getSystemPortName() + ": " + port.getDescriptivePortName());
|
||||
}
|
||||
|
||||
if (SerialPort.getCommPorts().length == 1) {
|
||||
SerialPort serialPort = SerialPort.getCommPorts()[0];
|
||||
if (!serialPort.setComPortParameters(9600, 8, 1, SerialPort.NO_PARITY)) {
|
||||
System.err.println("ComPortParameter konnten nicht korrekt gesetzt werden.");
|
||||
System.exit(1);
|
||||
}
|
||||
if (!serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 0, 0)) {
|
||||
System.err.println("ComPortTimeouts konnten nicht korrekt gesetzt werden.");
|
||||
System.exit(1);
|
||||
}
|
||||
serialPort.openPort();
|
||||
final NewValueListener listener = new NewValueListener() {
|
||||
|
||||
@Override
|
||||
public void newValue(int value) {
|
||||
System.out.println(value);
|
||||
}
|
||||
};
|
||||
try (InputStream is = serialPort.getInputStream();) {
|
||||
DecodeSmlMain.decode(is, listener);
|
||||
}
|
||||
serialPort.closePort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
69
src/main/java/info/peper/shelly/ReadShellyCloudMain.java
Normal file
69
src/main/java/info/peper/shelly/ReadShellyCloudMain.java
Normal file
@ -0,0 +1,69 @@
|
||||
package info.peper.shelly;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class ReadShellyCloudMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final OkHttpClient httpClient = new OkHttpClient();
|
||||
final RequestBody requestBody = new FormBody.Builder()
|
||||
.add("auth_key", "MmQ3ZHVpZA71BA656BE0DBDA1FF163B0F97EB1E902B18B3F3E45EFBCC78AC533A3BF52B91279C42553A06482D6")
|
||||
.add("id", "483fdacbefe0")
|
||||
.build();
|
||||
final Request request = new Request.Builder().url("https://shelly-8-eu.shelly.cloud/device/status")
|
||||
.post(requestBody)
|
||||
.build();
|
||||
final Response response = httpClient.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
// System.out.println(response.body().string());
|
||||
final Reader bodyReader = response.body().charStream();
|
||||
final Gson gson = new Gson();
|
||||
final JsonReader jsonReader = gson.newJsonReader(bodyReader);
|
||||
jsonReader.beginObject();
|
||||
int level = 0;
|
||||
int phase = 0;
|
||||
while (jsonReader.hasNext()) {
|
||||
final String name = jsonReader.nextName();
|
||||
if ("data".equals(name) && level == 0) {
|
||||
jsonReader.beginObject();
|
||||
level++;
|
||||
} else if ("device_status".equals(name) && level == 1) {
|
||||
jsonReader.beginObject();
|
||||
level++;
|
||||
} else if ("emeters".equals(name) && level == 2) {
|
||||
jsonReader.beginArray();
|
||||
jsonReader.beginObject();
|
||||
phase = 1;
|
||||
level++;
|
||||
} else if ("power".equals(name) && level == 3) {
|
||||
System.out.println("Phase: " + phase + " / Verbrauch: " + jsonReader.nextDouble());
|
||||
while (jsonReader.hasNext()) {
|
||||
jsonReader.nextName();
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
jsonReader.endObject();
|
||||
if (jsonReader.hasNext()) {
|
||||
phase++;
|
||||
jsonReader.beginObject();
|
||||
}
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
// if ("apower".equals(name)) {
|
||||
// System.out.println("- " + jsonReader.nextDouble());
|
||||
// } else {
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
34
src/main/java/info/peper/shelly/ReadShellyLocalMain.java
Normal file
34
src/main/java/info/peper/shelly/ReadShellyLocalMain.java
Normal file
@ -0,0 +1,34 @@
|
||||
package info.peper.shelly;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class ReadShellyLocalMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final OkHttpClient httpClient = new OkHttpClient();
|
||||
final Request request = new Request.Builder().url("http://photovoltaik/rpc/Switch.GetStatus?id=0").build();
|
||||
final Response response = httpClient.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
final Reader bodyReader = response.body().charStream();
|
||||
final Gson gson = new Gson();
|
||||
final JsonReader jsonReader = gson.newJsonReader(bodyReader);
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
final String name = jsonReader.nextName();
|
||||
if ("apower".equals(name)) {
|
||||
System.out.println(jsonReader.nextDouble());
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user