A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cnc.js.org/docs/rpi-setup-guide/ below:

Raspberry Pi Setup Guide | cncjs

Raspberry Pi Setup Guide

We recommend that you use a Raspberry Pi 3 or Raspberry Pi 2 because of the performance requirements of the Node.js application. If you a buying a raspberry pi, buy a Raspberry Pi 3 or latest model.

Recommed Software (for a full web capatable CNC software stack): Raspberry Pi Install: System Preparation Install NOOBS & RASPBIAN on your Raspberry Pi Configure Raspberry Pi
# Change User Passwords
sudo passwd pi
sudo passwd root

sudo raspi-config
# Change Timezone
# Change Hostname
# Change Boot Option: Boot to CLI (No GUI)
Updates & Upgrade System

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y



sudo apt-get install -y build-essential git


sudo apt-get install htop iotop nmon lsof screen -y
PAUSE HERE!!!, decide on which method to use: Install Node.js via Package Manager
# Install Node.js via Package Manager & Add Package Source
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -  # Install NodeJS v7
sudo apt-get install -y nodejs  # npm nodejs-legacy #(Installed with nodesource)
Update Node Package Manager (NPM)

sudo npm install npm@latest -g


echo "[NPM] ============"; which npm; npm -v;
echo "[NODE] ============"; which node; node -v

### Install Node.JS Serial Port application first (OPTIONAL) npm install serialport

Install CNCjs
# Install Latest Release Version of CNCjs
sudo npm install -g cncjs@latest --unsafe-perm

# --- OR ----

# Install Specific Version of CNCjs
#sudo npm install -g cncjs@v1.9.0-beta.1 --unsafe-perm  
Install Production Process Manager [PM2]

sudo npm install -g pm2



pm2 startup  # To start PM2 as pi / current user
  #[PM2] You have to run this command as root. Execute the following command:
  sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi


pm2 start $(which cncjs) -- --port 8000 -m /tinyweb:/home/pi/tinyweb


pm2 save


pm2 list
Iptables (allow access to port 8000 from port 80)
# Iptables (allow access to port 8000 from port 80)
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000

# Make Iptables Persistent
sudo apt-get install iptables-persistent -y

# How-to: Save & Reload Rules
#sudo netfilter-persistent save
#sudo netfilter-persistent reload

# How-to: Manually Save Rules
#sudo sh -c "iptables-save > /etc/iptables/rules.v4"
#sudo sh -c "ip6tables-save > /etc/iptables/rules.v6"

# Run this if issues to reconfigure iptables-persistent
# sudo dpkg-reconfigure iptables-persistent
Reboot to test

sudo reboot

You’re Done, STOP HERE!!!

The information below is a breakdown of the process above with different / additional options as part of a separate process.

Install Install Node.js via Node Version Manager (NVM) Install Node Version Manager (NVM)
# Install Node Version Manager (NVM)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash

# Rerun Profile script to start NVM
source ~/.bashrc  # Rerun profile after installing nvm
Install Node.js via NVM

Installing an ARM-version of Node has become very easy:


nvm install 4  
nvm use 4  
Update Node Package Manager (NPM)

npm install npm@latest -g

To make sure it ran correctly, run npm -v, nvm --version, & node -v. It should return the current versions.


echo "[NPM] ============"; which npm; npm -v;
echo "[NVM] ============"; nvm --version; nvm ls
echo "[NODE] ============"; which node; node -v

### Install Node.JS Serial Port application first (OPTIONAL) npm install serialport

Install CNCjs

npm install -g cncjs

Allow access to port 8000 from port 80
# Allow access to port 8000 from port 80
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000

# Make Iptables Persistent
sudo apt-get install iptables-persistent -y

# How-to: Save & Reload Rules
#sudo netfilter-persistent save
#sudo netfilter-persistent reload

# How-to: Manually Save Rules
#sudo sh -c "iptables-save > /etc/iptables/rules.v4"
#sudo sh -c "ip6tables-save > /etc/iptables/rules.v6"

# Run this if issues to reconfigure iptables-persistent
# sudo dpkg-reconfigure iptables-persistent
Auto Start Options Install Production Process Manager [PM2]
# Install Production Process Manager [PM2]
npm install pm2 -g

# Start CNCjs (on port 8000) with PM2
pm2 start $(which cncjs) -- --port 8000

# Setup PM2 Startup Script
pm2 startup debian
#[PM2] You have to run this command as root. Execute the following command:
sudo su -c "env PATH=$PATH:/home/pi/.nvm/versions/node/v4.5.0/bin pm2 startup debian -u pi --hp /home/pi"

# Set current running apps to startup
pm2 save

# Get list of PM2 processes
pm2 list
Auto Start on Boot with cron (Alternative)

crontab -u pi -e


@reboot env PATH=$PATH:/home/pi/.nvm/versions/node/v4.5.0/bin /home/pi/.nvm/versions/node/v4.5.0/bin/cnc >> $HOME/cncjs.log 2>&1
You’re Done, STOP HERE!!! Install Node.js Manually

Information on how to install Node.js on Raspberry Pi 1 or ARM6 devices


wget https://nodejs.org/dist/v4.5.0/node-v4.5.0-linux-armv6l.tar.xz
tar -xvf node-v4.5.0-linux-armv6l.tar.xz 
cd node-v4.5.0-linux-armv6l
sudo cp -R * /usr/local/

Resume install at Update Node Package Manager (NPM)

Maintaining your Software Stack w/ Updates & Upgrades Updates & Upgrade System

sudo apt-get update
sudo apt-get upgrade -y  # Should also update Node.js if you used method #1
sudo apt-get dist-upgrade -y

Update Node Package Manager (NPM)

sudo npm install npm@latest -g


echo "[NPM] ============"; which npm; npm -v;
echo "[NODE] ============"; which node; node -v
Update CNCjs
# Stop CNCjs in PM2 
pm2 stop cnc

# Update CNCjs
#sudo npm update -g cncjs --unsafe-perm  
sudo npm install -g cncjs --unsafe-perm  # Install CNCjs again, if this fails or causes issue then run (sudo npm uninstall -g cncjs; sudo npm install -g cncjs --unsafe-perm )   https://github.com/cncjs/cncjs/issues/78

# Restart CNCjs in PM2
pm2 start cnc
Update Production Process Manager [PM2]

pm2 save

Then install the latest PM2 version from NPM:
sudo npm install pm2 -g

And finally update the in-memory PM2 process:
pm2 update
TinyWeb Console for 320x240 LCD Display

rm -r cncjs-pendant-tinyweb*


wget https://github.com/cncjs/cncjs-pendant-tinyweb/releases/download/latest/cncjs-pendant-tinyweb-1.0.0-613f598.zip


unzip cncjs-pendant-tinyweb*.zip -d /home/pi/
rm -r cncjs-pendant-tinyweb*.zip


mv /home/pi/cncjs-pendant-tinyweb* /home/pi/tinyweb


cncjs -m /tinyweb:/home/pi/tinyweb


pm2 stop cncjs  
pm2 delete cnsjc  
pm2 start $(which cncjs) -- --port 8000 -m /tinyweb:/home/pi/tinyweb
pm2 save 
Wireless Setup

https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=139866 https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=139486


sudo ifup wlan0


sudo iwlist wlan0 scan


sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

network={
  ssid="YOUR_SSID"
  scan_ssid=1
  psk="YOUR_PASSKEY"
  mode=0
  proto=WPA2
  key_mgmt=WPA-PSK
  pairwise=CCMP
  group=CCMP
  auth_alg=OPEN
  id_str="raspi"
  priority=1
}



sudo ifdown wlan0
sudo ifup wlan0


ifconfig wlan0
MJPEG-Streamer Install & Setup
# Update & Install Tools
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential libjpeg8-dev imagemagick libv4l-dev cmake -y

# Clone Repo in /tmp
cd /tmp
git clone https:
cd mjpg-streamer/mjpg-streamer-experimental

# Make
make
sudo make install

# Run
/usr/local/bin/mjpg_streamer -i "input_uvc.so -r 1280x720 -d /dev/video0 -f 30 -q 80" -o "output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www"
MJPEG-Streamer Auto Start Manager Script
nano /home/pi/mjpg-streamer.sh

Add the below code to ( /home/pi/mjpg-streamer.sh )

#!/bin/bash



MJPG_STREAMER_BIN="/usr/local/bin/mjpg_streamer" 
MJPG_STREAMER_WWW="/usr/local/share/mjpg-streamer/www"
MJPG_STREAMER_LOG_FILE="$(dirname $0)/mjpg-streamer.log"
RUNNING_CHECK_INTERVAL="2" 
HANGING_CHECK_INTERVAL="3" 

VIDEO_DEV="/dev/video0"
FRAME_RATE="30"
QUALITY="60"
RESOLUTION="VGA"  
PORT="8080"
YUV="yes"

INPUT_OPTIONS="-r ${RESOLUTION} -d ${VIDEO_DEV} -f ${FRAME_RATE} -q ${QUALITY}"
if [ "${YUV}" == "true" ]; then
	INPUT_OPTIONS+=" -y"
fi

OUTPUT_OPTIONS="-p ${PORT} -w ${MJPG_STREAMER_WWW}"


function running() {
    if ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} >/dev/null 2>&1; then
        return 0

    else
        return 1

    fi
}

function start() {
    if running; then
        echo "already started"
        return 1
    fi

    export LD_LIBRARY_PATH="$(dirname $MJPG_STREAMER_BIN):."

	echo "Starting:  ${MJPG_STREAMER_BIN} -i \"input_uvc.so ${INPUT_OPTIONS}\" -o \"output_http.so ${OUTPUT_OPTIONS}\""
    ${MJPG_STREAMER_BIN} -i "input_uvc.so ${INPUT_OPTIONS}" -o "output_http.so ${OUTPUT_OPTIONS}" >> ${MJPG_STREAMER_LOG_FILE} 2>&1 &

    sleep 1

    if running; then
        if [ "$1" != "nocheck" ]; then
            check_running & > /dev/null 2>&1 
            check_hanging & > /dev/null 2>&1 
        fi

        echo "started"
        return 0

    else
        echo "failed to start"
        return 1

    fi
}

function stop() {
    if ! running; then
        echo "not running"
        return 1
    fi

    own_pid=$$

    if [ "$1" != "nocheck" ]; then
        
        ps aux | grep $0 | grep start | tr -s ' ' | cut -d ' ' -f 2 | grep -v ${own_pid} | xargs -r kill
        sleep 0.5
    fi

    
    ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} | tr -s ' ' | cut -d ' ' -f 2 | grep -v ${own_pid} | xargs -r kill

    echo "stopped"
    return 0
}

function check_running() {
    echo "starting running check task" >> ${MJPG_STREAMER_LOG_FILE}

    while true; do
        sleep ${RUNNING_CHECK_INTERVAL}

        if ! running; then
            echo "server stopped, starting" >> ${MJPG_STREAMER_LOG_FILE}
            start nocheck
        fi
    done
}

function check_hanging() {
    echo "starting hanging check task" >> ${MJPG_STREAMER_LOG_FILE}

    while true; do
        sleep ${HANGING_CHECK_INTERVAL}

        
        if tail -n2 ${MJPG_STREAMER_LOG_FILE} | grep -i "error grabbing frames" > /dev/null; then
            echo "server is hanging, killing" >> ${MJPG_STREAMER_LOG_FILE}
            stop nocheck
        fi
    done
}

function help() {
    echo "Usage: $0 [start|stop|restart|status]"
    return 0
}

if [ "$1" == "start" ]; then
    start && exit 0 || exit -1

elif [ "$1" == "stop" ]; then
    stop && exit 0 || exit -1

elif [ "$1" == "restart" ]; then
    stop && sleep 1
    start && exit 0 || exit -1

elif [ "$1" == "status" ]; then
    if running; then
        echo "running"
        exit 0

    else
        echo "stopped"
        exit 1

    fi

else
    help

fi
Start on Boot

chmod +x /home/pi/mjpg-streamer.sh


crontab -e


@reboot /home/pi/mjpg-streamer.sh start
FFMpeg

http://www.jeffreythompson.org/blog/2014/11/13/installing-ffmpeg-for-raspberry-pi/


sudo -i


cd /usr/src
git clone git://git.videolan.org/x264
cd x264
./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
make
sudo make install


cd /usr/src
git clone https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg
sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
make
sudo make install
Recored Stream w/ ffmpeg

source_stram="http://xcarve:8080/?action=stream"
destination_directory="/home/pi/Videos"
destination_file="xcarve-recording_$(date +'%Y%m%d_%H%M%S').mpeg"


ffmpeg -i "${source_stram}" "${destination_directory}/${destination_file}"
Raspberry Pi Shutdown Button & LED Script

Gracefully shutdown the Raspberry Pi using a hardware button.

NOTE: Jumping pins 5 & 6 (grounding GPIO3) will power on the RPi. So I altered the script to use GPIO3, rather than pin 40. Now I can use the same button to turn on and off the Pi!

Python Script
sudo touch /root/shutdown_button_pi.py  
sudo chmod +x /root/shutdown_button_pi.py  
sudo nano /root/shutdown_button_pi.py  
Python Script: Interrupts & While Loop [For LED Button] (AWEOMENESSS!!!)







from subprocess import call
import RPi.GPIO as gpio
import time



button_pin = 7
led_pin = 11  


def loop():
    
    while True:
        time.sleep(1)


def blink_led(interations):
    for interation in range(interations):
        gpio.output(led_pin,gpio.HIGH)
        time.sleep(.5)
        gpio.output(led_pin,gpio.LOW)
        time.sleep(.5)
        gpio.output(led_pin,gpio.HIGH)


def shutdown(pin):
    
    gpio.output(led_pin,gpio.LOW)

    
    pressed_time=time.monotonic()
    while gpio.input(button_pin): 
        
        if time.monotonic()-pressed_time >= 3:
            
            blink_led(3)
            call('halt', shell=False)
            break

    
    gpio.output(led_pin,gpio.HIGH)


gpio.setmode(gpio.BOARD) 


gpio.setup(button_pin, gpio.IN) 
gpio.add_event_detect(button_pin, gpio.RISING, callback=shutdown, bouncetime=200) 


gpio.setup(led_pin, gpio.OUT, initial=1)

loop() 
Set to Executable
sudo chmod +x  /root/shutdown_button_pi.py
Run Script & Test

sudo python3 /root/shutdown_button_pi.py

Autostart Script
# Run Crontab
sudo crontab -e

# Now, enter the line:
@reboot sudo /usr/bin/python3 /root/shutdown_button_pi.py > /root/shutdown_button_pi.log 2>&1

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4