diff --git a/directory_server/register.js b/directory_server/register.js index a4669c6..d8e2788 100644 --- a/directory_server/register.js +++ b/directory_server/register.js @@ -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) { diff --git a/frontend/lib/rot.js b/frontend/lib/rot.js index 648eaee..a72944b 100644 --- a/frontend/lib/rot.js +++ b/frontend/lib/rot.js @@ -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 + " :("); diff --git a/frontend/lib/rotv2.js b/frontend/lib/rotv2.js old mode 100644 new mode 100755 diff --git a/slave/configRemoteApp.json b/slave/configRemoteApp.json index 46329f0..bc0c1f2 100755 --- a/slave/configRemoteApp.json +++ b/slave/configRemoteApp.json @@ -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"} } } diff --git a/slave/fakeDevices/fakeADC.js b/slave/fakeDevices/fakeADC.js index df2b5ef..df2eb35 100644 --- a/slave/fakeDevices/fakeADC.js +++ b/slave/fakeDevices/fakeADC.js @@ -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);