var xbee = require('../lib/xbee-promise.js');

var onNext = true;
var nodeId = 'TEMP3';

console.log('Blinking LED on AD1 on module with ID: ', nodeId);

var interval = setInterval(function () {
    xbee.remoteCommand({
        command: "D1",
        commandParameter: [ onNext ? 5 : 4 ],
        destinationId: nodeId
    }).catch(function(e) {
        console.log("Command failed:", e);
        clearInterval(interval);
        xbee.close();
    });
    console.log(onNext ? 'ON' : 'OFF');

    onNext = !onNext;
}, 2000);


@@ -1,12 +1,242 @@
+/*jslint node:true */%0A%0A/*%0A * blink.js%0A * https://github.com/101100/xbee-promise%0A *%0A * Example that blinks a LED on AD1 on a remote module%0A *%0A * Copyright (c) 2014 Jason Heard%0A * Licensed under the MIT license.%0A */%0A%0A%22use strict%22;%0A%0A
 var xbee
  = r
@@ -231,16 +231,23 @@
 var xbee
+Promise
  = requi
@@ -273,24 +273,217 @@
 mise.js');%0A%0A
+var xbee = xbeePromise(%7B%0A    serialport: '/dev/ttyUSB0',%0A    serialportOptions: %7B%0A        baudrate: 57600%0A    %7D,%0A    // turn on debugging to see what the library is doing%0A    debug: false%0A%7D);%0A%0A
 var onNext =
@@ -506,15 +506,15 @@
 d = 
-'
+%22
 TEMP3
-'
+%22
 ;%0A%0Ac
@@ -581,48 +581,108 @@
 );%0A%0A
-var interval = setInterval(function () %7B
+function toggleLed() %7B%0A    process.stdout.write(%22Turning LED %22 + (onNext ? %22ON.%22 : %22OFF%22) + %22...%22);%0A
 %0A   
@@ -813,13 +813,12 @@
  %7D).
-catch
+then
 (fun
@@ -826,10 +826,23 @@
 tion
+ toggleSuccess
 (
-e
 ) %7B%0A
@@ -866,97 +866,179 @@
 og(%22
-Command failed:%22, e);%0A        clearInterval(interval);%0A        xbee.close();%0A    %7D);%0A
+ success.%22);%0A        onNext = !onNext;%0A%0A        // schedule next toggle in 2 seconds%0A        setTimeout(toggleLed, 2000);%0A    %7D).catch(function toggleFailure(e) %7B%0A   
     
+ 
 cons
@@ -1049,62 +1049,109 @@
 log(
-onNext ? 'ON' : 'OFF'
+%22 command failed:%5Cn%22, e);%0A        xbee.close(
 );%0A
-%0A
     
-onNext = !onNext;%0A%7D, 2000
+%7D);%0A%7D%0A%0A// do initial toggle%0AsetImmediate(toggleLed
 );%0A
-%0A

Fix blink.js example