Comments (8)
What you want is KNX process communication. There is an example in the introduction repository here. This allows you to read and write datapoints. You can create the different datapoints of your weather station using either several StateDPs, or supply directly the DPTXlator instances of the DPTs you use for translating the KNX data. To listen to incoming changes, add a ProcessListener to the process communicator.
Whether you use routing or tunneling, it does not really make a difference. You only have to select your choice in the IP network link constructor via the service mode parameter. Some differences are that KNX routers often support only one active tunnel connection, in routing mode packets are not acknowledged (in tunneling mode they are).
You can easily try both and use what better fits your setup.
from calimero-core.
Thank you for the explanation.
Today I tried this code and it's working but only for rain because only that parameter is boolean true/false statement. Do you know how should I write the rest of the code for temperature (data type 9.001 °C), wind speed (data type 9.005 meter per second), brightness (data type 9.004 lux), morning/evening (data type 1.001 switch)? Where could I found that? This library supports these data type right?
package projFiles;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import tuwien.auto.calimero.DetachEvent;
import tuwien.auto.calimero.GroupAddress;
import tuwien.auto.calimero.KNXAddress;
import tuwien.auto.calimero.Priority;
import tuwien.auto.calimero.cemi.CEMILData;
import tuwien.auto.calimero.datapoint.Datapoint;
import tuwien.auto.calimero.dptxlator.DPT;
import tuwien.auto.calimero.exception.KNXException;
import tuwien.auto.calimero.exception.KNXTimeoutException;
import tuwien.auto.calimero.link.KNXLinkClosedException;
import tuwien.auto.calimero.link.KNXNetworkLink;
import tuwien.auto.calimero.link.KNXNetworkLinkIP;
import tuwien.auto.calimero.link.KNXNetworkMonitorIP;
import tuwien.auto.calimero.link.NetworkLinkListener;
import tuwien.auto.calimero.link.medium.KNXMediumSettings;
import tuwien.auto.calimero.link.medium.TPSettings;
import tuwien.auto.calimero.process.ProcessCommunicator;
import tuwien.auto.calimero.process.ProcessCommunicatorImpl;
import tuwien.auto.calimero.process.ProcessEvent;
import tuwien.auto.calimero.process.ProcessListener;
public class MainClass {
/**
* Address of your KNXnet/IP server. Replace the IP address as necessary.
*/
private static final String remoteHost = "192.168.1.220";
/**
* We will read a boolean from this KNX datapoint group address, replace the address string with
* one of yours. Make sure this datapoint exists, otherwise you will get a read timeout!
*/
private static final String group = "4/1/2";
public static void main(String[] args) {
// TODO Auto-generated method stub
KNXNetworkLink knxLink = null;
ProcessCommunicator pc = null;
try {
// Create our network link. See other constructors if this one assumes too many
// default settings.
knxLink = new KNXNetworkLinkIP(remoteHost, TPSettings.TP1);
// create a process communicator using that network link
pc = new ProcessCommunicatorImpl(knxLink);
System.out.println("read the group value from datapoint " + group);
// this is a blocking method to read a boolean from a KNX datapoint
final boolean value = pc.readBool(new GroupAddress(group));
System.out.println("value read from datapoint " + group + ": " + value);
pc.addProcessListener(new ProcessListener() {
@Override
public void groupWrite(ProcessEvent arg0) {
// TODO Auto-generated method stub
//The groupWrite() method of your handler will then be called on every received A_GroupWrite indication, with the received message as a parameter (wrapped in a ProcessEvent). Look at ProcessListenerEx for an example how to decode the payload.
System.out.println("groupWrite");
}
@Override
public void detached(DetachEvent arg0) {
// TODO Auto-generated method stub
System.out.println("detached");
}
});
Thread.sleep(10000);
}
catch (final KNXException e) {
System.out.println("Error reading KNX datapoint: " + e.getMessage());
}
catch (final InterruptedException e) {
System.out.println("Interrupted: " + e.getMessage());
}
finally {
// we don't need the process communicator anymore, detach it from the link
if (pc != null)
pc.detach();
// close the KNX link
if (knxLink != null)
knxLink.close();
}
}
}
The first image shows false because the sensor was dry and then I poured sensor with water and then it was written true.
from calimero-core.
DPT 9.x is the KNX 2-byte float. Use pc.readFloat(new GroupAddress(temperature), false)
and pc.readFloat(new GroupAddress(windspeed), false)
, where temperature
and windspeed
are the corresponding datapoints. This returns you the value as Java type float
.
Alternatively, if you want to have a datapoint value formatted as string with the unit of measurement appended, use something like
final Datapoint dp = new StateDP(new GroupAddress(temperature),
"Weather station temperature", 0, "9.001");
String s = pc.read(dp);
from calimero-core.
Thank you, I did it, can you explain how to catch telegrams from weather station through ProcessListener? I don't understand that part very well
For example, the program is running and then happens some changes and weather station sends telegrams automaticaly
from calimero-core.
You already added the process listener. I would suggest to replace ProcessListener
with ProcessListenerEx. This provides you with methods like asFloat
, so you can easily convert to, e.g., a Java floating point type.
As a start copy this in all your process listener methods (or create a method for it):
try {
System.out.println(LocalTime.now() +" " + svc + " " + e.getSourceAddr() + "->"
+ e.getDestination() + ": " + DataUnitBuilder.toHex(e.getASDU(), ""));
}
catch (final KNXFormatException | RuntimeException ex) {}
This prints you for every notification the KNX source/destination, and data of your weather station in hexadecimal format. It works for any datapoint (you basically created a very simple KNX group monitor).
In your case, a straightforward implementation for data formatting, because you know your DPTs, is the following (shown for the temperature datapoint; copy the following code into the try
block from above):
if (e.getDestination().equals(new GroupAddress(temperature))) {
final double v = asFloat(e, false);
System.out.println("Temperature changed to " + v);
}
Similar for your other datapoints.
HTH, Boris
from calimero-core.
An example of a simple group monitor I put here.
from calimero-core.
Thanks for explanation! It works! One more question, which protocol is used for sending telegrams in this library? UDP or TCP/IP?
from calimero-core.
KNXnet/IP uses UDP.
from calimero-core.
Related Issues (20)
- Does not work with tpuart ic HOT 24
- [Feature Request] Add support for security proxy
- Datapoint type discovery HOT 1
- DPT8 missing in README.md HOT 1
- Mangamementclient no basic restart anymore with v2.5? HOT 3
- [Feature Request] "protected" for some fields and methods of ManagementClientImpl HOT 6
- Warnings from Calimero HOT 13
- Receiving a GroupValueResponse with DPT 1.001 fails due to missing data in the asdu HOT 2
- DPT 251.600 format should be consistent across platforms and locales HOT 3
- readBool maxASDULen should be ‘1’ ?,now is ‘0’ HOT 1
- Android project runtime FATAL EXCEPTION. HOT 5
- GO Diagnostics: Improve selection of surrogate HOT 10
- DPT 10.001 is wrongly parsed when "no day" is present HOT 2
- Throws Exception when EventListener catch one HOT 2
- KNXNetworkLinkFT12: detect status, CEMI setting.... HOT 2
- Implement Transport Layer Connection-Oriented State Machine Style 3 HOT 2
- Throws `KNXTimeoutException` due to missing confirmation although the confirmation was received HOT 2
- Calimero GUI and KNX Virtual HOT 2
- Data Secure - Read Group Request management HOT 2
- Not able to connect to KNX USB RF module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from calimero-core.