package com.ociweb.grove;


import static com.ociweb.iot.grove.GroveTwig.*;

import com.ociweb.iot.maker.Hardware;
import com.ociweb.iot.maker.CommandChannel;
import com.ociweb.iot.maker.DeviceRuntime;
import com.ociweb.iot.maker.IoTSetup;
import static com.ociweb.iot.maker.Port.*;

public class IoTApp implements IoTSetup
{
    ///////////////////////
    //Connection constants 
    ///////////////////////
    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in
      
    //private static final Port BUTTON_PORT = D3;
	//private static final Port LED_PORT    = D4;
    //private static final Port RELAY_PORT  = D7;
    //private static final Port LIGHT_SENSOR_PORT= A2;

    @Override
    public void declareConnections(Hardware c) {
        ////////////////////////////
        //Connection specifications
        ///////////////////////////
        
        // // specify each of the connections on the harware, eg which component is plugged into which connection.        
              
        //c.connect(Button, BUTTON_PORT); 
        //c.connect(Relay, RELAY_PORT);         
        //c.connect(LightSensor, LIGHT_SENSOR_PORT); 
        //c.connect(LED, LED_PORT);        
        //c.useI2C();
        
    }


    @Override
    public void declareBehavior(DeviceRuntime runtime) {
        //////////////////////////////
        //Specify the desired behavior
        //////////////////////////////
        
        //  //Use lambdas or classes and add listeners to the runtime object
        //  //CommandChannels are created to send outgoing events to the hardware
        //  //CommandChannels must never be shared between two lambdas or classes.
        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior
        
        
        //        final CommandChannel channel1 = runtime.newCommandChannel();
        //        //this digital listener will get all the button press and un-press events 
        //        runtime.addDigitalListener((connection, time, value)->{ 
        //            
        //            //connection could be checked but unnecessary since we only have 1 digital source
        //            
        //            if (channel1.digitalSetValue(RELAY_PORT, value)) {
        //                //keep the relay on or off for 1 second before doing next command
        //                channel1.digitalBlock(RELAY_PORT, 1000); 
        //            }
        //        });
    }
        
  
}

@@ -20,16 +20,46 @@
 grove;%0A%0A
+import com.ociweb.iot.maker.*;
 %0Aimport 
@@ -103,674 +103,194 @@
 .*;%0A
-%0Aimport com.ociweb.iot.maker.Hardware;%0Aimport com.ociweb.iot.maker.CommandChannel;%0Aimport com.ociweb.iot.maker.DeviceRuntime;%0Aimport com.ociweb.iot.maker.IoTSetup;%0Aimport static com.ociweb.iot.maker.Port.*;%0A%0Apublic class IoTApp implements IoTSetup%0A%7B%0A    ///////////////////////%0A    //Connection constants %0A    ///////////////////////%0A    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in%0A      %0A    //private static final Port BUTTON_PORT = D3;%0A%09//private static final Port LED_PORT    = D4;%0A    //private static final Port RELAY_PORT  = D7;%0A    //private static final Port LIGHT_SENSOR_PORT= A2;%0A
+import static com.ociweb.iot.maker.Port.*;%0A%0Apublic class IoTApp implements IoTSetup%0A%7B%0A    private static final Port BUTTON_PORT = D3;%0A    private static final Port RELAY_PORT  = D7;%0A    
 %0A   
@@ -352,275 +352,22 @@
 c) %7B
-%0A
      
-   ////////////////////////////%0A        //Connection specifications%0A        ///////////////////////////%0A        %0A        // // specify each of the connections on the harware, eg which component is plugged into which connection.        %0A              %0A        //
+%0A        
 c.co
@@ -395,34 +395,32 @@
 PORT); %0A        
-//
 c.connect(Relay,
@@ -446,145 +446,15 @@
    %0A
-        //c.connect(LightSensor, LIGHT_SENSOR_PORT); %0A        //c.connect(LED, LED_PORT);        %0A        //c.useI2C();%0A        %0A
     %7D%0A%0A
-%0A
     
@@ -528,670 +528,87 @@
     
-    //////////////////////////////%0A        //Specify the desired behavior%0A        //////////////////////////////%0A        %0A        //  //Use lambdas or classes and add listeners to the runtime object%0A        //  //CommandChannels are created to send outgoing events to the hardware%0A        //  //CommandChannels must never be shared between two lambdas or classes.%0A        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior%0A        %0A        %0A        //        final CommandChannel channel1 = runtime.newCommandChannel();%0A        //        //this digital listener will get all the button press and un-press events %0A        //
+%09final CommandChannel channel1 = runtime.newCommandChannel(DYNAMIC_MESSAGING);%0A
     
@@ -639,16 +639,22 @@
 stener((
+port, 
 connecti
@@ -686,382 +686,64 @@
     
-//            %0A        //            //connection could be checked but unnecessary since we only have 1 digital source%0A        //            %0A        //            if (channel1.digitalSetValue(RELAY_PORT, value)) %7B%0A        //                //keep the relay on or off for 1 second before doing next command%0A        //                channel1.digitalBlock(RELAY_PORT, 10
+%09channel1.setValueAndBlock(RELAY_PORT, value == 1, 5
 00);
- 
 %0A   
@@ -751,62 +751,16 @@
     
-//            %7D%0A        //        %7D);%0A    %7D%0A        %0A  
+%7D);%0A    %7D
 %0A%7D%0A

Create IoTApp.java