Added Power Controller API (frist draft)
This commit is contained in:
parent
167e7f2cee
commit
630b084b17
3 changed files with 27 additions and 21 deletions
|
@ -56,10 +56,10 @@ desc: This is the main file for the web-based RaspiControl.
|
|||
$("#t" + item.id + "min").html(Number(item.min).toFixed(2) + " °C")
|
||||
$("#t" + item.id + "max").html(Number(item.max).toFixed(2) + " °C")
|
||||
$("#t" + item.id + "avg").html(Number(item.avg).toFixed(2) + " °C")
|
||||
var ts = new Date(item.tsmin);
|
||||
var ts = new Date(item.tsmin*1000);
|
||||
var month = ts.getMonth() + 1;
|
||||
$("#t" + item.id + "mindat").html(twoDigits(ts.getDate()) + "." + twoDigits(month) + "." + ts.getFullYear() + " " + twoDigits(ts.getHours()) + ":" + twoDigits(ts.getMinutes()));
|
||||
ts = new Date(item.tsmax);
|
||||
ts = new Date(item.tsmax*1000);
|
||||
month = ts.getMonth() + 1;
|
||||
$("#t" + item.id + "maxdat").html(twoDigits(ts.getDate()) + "." + twoDigits(month) + "." + twoDigits(ts.getFullYear()) + " " + twoDigits(ts.getHours()) + ":" + twoDigits(ts.getMinutes()));
|
||||
|
||||
|
@ -73,9 +73,9 @@ desc: This is the main file for the web-based RaspiControl.
|
|||
// * chan: Wireless channel of the switch (1-4)
|
||||
// * id: Wireless ID of the switch (1-4)
|
||||
// * cmd: Command to send (1 = on, 0 = off)
|
||||
function pswitch(chan, id, cmd)
|
||||
function pswitch(id)
|
||||
{
|
||||
$.ajax({url: "rfbb?chan=" + chan + "&id=" + id + "&cmd=" + cmd});
|
||||
$.ajax({url: "power/" + id});
|
||||
}
|
||||
|
||||
/*$(document).bind("pagebeforeshow", function(event,pdata) {
|
||||
|
@ -339,25 +339,13 @@ desc: This is the main file for the web-based RaspiControl.
|
|||
<article data-role="content">
|
||||
<ul data-role="listview">
|
||||
<li data-icon="info">
|
||||
<h1>Monitor & Co.</h1>
|
||||
<div data-role="controlgroup" data-type="horizontal">
|
||||
<a href="#" onclick="pswitch(1, 2, 1)" data-role="button">An</a>
|
||||
<a href="#" onclick="pswitch(1, 2, 0)" data-role="button">Aus</a>
|
||||
</div>
|
||||
<a href="#" onclick="pswitch(2)"><h1>Monitor & Co</h1></a>
|
||||
</li>
|
||||
<li data-icon="info">
|
||||
<h1>Drucker</h1>
|
||||
<div data-role="controlgroup" data-type="horizontal">
|
||||
<a href="#" onclick="pswitch(1, 1, 1)" data-role="button">An</a>
|
||||
<a href="#" onclick="pswitch(1, 1, 0)" data-role="button">Aus</a>
|
||||
</div>
|
||||
<a href="#" onclick="pswitch(1)"><h1>Drucker</h1></a>
|
||||
</li>
|
||||
<li data-icon="info">
|
||||
<h1>Rechner</h1>
|
||||
<div data-role="controlgroup" data-type="horizontal">
|
||||
<a href="#" onclick="pswitch(1, 4, 1)" data-role="button">An</a>
|
||||
<a href="#" onclick="pswitch(1, 4, 0)" data-role="button">Aus</a>
|
||||
</div>
|
||||
<a href="#" onclick="pswitch(4)"><h1>Rechner</h1></a>
|
||||
</li>
|
||||
</ul>
|
||||
</article>
|
||||
|
|
15
routes/power.js
Normal file
15
routes/power.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
var exec = require("child_process").execFile;
|
||||
|
||||
exports.toggle = function(req, res) {
|
||||
if (req.params.id !== undefined) {
|
||||
exec("/usr/bin/sispmctl", ["-nt" + req.params.id], function(err, stdout, stderr){
|
||||
if (err !== null) {
|
||||
// an error occured, log it
|
||||
res.status(400).send({"errid": 5, "errtxt": "Error Switching Socket"});
|
||||
} else {
|
||||
res.status(200).end();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ var bodyParser = require('body-parser');
|
|||
|
||||
var tempdb = require("./routes/tempdb.js");
|
||||
var index = require("./routes/index.js");
|
||||
var power = require("./routes/power.js");
|
||||
|
||||
global.rootpath = __dirname;
|
||||
|
||||
|
@ -18,9 +19,11 @@ srv.get("/temp/:id", tempdb.getTemp);
|
|||
srv.post("/temp", tempdb.addTemp);
|
||||
srv.put("/temp/:id", tempdb.updTemp);
|
||||
|
||||
srv.get("/power/:id", power.toggle);
|
||||
|
||||
srv.get("/", index.index);
|
||||
srv.get("/inc/:file", index.inc);
|
||||
srv.get("/inc/images/:file", index.img);
|
||||
|
||||
srv.listen(3000);
|
||||
console.log("Server started on port 3000.");
|
||||
srv.listen(80);
|
||||
console.log("Server started on port 80.");
|
||||
|
|
Loading…
Reference in a new issue