This library allows you to use your relay connected to computer directly from Java. It's designed to abstract commonly used relay's drivers and has very simple API.
Today we have a huge amount of various relay on the market with cardinal differences in hardware and driver's part, that often used as a switch for the home devices. This way we may use relay to control almost every device in our home and jrelay API was created to remove the burden of situations where you have to rewrite your code because of relay replacing, but instead you can simply switch the driver class to different one.
- Simple, thread-safe and non-blocking API,
- No additional software required,
- Supports multiple platforms (Windows, Linux, Mac OS, etc) and various architectures,
- It is available as Maven dependency or standalone ZIP binary (with all dependencies included),
- Multiple relay drivers are supported.
The latest stable version is available in EasySmartHouse github repo:
Add repository:
<repository>
<id>jrelay-mvn-repo</id>
<url>https://raw.github.com/EasySmartHouse/jrelay/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
Add core dependency:
<dependency>
<groupId>com.github.jrelay</groupId>
<artifactId>jrelay-core</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
Add desired driver:
<dependency>
<groupId>com.github.jrelay</groupId>
<artifactId>driver-usbhid</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jrelay</groupId>
<artifactId>driver-jssc</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
Click on to download it:
Code below will just open and then close a relay after 1 second:
public class HelloWorld {
static {
// set all available drivers
Relay.setDrivers(UsbHidRelayDriver.class, JsscRelayDriver.class);
}
public static void main(String[] args) throws Exception{
//get all available relays
Relay relay = Relay.getDefault();
//open relay
relay.open();
//wait 1 second
Thread.sleep(1000l);
//relay close
relay.close();
}
}
This example is available here