Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const sys = require('sys')
  2. const exec = require('child_process').exec
  3. const express = require('express')
  4. const app = express()
  5.  
  6. const commandOn = '/root/workspace/raspberry-remote/send -p 16 11001 2 1'
  7. const commandOff = '/root/workspace/raspberry-remote/send -p 16 11001 2 0'
  8.  
  9. const PORT = 9000
  10.  
  11. app.get('/on', (req, res) => {
  12.   exec(commandOn, (error, stdout, stderr) => {
  13.     sys.print('stdout: ' + stdout)
  14.     sys.print('stderr: ' + stderr)
  15.  
  16.     if (error !== null) {
  17.       console.log('exec error: ' + error)
  18.       res.send('Error while turning on: ' + error)
  19.     } else {
  20.       res.send('Success, now turning on: ' + stdout)
  21.     }
  22.   })
  23. })
  24.  
  25. app.get('/off', (req, res) => {
  26.   exec(commandOff, (error, stdout, stderr) => {
  27.     sys.print('stdout: ' + stdout)
  28.     sys.print('stderr: ' + stderr)
  29.  
  30.     if (error !== null) {
  31.       console.log('exec error: ' + error)
  32.       res.send('Error while turning off: ' + error)
  33.     } else {
  34.       res.send('Success, now turning off: ' + stdout)
  35.     }
  36.   })
  37. })
  38.  
  39. const server = app.listen(PORT, () => {
  40.   console.log('App listens on port ' + PORT)
  41. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement