diff options
author | xengineering <mail2xengineering@protonmail.com> | 2020-09-13 20:50:54 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2020-09-13 20:50:54 +0200 |
commit | fbc00d7932a717a227389040a96443e61b597d7c (patch) | |
tree | c732c68cd16e5eac3e302a64f62441128ca39749 /static | |
parent | de699b487df334226fe9863ffc7c92d081b38a76 (diff) | |
download | picontrol-fbc00d7932a717a227389040a96443e61b597d7c.tar picontrol-fbc00d7932a717a227389040a96443e61b597d7c.tar.zst picontrol-fbc00d7932a717a227389040a96443e61b597d7c.zip |
Implement API
Diffstat (limited to 'static')
-rw-r--r-- | static/js/api_client.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/static/js/api_client.js b/static/js/api_client.js new file mode 100644 index 0000000..4c80651 --- /dev/null +++ b/static/js/api_client.js @@ -0,0 +1,40 @@ + + +/* + picontrol - A small Web Application to shutdown or reboot your Raspberry Pi. + + Copyright (C) 2020 xengineering + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + + +function poweroff() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/api", true); + xhr.setRequestHeader("Content-type", "application/json"); + var data = {"cmd":"poweroff"} + var json = JSON.stringify(data); + xhr.send(json); +} + + +function reboot() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/api", true); + xhr.setRequestHeader("Content-type", "application/json"); + var data = {"cmd":"reboot"} + var json = JSON.stringify(data); + xhr.send(json); +} |