NodeJS and Raspberry Pi

Now I ran Raspbian on the Raspberry Pi, and I would like to make a control panel for it, so I can control my Raspberry Pi in a web browser. But how do I execute commands in NodeJS?

+5
source share
5 answers

You can use this node.js code to run commands on raspberries pi (below is an example to execute a reboot command on raspberries pi)

var exec = require('child_process').exec;

function execute(command, callback) {
  var cmd = exec(command, function(error, stdout, stderr) {
    console.log("error: " + error);
    callback(stdout);
  });
}

function reStart() {
  try {
    console.log("Reboot");
    execute('sudo reboot', function(callback) {
    });
  }
  catch (err) {
    console.log(err);
  }
}
+2
source

You need to check if your Linux supports sysfs interface for GPIO and PWM. In most cases, this is not available with standard configuration, and control is carried out through some "proprietary" (not proprietary, but difficult to manage) interface.

sysfs, fs nodejs gpio fd .

, , Raspberry Pi: https://www.npmjs.org/package/native-io

0

apt-get install -y node npm Node NPM, Node n (https://www.npmjs.com/package/n) Raspi-Io (https://www.npmjs.com/package/raspi-io) Raspberry Pi.

0

, , node-red.

Raspberry Pi, , .. -, .

node-red .

0

Source: https://habr.com/ru/post/1530764/


All Articles