adjustmentsfor demo:: insert REST calls for osjs, pinMode, digital and analog write
This commit is contained in:
parent
c8c9900ae2
commit
8e927af9b6
@ -58,32 +58,96 @@ s4t_wamp_server.prototype.start = function(restPort, wamp_router_url){
|
||||
|
||||
//DEBUG Message
|
||||
console.log('POST::::'+req.originalUrl);
|
||||
var board = req.query.board
|
||||
var command = req.query.command
|
||||
|
||||
var board = req.query.board;
|
||||
var command = req.query.command;
|
||||
var pin = req.query.pin;
|
||||
var mode = req.query.mode;
|
||||
var value = req.query.value;
|
||||
|
||||
if(boards[board] != undefined){
|
||||
//DEBUG Message
|
||||
//
|
||||
console.log("ID exsist");
|
||||
|
||||
switch(board){
|
||||
case 'ssh':
|
||||
//random port for reverse service
|
||||
var port = randomIntInc(6000,7000);
|
||||
session.publish(topic_command, [board, command, port]);
|
||||
if(command == 'ssh'){
|
||||
//res.send("ssh -p "+port+" root@"+IPLocal);
|
||||
res.json(IPLocal+':'+port);
|
||||
}
|
||||
if(command == 'ideino'){
|
||||
break;
|
||||
|
||||
case 'ideino':
|
||||
var port = randomIntInc(6000,7000);
|
||||
session.publish(topic_command, [board, command, port]);
|
||||
//res.send("http://"+IPLocal+":"+port);
|
||||
res.json(IPLocal+':'+port);
|
||||
}
|
||||
if(command == 'osjs'){
|
||||
break;
|
||||
|
||||
case 'osjs':
|
||||
var port = randomIntInc(6000,7000);
|
||||
session.publish(topic_command, [board, command, port]);
|
||||
//res.send("http://"+IPLocal+":"+port);
|
||||
res.json(IPLocal+':'+port);
|
||||
break;
|
||||
|
||||
case 'mode':
|
||||
if(pin>=2 && pin<=13){
|
||||
if(mode === 'input' || mode ==='output'){
|
||||
session.publish(topic_command, [board, command, pin, mode]);
|
||||
res.json(pin+':'+mode);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
|
||||
//Analog Write
|
||||
case 'analog':
|
||||
if(pin>=2 && pin<=13){
|
||||
if(value<=0 && value <=1024){
|
||||
session.publish(topic_command, [board, command+'write', pin, value]);
|
||||
res.json(pin+':'+value);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
//Analog Write
|
||||
case 'digital':
|
||||
if(pin>=2 && pin<=13){
|
||||
if(value==0 || value==1){
|
||||
session.publish(topic_command, [board, command+'write', pin, value]);
|
||||
res.json(pin+':'+value);
|
||||
break;
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
res.json('null');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
res.send("Error: malformed REST ");
|
||||
//res.send("Error: malformed REST ");
|
||||
res.json('null');
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user