Skip to content

Latest commit

 

History

History
91 lines (74 loc) · 3.04 KB

File metadata and controls

91 lines (74 loc) · 3.04 KB

jrelay Build Status##

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.

Rationale

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.

Features

  • 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.

Supported devices

RS232 relay RS232 relay USB relay USB relay USB relay

Maven

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>

Download

Click on to download it:

jrelay-0.1-repo.zip

Hello World

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