Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.87 KB

README.md

File metadata and controls

52 lines (40 loc) · 1.87 KB

wattsup-java-sdk

What is it ?

A Java application to communicate with the WattsUp? to get the available power measurements. The communication is based on the protocol description available at https://www.wattsupmeters.com/secure/downloads/CommunicationsProtocol090824.pdf

Usage

Here is a class that connects to the power meter during three minutes and print the measurements data on output console.

public final class WattsUpTest
{	    
    /**
     * Creates an {@link WattsUp} for monitoring during three minutes.
     * 
     * @param args
     *            The reference to the arguments.
     * @throws IOException
     *             If the power meter is not connected.
     */
    public static void main(String[] args) throws IOException
    {
	final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
	final WattsUp meter = new WattsUp(new WattsUpConfig().withPort(args[0]).scheduleDuration(3 * 60));

	meter.registerListener(new WattsUpDataAvailableListener()
	{
	    @Override
	    public void processDataAvailable(final WattsUpDataAvailableEvent event)
	    {
	        WattsUpPacket[] values = event.getValue();
	        System.out.printf("[%s] %s\n", format.format(new Date()), Arrays.toString(values));
	    }
	});
	meter.connect();
    }
}

Running:

java -cp lib/nrjavaserial-3.8.8.jar wattsup.jsdk.example.test.WattsUpTest /dev/ttyUSB0

Dependencies

This project uses the nrjavaserial and Java 7.

Bitdeli Badge