package com.ociweb.iot.project.lightblink;

import com.ociweb.iot.maker.CommandChannel;
import com.ociweb.iot.maker.DeviceRuntime;
import com.ociweb.iot.maker.PayloadReader;
import com.ociweb.iot.maker.PubSubListener;
import com.ociweb.iot.maker.StartupListener;

public class BlinkerBehavior implements StartupListener, PubSubListener {
 
    private static final String TOPIC = "light";
    private static final int PAUSE = 500;
	
	private CommandChannel blinkerChannel;
	
	public BlinkerBehavior(DeviceRuntime runtime) {
		blinkerChannel = runtime.newCommandChannel(); 
	}	
	
	@Override
	public void message(CharSequence topic, PayloadReader payload) {
		 int value = payload.readInt();
         blinkerChannel.digitalSetValueAndBlock(IoTApp.LED_CONNECTION, value, PAUSE);               
         blinkerChannel.openTopic(TOPIC).writeInt( 1==value ? 0 : 1 ).publish();
    }

	@Override
	public void startup() {
		blinkerChannel.subscribe(TOPIC, this);
		blinkerChannel.openTopic(TOPIC).writeInt( 1 ).publish();   
	}

}

@@ -1,8 +1,779 @@
+/**%0A * blinkerChannel is a CommandChannel created to transport data. %0A * Data is published to the channel, and it can also be accessed %0A * by playload.writeInt() to read from the channel%0A * %3Cp%3E%0A * The blinky light is achieved by alternate the value publish to%0A * the channel. The method shown below enable to turn on/off the %0A * LED as well as block the command channel for the duration of a %0A * blink%0A * digitalSetValueAndBlock(int connector, int value, long msDuration)%0A * @param  connector  the LED connect to the digital connector D5%0A * @param  value      1 is turn on the LED while 0 turn off the LED%0A * @param  msDuration how long the channel is blocked till it is available for next command%0A * @return      return true when the method operated successfully %0A */%0A%0A%0A
 package 

Add the Javadoc