This commit is contained in:
raluca-elena 2014-08-14 18:18:44 -07:00
Родитель fe4083a424
Коммит 661a59a74e
5 изменённых файлов: 23 добавлений и 34 удалений

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

@ -1,5 +1,8 @@
var baseurl = "http://10.0.0.3:8080";
var url = "10.0.0.3";
//var baseurl = "http://10.0.0.3:8080";
//var url = "10.0.0.3";
var baseurl = "http://10.251.38.229:8080";
var url = "10.251.38.229";
$.ajax({"url":baseurl + "/ls"}).done(function (data) {
var data = JSON.parse(data);
if (Object.keys(data).length === 0) {

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

@ -5,7 +5,6 @@ if (typeof superagent === 'undefined') {
}
var baseurl = "http://10.0.0.3:8080";
var allUuids = [];
var allThings = {}; // { 'uuid1dc65c13': { uuid: 'uuid1dc65c13', localURL: 'http://slave:80' }}
var allTags = {};
@ -20,6 +19,11 @@ function isValidURL(url){
}
}
/*
= get my data => GET /ls on directory => [data]
= for each uuid => GET /thing/uuid/ => info registeded by each device/slave. {"uuid":uuid, "localURL": slave-rest-endpoint}
= for each uuid => GET /tags/. First time, no tags defined (likely): brand new device.
*/
function init(cb) {
superagent.get(baseurl + "/ls", function(err, res) {
console.log("--------------------- ROT init ------------------");
@ -34,7 +38,6 @@ function init(cb) {
getAllThings(uuids, function(err, things) {
allThings = things;
console.log("ROT allThings: ", allThings);
getAllFeatures(things, function(err, features) {
allFeatures = features;
console.log("ROT allFeatures: ", allFeatures);
@ -46,12 +49,6 @@ function init(cb) {
});
});
});
/*
= get my data => GET /ls on directory => [data]
= for each uuid => GET /thing/uuid/ => info registeded by each device/slave. {"uuid":uuid, "localURL": slave-rest-endpoint}
= for each uuid => GET /tags/. First time, no tags defined (likely): brand new device.
*/
}
function queryTags(tags, cb) {
@ -62,7 +59,7 @@ function queryTags(tags, cb) {
}
cb(resp); // no error
}
//this works only for http requests not free tags
function readTag(tag, cb) {
var tagData = allTags[tag];
console.log("ROT READ TAG--", tagData);
@ -82,7 +79,6 @@ function readTag(tag, cb) {
}
}
//this works only for http requests not for free tags
function writeTag(tag, data, cb) {
var tagData = allTags[tag];
console.log("IN WRITE TAG and tagData is ", tagData);
@ -91,9 +87,7 @@ function writeTag(tag, data, cb) {
} else if (tagData === undefined) {
cb(undefined, "No url for tag: " + tag + " :(");
} else if (isValidURL(tagData)){
//superagent.post("http://" + tagData)
console.log("valid tag is:", tagData)
//var url = "http://" + tagData;
superagent.put(tagData)
.send(data)
.end(function(res){
@ -106,7 +100,6 @@ function writeTag(tag, data, cb) {
}
function getAllThings(uuids, cb) {
console.log("------------------ROT GET ALL THINGS-------------------");
var things = {};
var errors = undefined;
var done = 0;
@ -148,18 +141,16 @@ function getAllTags(things, cb) {
errors.push(err);
} else {
var tagsResp = JSON.parse(res.text);
console.log("Got tagsResp: ", tagsResp, " for thing: ", thing);
// merge tag lists
for (var tagName in tagsResp) {
if (JSON.parse(tagsResp[tagName]).url !== undefined) {
tags[tagName] = JSON.parse(tagsResp[tagName]).url;
}
if (JSON.parse(tagsResp[tagName]).val !== undefined) {
tags[tagName] = JSON.parse(tagsResp[tagName]).val;
}
}
for (var tagName in tagsResp) {
if (JSON.parse(tagsResp[tagName]).url !== undefined) {
tags[tagName] = JSON.parse(tagsResp[tagName]).url;
}
if (JSON.parse(tagsResp[tagName]).val !== undefined) {
tags[tagName] = JSON.parse(tagsResp[tagName]).val;
}
}
}
done ++;
if (done === Object.keys(things).length)
@ -222,7 +213,6 @@ function setTag(uuid, feature, tag, cb) {
}
}
// 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 + " :(");

0
frontend/lib/rotv2.js Normal file → Executable file
Просмотреть файл

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

@ -1,5 +1,5 @@
{
"directoryServer": "http://10.0.0.3:8080",
"directoryServer": "http://10.251.38.229:8080",
"tagFile":"/tmp/tags.json",
"port":3000,
"proxyport":3000,
@ -12,6 +12,7 @@
"motion-sensor": {"url": "http://10.0.0.5:1111"},
"speaker": {"url":"http://10.0.0.5:3333"},
"buzzer/relay":{"url":"http://10.0.0.5:8888"},
"photocell":{"url":"http://10.0.0.5:4444"}
"photocell":{"url":"http://10.0.0.5:4444"},
"dummy":{"url":"http://10.251.38.229:9000"}
}
}

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

@ -9,11 +9,6 @@ function generate(){
console.log("random value is", x);
return x;
}
var argv = process.argv;
var port = argv.split(" ");
port.shift();
port.shift();
var app = express();
//handle post/put
@ -47,4 +42,4 @@ app.put(/^\/tags\/[A-z:.-]+$/, function(req, res, next) {
res.send("OK");
});
})
app.listen(6666);
app.listen(9000);