This commit is contained in:
raluca-elena 2014-08-07 16:33:19 -07:00
Родитель 2d7ee8dc61
Коммит 85355580e6
2 изменённых файлов: 11 добавлений и 43 удалений

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

@ -1,15 +1,16 @@
//working with predefined tags led1 and led2
//var tags = ["led1", "led2"];
//tagging another feature to see if setTag works
function app(){
console.log("in app()");
queryTags(['led1', 'led2'], function(tags, err) {
console.log("-----in app------");
//test api query tags
queryTags(['led1', 'led2'], function(tags, err) {
listExistingTags(tags, setup);
});
});
};
function listExistingTags(links, cb){
console.log("LINKS is ---------: ", links);
console.log("--------existing links ---------: ", links);
for (var key in links) {
if (links[key] !== undefined)
$('<a>',{
@ -27,15 +28,13 @@ function setup() {
//test/set a new tag for raspberry-cam and use it as stream source
setTag("uuid1", "raspberry-cam", 'cam', function(data) {
console.log("QQQQQQQQQQ AAAAAAAAAAAAA just set a tag to the cam ...you should have an entry in /tmp/tags", data);
console.log("just set a tag to the cam ...you should have an entry in /tmp/tags", data);
});
readTag('cam', function(data, err) {
if (err)
console.log("****************** I fail miserably to read url of my cam :(******************", err);
console.log("**** |o/ ****************************data is ", data);
console.log("-----data read tag 'cam' |o/ ------------------------------", data);
var url = "http://" + data;
console.log("APP url for camera ------------", url);
console.log("----------------------------app url for camera ------------", url);
loadImage(url);
});
var pushMe = $('<button/>',
@ -60,8 +59,8 @@ function setup() {
});
//some test calls that will be removes as soon as this app is finished
readTag('led1', function(data, err){console.log("read state of led1: ", data);});
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");
@ -81,11 +80,8 @@ function forEach(obj, cb) {
}
function readTags(tags, cb) {
console.log("I am in readTags tags: ------------------------", tags);
var readValues = {};
console.log("TAGS ARE ", tags);
forEach(tags, function(tag) {
console.log("tag: ", tag);
readTag(tag, function(data, err) {
readValues[tag] = data;
if (err)

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

@ -48,8 +48,6 @@ function init(cb) {
function queryTags(tags, cb) {
// ["tag1", "tag2"], cb (resp, err)); where resp: {"tag1": ?, "tag2": ?}
var resp = {};
console.log("I AM IN QUERY TAGS IN ROT");
console.log("allTags is ----", allTags);
for (var i = 0; i < tags.length; i++) {
resp[tags[i]] = allTags[tags[i]];
}
@ -58,8 +56,6 @@ function queryTags(tags, cb) {
function readTag(tag, cb) {
var tagData = allTags[tag];
console.log("allTags is ----------", allTags);
console.log("tag data is ---------------",tagData);
if (tagData === undefined) {
cb(undefined, "ROT No such tag: " + tag + " :(");
} else if (tagData === undefined) {
@ -72,8 +68,6 @@ function readTag(tag, cb) {
function writeTag(tag, data, cb) {
var tagData = allTags[tag];
console.log("------------- WRITE TAG ------Write tag tagData[tag] -------------", tagData);
console.log("------------- WRITE TAG -------data is--------", data);
if (tagData === undefined) {
cb(undefined, "No such tag: " + tag + " :(");
} else if (tagData === undefined) {
@ -107,13 +101,11 @@ function getAllThings(uuids, cb) {
errors.push(err);
} else {
var thing = JSON.parse(res.text);
console.log("Got thing: ", thing, " for uuid: ", uuid);
things[uuid] = thing;
}
done ++;
if (done === uuids.length) {
cb(errors, things);
console.log("THINGS are : ", things);
}
});
})();
@ -128,7 +120,6 @@ function getAllTags(things, cb) {
for (var uuid in things) {
(function(uuid) {
var thing = things[uuid];
console.log("ROT IN GETALLTAGS A thing:------------------", thing);
superagent.get(thing['localURL'] + "/tags/", function(err, res) {
console.log("--> getAllTags: err: ", err);
if (err) {
@ -142,17 +133,10 @@ function getAllTags(things, cb) {
// merge tag lists
for (var tagName in tagsResp) {
//var feature = tagsResp[tagName];
console.log("tagName -------", tagName);
console.log("tagsResp[tagName]------------",tagsResp[tagName]);
if (JSON.parse(tagsResp[tagName]).url !== undefined) {
//tags[tagName] = tagsResp[tagName];
console.log("JSON.parse(tagsResp[tagName]).url-------------", JSON.parse(tagsResp[tagName]).url);
tags[tagName] = JSON.parse(tagsResp[tagName]).url;
}
if (JSON.parse(tagsResp[tagName]).val !== undefined) {
console.log("JSON.parse(tagsResp[tagName]).val------------", JSON.parse(tagsResp[tagName]).val);
//tags[tagName] = tagsResp[tagName];
tags[tagName] = JSON.parse(tagsResp[tagName]).val;
}
}
@ -172,8 +156,6 @@ function getAllFeatures(things, cb) {
for (var uuid in things) {
(function(uuid) {
var thing = things[uuid];
console.log("ROT A THING LOOKS LIKE :", thing);
console.log("thing[localURL]"+ thing['localURL'] +"/features/");
superagent.get(thing['localURL'] + "/features/", function(err, res) {
console.log("--> getAllFeatures: err: ", err, " res.text: ", res.text);
if (err) {
@ -182,7 +164,6 @@ function getAllFeatures(things, cb) {
errors.push(err);
} else {
var featuresResp = JSON.parse(res.text);
console.log("************************ Got featuresResp: ", featuresResp, " for thing: ", thing, "uuid:", uuid);
features[uuid] = JSON.stringify(featuresResp);
}
done ++;
@ -198,12 +179,7 @@ function getFeatures(cb) {
}
function setTag(uuid, feature, tag, cb) {
console.log("----------------------SET TAG_____________________")
console.log("in setTag(uuid:", uuid, ", feature:", feature, ", tag:", tag, ")");
console.log("allFeatures[uuid]", allFeatures[uuid]);
console.log("allFeatures[uuid]~~~~~~~~~~~~~~~~~~~~~~", JSON.parse(allFeatures[uuid])[feature]);
var data = {"url":JSON.parse(allFeatures[uuid])[feature].url, "feature":feature};
//console.log("allFeatures[uuid][feature] is-------------------------- ", allFeatures[uuid][feature]);
if (allFeatures[uuid] === undefined) {
cb("No such uuid: " + uuid + " :( in allFeatures:" + allFeatures);
} else if (JSON.parse(allFeatures[uuid])[feature] === undefined) {
@ -212,14 +188,10 @@ function setTag(uuid, feature, tag, cb) {
cb("Tag already used: " + tag + " :(");
} else {
var url = allThings[uuid].localURL + "/tags/" + tag;
console.log("in SET TAG PUT(url)***************************", url);
superagent.put(url)
.send(data)
.end(function(res){
allTags[tag] = JSON.parse(allFeatures[uuid])[feature].url;
console.log("AAAAAAA-------------AllTags", allTags);
console.log("TAG IS ----", tag, "allTags[tag]", allTags[tag]);
if (res.ok) {
cb();
} else {
@ -229,7 +201,7 @@ function setTag(uuid, feature, tag, cb) {
}
}
// TODO:
// TODO:implementation & testing as not sure if we want to expose it
function deleteTag(tag, cb) {
if (allTags[tag] == undefined) {
cb("No such tag: " + tag + " :(");