This commit is contained in:
raluca-elena 2014-08-04 22:06:31 -07:00
Родитель b38f03bcb2
Коммит 099a6e5cb3
11 изменённых файлов: 106 добавлений и 102 удалений

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

@ -0,0 +1,42 @@
var baseurl = "http://10.0.0.3:8080";
var url = "10.0.0.3";
$.ajax({"url":baseurl + "/lsall"}).done(function (data) {
var things = JSON.parse(data)["10.0.0.3"];
console.log("THINGS: ", things);
for (var key in things) {
var pl =JSON.parse(things[key].payload);
if (things.hasOwnProperty(key)) {
console.log("key is ", key);
constructButton(key, Object.keys(pl.features));
}
}
function constructButton(thingId, features) {
console.log("thingId: ", thingId);
$('<button/>', {
text: "thing " + thingId + " has features :",
id: 'thing_' + thingId,
click: function () {
console.log("MUAHAHAH");
}
}).addClass("btn btn-success").appendTo("#myDiv");
for (var i in features)
$('<button/>', {
text: features[i],
id: 'feature_' + features[i]
}).addClass("btn btn-info").appendTo("#myDiv");
$('<button/>', {
text: "tagFeaturesForThing",
click: function(){window.location.href='http://10.0.0.5';},
id: 'tag_features' + thingId
}).addClass("btn btn-danger").appendTo("#myDiv");
$("#myDiv").append('<br/>');
}
});

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

@ -0,0 +1,19 @@
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="./superagent.js"></script>
<script src="directory.js"></script>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<div id="myDiv" class="btn-group btn-group-justified">
<!-- <button id = "led1" type="button" class="btn btn-default">Led1</button> -->
<!-- <button id = "led2" type="button" class="btn btn-default">Led2</button> -->
</div>
<body>
</body>
</html>

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

@ -1,6 +1,7 @@
const http = require("http")
const fs = require("fs")
const url = require("url")
const utf8 = require("utf8")
var config = JSON.parse(fs.readFileSync(process.argv[2]))
@ -23,7 +24,7 @@ function ok(response, message) {
"Content-Length": message.length
});
response.write(message);
console.log("ok", message, things);
//console.log("ok", message, things);
response.end();
}
@ -35,16 +36,14 @@ function putPing(uuid, remoteAddress, payload) {
}
var thing = network[uuid];
if (!thing) {
console.log("got no thing");
console.log("got no thing :(");
network[uuid] = thing = {};
console.log("network is ", network);
}
thing.expiryTime = Date.now();
thing.payload = payload;
console.log("PUTPING thing is ", thing);
console.log("PUTPING payload is ",payload.toString());
console.log("PUTPING things is ", things);
console.log("PUTPING network ", network);
thing.payload = payload.toString('utf8');
console.log("payload *************", payload);
console.log("network *************", network);
}
/** put json to /thing/stable-uuid
@ -55,15 +54,14 @@ function handlePing(uuid, request, response) {
if (!('content-length' in request.headers)) {
return fail(response, 500, "Missing content-length header");
}
console.log("HANDLEPING uuid", uuid);
var content_length = request.headers['content-length'] * 1
var buf = new Buffer(content_length);
var pos = 0;
request.on('data', function(chunk) {
chunk.copy(buf, pos);
pos += chunk.length;
console.log("i have data for uuid ", uuid, "data", chunk);
})
console.log("i have data for uuid ", uuid, "data", chunk.toString('utf8'));
})
request.on('end', function() {
var remoteAddress = request.connection.remoteAddress;
console.log("request.connection.remoteAddress", request.connection.remoteAddress)
@ -96,9 +94,10 @@ function handleGet(request, response) {
if (!thing)
return fail(response, 404, "No thing " + uuid + " in " + remoteAddress + " network");
console.log("THINGS IS :", things);
console.log("PAYLOAD IS :", thing.payload);
return ok(response, thing.payload);
} if(pathname =="/lsall"){
console.log("-----------lsAll----------");
return ok(response, JSON.stringify(things))
} else {
return fail(response, 404, pathname + " not found");
}
@ -107,18 +106,14 @@ function handleGet(request, response) {
function handlePut(request, response) {
var pathname = url.parse(request.url).pathname;
if (pathname.substr(0,7) == "/thing/") {
console.log("HANDLEPUT i am in a put request and i make a request at ", pathname);
return handlePing(pathname.substr(7), request, response);
}
response.write(pathname);
console.log("handlePut: pathname----", pathname, things);
response.end();
}
http.createServer(function(request, response) {
var pathname = url.parse(request.url).pathname;
console.log("my pathname is ----", pathname);
console.log(request.method, pathname);
if (request.method == "GET" || request.method == "HEAD") {
return handleGet(request, response);
} else if (request.method == "PUT") {

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

@ -29,6 +29,7 @@ function setup() {
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) {
if (err)
console.log("****************** I fail miserably to read url of my cam :(******************", err);

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

@ -1,8 +1,8 @@
var baseurl = "http://10.251.43.233:8080";
//var baseurl = "http://10.0.0.6:8080";
$.ajax({"url":baseurl + "/ls"}).done(function (data) {
//var baseurl = "http://10.251.43.233:8080";
var baseurl = "http://10.0.0.3:8080";
$.ajax({"url":baseurl + "/lsall"}).done(function (data) {
console.log("date primite pe ls ", data);
console.log("date primite pe lsall ", data);
var ls = JSON.parse(data);
ls.forEach(function (thingid) {
var url = baseurl + "/thing/" + thingid;

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

@ -7,7 +7,6 @@
<div id="myDiv" class="btn-group btn-group-justified">
<button id = "led1" type="button" class="btn btn-default">Led1</button>
<button id = "led2" type="button" class="btn btn-default">Led2</button>
<!--<button id = "changeState" type="button" class="btn btn-default">Change</button>-->
</div>
<script src="./superagent.js"></script>
@ -15,8 +14,16 @@
</script>
<script src="app.js">
</script>
<div>
<img id = "myPic" style="float:left;margin: 10px 10px;" src="http://localhost:8090/?action=stream" width="520" height="480" />
<div style="display: inline-flex;">
<div>
<img id = "myPic" style="float:left;margin: 10px 10px;" src="http://localhost:8090/?action=stream" width="520" height="480" />
</div>
<form id="speech" class="navbar-form navbar-left" action="http://localhost:3333" method="post">
<div class="form-group">
<input type="text" class="form-control" placeholder="write something">
</div>
<button type="submit" class="btn btn-danger">ToSpeech</button>
</form>
</div>
</body>
</html>

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

@ -1,60 +0,0 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.js"></script>
<script src="./superagent.js"></script>
<script src="./rot.js"></script>
<body>
<table id='tagstable' border=1px>
<tr>
<td>UUID</td>
<td>Feature</td>
<td>Tags</td>
</tr>
</table>
</body>
<script>
function writeTagTable() {
console.log('lol');
getFeatures(function(features) {
console.log('features:', features);
$.each(features, function(uuid, ufeatures) {
$.each(ufeatures, function(fname, finfo) {
var row = $('<tr>');
$('<td>').text(uuid).appendTo(row);
$('<td>').text(fname).appendTo(row);
var tagsSelector = $('<input style="width:300px"/>');
tagsSelector.appendTo(row);
tagsSelector.select2({tags:[],
tokenSeparators: [",", " "]});
tagsSelector.on("change", function(s2) {
console.log('added:', s2.added,
'removed:', s2.removed,
'all:', s2.val,
'uuid:', uuid,
'fname:', fname,
'finfo:', finfo);
});
$('#tagstable').append(row);
});
});
});
}
$(document).ready(function() {
init(writeTagTable);
});
</script>

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

@ -7,7 +7,8 @@
"features": {
"factory-name-for-led1-C00FF33": {"url": "localhost:1234"},
"useless-device-MQYOK7N1WA*#22": {"url": "localhost:7777"},
"raspberry-cam": {"url": "localhost:8090"}
"raspberry-cam": {"url": "localhost:8090"},
"speaker": {"url":"localhost:3333"}
}
}

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

@ -7,15 +7,12 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.js"></script>
<body>
<table id='tagstable' border=1px>
<tr>
<td>Feature</td>
<td>Tags</td>
</tr>
</table>
<table id='tagstable' border=1px>
<tr>
<td>Feature</td>
<td>Tags</td>
</tr>
</table>
</body>
<script>
@ -28,10 +25,10 @@
* Return: list of tags for this feature [led1]
*/
function findTags(feature, tags) {
var l = [];
$.each(tags, function(tag, fname) { if (fname === feature) l.push(tag); });
console.log("findTags:", l);
return l;
var l = [];
$.each(tags, function(tag, fname) { if (fname === feature) l.push(tag); });
console.log("findTags:", l);
return l;
}
function writeTagTable(features, tags) {
@ -53,7 +50,7 @@ function writeTagTable(features, tags) {
// trigger the 'change' event.
tagsSelector.val(findTags(fname, tags)).trigger("change");
tagsSelector.on("change", function(e) {
tagsSelector.on("change", function(e) {
console.log(e.added, e.removed);
if (e.added !== undefined) {
var newTag = e.added.text;

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

@ -143,7 +143,9 @@ function registerWithDirectoryServer() {
}
var uuid = getUUID();
var payload = JSON.stringify({"uuid":uuid, "localURL":url});
//var payload = JSON.stringify({"uuid":uuid, "localURL":url});
console.log("config.features are |0/ :", config.features);
var payload = JSON.stringify({"uuid":uuid, "localURL":url, "features": config.features});
var options = {
host: directoryUrl.hostname,
port: directoryUrl.port,
@ -155,7 +157,7 @@ function registerWithDirectoryServer() {
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
//res.setEncoding('utf8');
var ret = "";
res.on('data', function (chunk) {
ret += chunk;

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

@ -24,9 +24,9 @@ app.use(function (req, res, next) {
app.use(cors());
app.put("/", function(req, res, next) {
app.post("/", function(req, res, next) {
var text = req.text;
console.log("PUT /, text is : ", text);
console.log("POST /, text is : ", text);
require('child_process').spawn('node', ["textToSpeechServer.js", text]);
res.send("text processed is " + text);
});