Giter VIP home page Giter VIP logo

calijuice's Introduction

juicefeed

The following info is a guide to setting up a basic node.js/express web server on a raspberry pi. A database will be created and populated with juice info from a cron script run every 15 minutes. Additionally, an express server will be installed that hosts a static web page (Juice Feed) which queries the aforementioned database for juice infos and displays chronologically sorted, filterable juice info cards.

Screen Shot

Requirements

Hardware (Monitor and keyboard only necessary for initial setup):

  • raspberry pi microSD card
  • micro USB power supply
  • HDMI cable
  • monitor
  • keyboard

Software:

  • Rasbian OS image (tesed using June 2018 release) here
  • Raspberry Pi image flashing software Etcher here
  • Putty SSH Client (optional) here

Install raspbian

Follow steps from raspbian installation guide here

  • Flash image to microSD card using Etcher.io
  • Insert microSD card into pi and plug in

Configure raspbian

Once the pi has booted, log in using: user pi password raspberry

Run sudo raspi-config to run raspberry pi config wizard:

  • setup and enable wifi [optional] (network options)
  • enable SSH for remote access (interface options)
  • set keyboard layout (localization options)
  • set timezone (localization options)
  • require user to log in (boot options/ Desktop/CLI)

Wireless config:
Use raspi-config tool network options

Wired config (using DHCP):
Shouldn't have to do anything

Wired config (static IP):
edit IP configuration file: sudo nano /etc/dhcpcd.conf add the following to the bottom of the file (ensure the static IP being set is not already in use on the network).

#static IP configuration 

interface eth0
static ip_address=192.168.50.50/24 
static routers=192.168.50.1 
static domain_name_servers=192.168.50.1

Reboot necessary after any network configuration change:
sudo reboot

Get your pi's IP address, record the IP address from the following command:
hostname -I

Use SSH for remaining configuration steps

Using your SSH client, enter the IP address found above to connect to your Pi:
ssh [email protected]

Create a new user

Add a new user, and delete default 'pi' user:
sudo adduser hawdis

To make new user part of the sudo group:
sudo adduser hawdis sudo

Reboot:
sudo reboot

Your SSH session will disconnect. Wait a minute or two and login with Putty again as your new user:
ssh [email protected]

Delete 'pi' user:
sudo deluser --remove-home pi

Install system wide app dependencies

Update rasbian:
sudo apt-get update then sudo apt-get upgrade

get required software from package manager:
sudo apt-get install -y git mariadb-server ufw

Allow access to ports:
sudo ufw allow 8082
sudo ufw allow 22

Enable firewall:
sudo ufw enable

Install latest node.js for your version of raspberry pi:
wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | sudo bash

mariadb setup

create new database user and set password. This needs to be done using 'root':
sudo mysql -u root

you are now at the mysql prompt. Now create the user and grant all privileges (replace 'hawdis' and 'abc123'):
GRANT ALL PRIVILEGES ON *.* TO 'hawdis'@'localhost' IDENTIFIED BY 'abc123';

quit mysql:
\q

log back in as your new user:
mysql -u hawdis -p

create new database:
CREATE DATABASE juicedb;

quit mysql:
\q

install and configure juicefeed app

clone from github:
git clone https://github.com/marsmith/juicefeed

enter project folder:
cd juicefeed

install npm dependencies:
npm install

Edit dbInfo.js file with your user credentials nano dbInfo.js

Edit config file and replace juice venue values as needed. This will configure your custom version of the juicefeed to suit your needs.
nano config.js

setup up cron jobs. cron is a special file that will execute tasks at a predefined interval.
crontab -e Choose your editor of choice, I like nano.

The entry below will run the 'getJuice.js' node script every 15 minutes to pull new juice data. Enter this on an empty line, where 'hawdis' is your username/home directory:

*/15 * * * * /usr/bin/node /home/hawdis/juicefeed/getJuice.js

Test your new juicefeed server

Run script manually for the first time at debug log level, check console log for errors:
node getJuice.js debug

Start up express server (stays running until CTRL-C):
node server.js

Open a browser on another computer/mobile device connected to the same network using the IP address found above as the URL ie.: http://192.168.1.195:8082

Persistently start and keep the node/express server script running (optional):

install pm2:
sudo npm install pm2 -g

create symlink for pm2 to enable user run:
sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2

start pm2 (replace 'hawdis' with your username/home directory):
pm2 start /home/hawdis/juicefeed/server.js
pm2 startup
sudo env PATH=$PATH:/opt/nodejs/bin /opt/nodejs/lib/node_modules/pm2/bin/pm2 startup systemd -u hawdis --hp /home/hawdis

calijuice's People

Contributors

njestes avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.