Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sys = require('sys')
- const exec = require('child_process').exec
- const express = require('express')
- const app = express()
- const commandOn = '/root/workspace/raspberry-remote/send -p 16 11001 2 1'
- const commandOff = '/root/workspace/raspberry-remote/send -p 16 11001 2 0'
- const PORT = 9000
- app.get('/on', (req, res) => {
- exec(commandOn, (error, stdout, stderr) => {
- sys.print('stdout: ' + stdout)
- sys.print('stderr: ' + stderr)
- if (error !== null) {
- console.log('exec error: ' + error)
- res.send('Error while turning on: ' + error)
- } else {
- res.send('Success, now turning on: ' + stdout)
- }
- })
- })
- app.get('/off', (req, res) => {
- exec(commandOff, (error, stdout, stderr) => {
- sys.print('stdout: ' + stdout)
- sys.print('stderr: ' + stderr)
- if (error !== null) {
- console.log('exec error: ' + error)
- res.send('Error while turning off: ' + error)
- } else {
- res.send('Success, now turning off: ' + stdout)
- }
- })
- })
- const server = app.listen(PORT, () => {
- console.log('App listens on port ' + PORT)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement