refactored apps with new vers of rot

This commit is contained in:
raluca-elena 2014-08-15 16:05:26 -07:00
Родитель e44ca96aa7
Коммит d305b15b6f
4 изменённых файлов: 44 добавлений и 75 удалений

Просмотреть файл

@ -6,7 +6,7 @@
*/
function app(){
console.log("-----in app------");
queryTags(['cam', 'motion', 'sound', 'openButton'], function(tags, err) {
ROT.queryTags(['cam', 'motion', 'sound', 'openButton'], function(tags, err) {
console.log("query tags response is: ", tags);
setInterval(monitorDoor,3000);
//monitorDoor();
@ -25,14 +25,14 @@ function app(){
function monitorDoor(){
console.log("-----in monitor door-----");
readTag('motion', function(data){
ROT.readTag('motion', function(data){
console.log("data form motion sensor is", data);
if (data === "1"){
console.log("got something at the door");
readTag('cam', function(data){
ROT.readTag('cam', function(data) {
console.log("camera gives me this data--", data);
$('#myPic').attr('src', data);
writeTag('sound', 'Leprecaun at the door!', function(resp){
ROT.writeTag('sound', 'Leprecaun at the door!', function(resp){
console.log("got this response --", resp);
});
})
@ -42,4 +42,4 @@ function monitorDoor(){
});
}
init(app);
ROT.init(app);

Просмотреть файл

@ -5,13 +5,13 @@
*/
function app(){
queryTags(['light', 'buzzer'], function(tags, err) {
ROT.queryTags(['light', 'buzzer'], function(tags, err) {
setInterval(monitorGarageDoor,7000);
var pushMe = $('<button/>',{
id:"pushMe",
text: 'CloseDoor',
click: function () {
writeTag("buzzer", "", function(data){
ROT.writeTag("buzzer", "", function(data){
console.log("wrote data to buzzer ", data);});
change();
}
@ -29,12 +29,13 @@ function change(text) {
}
if (elem.innerText == "CloseDoor") {
elem.innerText = "OpenDoor";
} else {
elem.innerText = "CloseDoor";
}
else elem.innerText = "CloseDoor";
}
function monitorGarageDoor() {
readTag('light', function(data){
ROT.readTag('light', function(data){
if (parseInt(data) > 900){
change("CloseDoor");
alert("GARAGE OPEN!");

Просмотреть файл

@ -3,9 +3,8 @@
function app(){
console.log("-----in app------");
//test api query tags
queryTags(['led1', 'led2'], function(tags, err) {
listExistingTags(tags, setup);
ROT.queryTags(['led1', 'led2'], function(tags, err) {
listExistingTags(tags, setup);
});
};
@ -14,34 +13,29 @@ function listExistingTags(links, cb){
for (var key in links) {
if (links[key] !== undefined)
$('<a>',{
text: " " +"http://" + links[key],
text: " " + links[key],
title: key,
href: "http://" + links[key]
href: links[key]
}).appendTo('#'+ key);
}
cb(links);
}
function setup() {
//- ROT.readTag("tag", function cb(resp, err) { ... } ) => resp: WHATEVER THE URLS OF THAT TAG RETURNS
//- ROT.writeTag("tag", data, cb(resp, err) { ... } ) => data: whatever data you want, resp: tag will respond whatever it wants
//test/set a new tag for raspberry-cam and use it as stream source
setTag("uuid1", "raspberry-cam", 'cam', function(data) {
ROT.setTag("uuid1", "raspberry-cam", 'cam', function(data) {
console.log("just set a tag to the cam ...you should have an entry in /tmp/tags", data);
});
readTag('cam', function(data, err) {
ROT.readTag('cam', function(data, err) {
console.log("-----data read tag 'cam' |o/ ------------------------------", data);
var url = "http://" + data;
console.log("----------------------------app url for camera ------------", url);
loadImage(url);
loadImage(data);
});
var pushMe = $('<button/>',
{
text: 'ChangeState',
click: function () { console.log('hi');
readTag("led1", function(state) {
click: function () {
console.log('hi');
ROT.readTag("led1", function(state) {
console.log("state of led1 in readTAG is ", state);
if (state === "on") {
writeTag("led1", "off", function(){console.log("LED1 OFF");});
@ -50,19 +44,13 @@ function setup() {
}
});
readTag("led2", function(state) {
ROT.readTag("led2", function(state) {
if (state === "on") {
writeTag("led2", "off", function(){console.log("LED2 OFF");});
ROT.writeTag("led2", "off", function(){console.log("LED2 OFF");});
} else {
writeTag("led2", "on", function(){console.log("LED2 ON");});
ROT.writeTag("led2", "on", function(){console.log("LED2 ON");});
}
});
//some test calls that will be removes as soon as this app is finished
readTags(['led1', 'led2'], function(tags){console.log("tags are", tags);});
//test if query tags works
queryTags(['led1'], function(data){console.log("queryTags ",data);})
}}).addClass("btn btn-success");
$("#myDiv").append(pushMe);
}
@ -79,17 +67,4 @@ function forEach(obj, cb) {
}
}
function readTags(tags, cb) {
var readValues = {};
forEach(tags, function(tag) {
readTag(tag, function(data, err) {
readValues[tag] = data;
if (err)
console.log("Error from readTag: ", err);
if (Object.keys(readValues).length === Object.keys(tags).length)
cb(readValues);
});
});
}
init(app);
ROT.init(app);

Просмотреть файл

@ -1,7 +1,6 @@
function app(){
console.log("in app()");
queryTags(['led1'], function(tags, err) {
ROT.queryTags(['led1'], function(tags, err) {
console.log("APP tags are", tags);
listExistingTags(tags, setup);
});
@ -12,42 +11,36 @@ function listExistingTags(links, cb){
for (var key in links) {
if (links[key] !== undefined)
$('<a>',{
text: " " +"http://" + links[key],
text: " " + links[key],
title: key,
href: "http://" + links[key]
href: links[key]
}).appendTo('#'+ key);
}
cb(links);
}
function setup() {
//- ROT.readTag("tag", function cb(resp, err) { ... } ) => resp: WHATEVER THE URLS OF THAT TAG RETURNS
//- ROT.writeTag("tag", data, cb(resp, err) { ... } ) => data: whatever data you want, resp: tag will respond whatever it wants
//I set a new tag for raspberry-cam and use it as stream source
readTag('led1', function(data, err) {
ROT.readTag('led1', function(data, err) {
if (err)
console.log("****************** I fail miserably to read url of my led :(******************", err);
console.log("**** |o/ **************************** data is ", data);
var url = "http://" + data;
var url = data;
})
var pushMe = $('<button/>',
{
text: 'ChangeState',
click: function () { console.log('hi');
readTag("led1", function(state) {
console.log("STATE of led1 in readTAG is ", state);
if (state === "on") {
console.log("---------------i am in state is on");
writeTag("led1", "off", function(err){console.log("LED1 OFF-----", err);});
} else {
writeTag("led1", "on", function(err){console.log("LED1 ON----", err); });
}
});
readTag('led1', function(data, err){console.log("read state of led1: ", data);});
var pushMe = $('<button/>', {
text: 'ChangeState',
click: function () { console.log('hi');
ROT.readTag("led1", function(state) {
console.log("STATE of led1 in readTAG is ", state);
if (state === "on") {
console.log("---------------i am in state is on");
ROT.writeTag("led1", "off", function(err){console.log("LED1 OFF-----", err);});
} else {
ROT.writeTag("led1", "on", function(err){console.log("LED1 ON----", err); });
}
});
ROT.readTag('led1', function(data, err){console.log("read state of led1: ", data);});
}}).addClass("btn btn-success");
}}).addClass("btn btn-success");
$("#myDiv").append(pushMe);
}
@ -57,4 +50,4 @@ function forEach(obj, cb) {
}
}
init(app);
ROT.init(app);