Oct 05 2019
RPI_NODE_P5.JS
summary:
having a local server to play p5.js should be easy with a Raspberry Pi
using Node and Express server.
update NODE, install npm
make app
p5.js and sketch
Raspbian node server start tools
test about a forum question
node and database
node on RPI4
current update / info:
Raspbian GNU/Linux 10
DEBIAN buster
Linux version 4.19.66-v7+
Raspberry Pi 3 Model B Plus Rev 1.3
inet 192.168.1.204
cpu-temp=52.1'C
date: Sat 2019-10-05 17:44:44
DEBIAN buster
Linux version 4.19.66-v7+
Raspberry Pi 3 Model B Plus Rev 1.3
inet 192.168.1.204
cpu-temp=52.1'C
date: Sat 2019-10-05 17:44:44
already installed:
pi@RPI:~/projects/p5js $ node -v
v10.15.2
v10.15.2
update NODE, install npm
follow my own article here
( in a temp dir what later is deleted, do:
but check on new version first:
)
wget https://nodejs.org/dist/latest/node-v12.11.1-linux-armv7l.tar.xz
tar -xvf node-v12.11.1-linux-armv7l.tar.xz
cd node-v12.11.1-linux-armv7l
sudo cp -R * /usr/local/
sudo reboot
pi@RPI:~/projects/p5js $ node -v
v12.11.1
pi@RPI:~/projects/p5js $ npm -v
6.11.3
v12.11.1
pi@RPI:~/projects/p5js $ npm -v
6.11.3
make app
old way:
mkdir myapp
cd myapp
npm init
npm install express --save
new way:
sudo npm install -g express-generator
i work in
/home/pi/projects/nodeserver/
here should make a
npm install express-session --save
/usr/local/bin/express -> /usr/local/lib/node_modules/express-generator/bin/express-cli.js
+ express-generator@4.16.1
added 10 packages from 13 contributors in 2.778s
express --view=pug myapp
cd myapp
npm install
DEBUG=myapp:* npm start
> myapp@0.0.0 start /home/pi/projects/p5js/myapp
> node ./bin/www
myapp:server Listening on port 3000
p5.js and sketch
lazy as usual, i go my newer sketch ( to be sure to catch a 0.9.0rev ) and download it.
( note: that downloads contain all files flat structure, so later should clean up )
unzip and copy all to
myapp/public/
restart server and WORKS
inside my network from a PC browser ( firefox ) call
http://192.168.1.204:3000/
manually i combine it with a test reading a csv file from assets, but see in console only

Raspbian node server start tools
made also a
chmod +x start
./start
well, to start that start you would need to go to that directory first...
and that you might copy to your desktop. OR
at
/home/pi/.config
create a /autostart subdirectory and copy that start.desktop in:
/home/pi/.config/autostart/start.desktop
( and reboot )

failed with build p5js editor
test about a forum question
also ref to Processing forum question
that is from the coding train, but not use the p5.js at all,
so just for test i replaced the index.html ( from p5.js ) with this
but the local csv file i tested already,
assets/test.csv
and get

so i renamed that index.html to test.html,
got the original data from the coding train website and put it also under assets/
and call the page with:
http://192.168.1.204:3000/test.html
manually:

test more @Kent's csv script, this works
node and database
try to get under node npm a database running
for the server RPI i try ( via terminal )
sudo apt install mariadb-server ( 150 MB / [Y] )
( expected usual admin user password question BUT nothing ???) try
mysql -u user -p
only errors, well not have user or password configured OR DEFAULTS?
lucky i typed
here find some better help
sudo mysql_secure_installation
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
$mysql -u root -p
password
CREATE USER 'pi'@'localhost' IDENTIFIED BY 'raspberry';
CREATE DATABASE processing;
USE processing;
status
GRANT ALL ON processing.* TO 'pi'@'localhost';
quit
$mysql -u pi -p
raspberry
use processing;
status
now a next step is about using SQL, best by making and executing sql files?
( bad style, never do the password thing like that!! )
nano dbdo with content:
#!/bin/bash
#
mysql -u pi --password=raspberry -t< "/home/pi/projects/p5jsdb/database/mycommand.sql" > "/home/pi/projects/p5jsdb/database/mycommand.log"
chmod +x dbdo
nano mycommand.sql with content for test:
use processing;
status;
./dbdo
cat mycommand.log
pi@RPI4:~/projects/p5jsdb/database $ cat mycommand.log
--------------
mysql Ver 15.1 Distrib 10.3.17-MariaDB, for debian-linux-gnueabihf (armv7l) using readline 5.2
Connection id: 44
Current database: processing
Current user: pi@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 20 hours 1 min 54 sec
Threads: 7 Questions: 94 Slow queries: 0 Opens: 32 Flush tables: 1 Open tables: 26 Queries per second avg: 0.001
--------------
pi@RPI4:~/projects/p5jsdb/database $
--------------
mysql Ver 15.1 Distrib 10.3.17-MariaDB, for debian-linux-gnueabihf (armv7l) using readline 5.2
Connection id: 44
Current database: processing
Current user: pi@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 20 hours 1 min 54 sec
Threads: 7 Questions: 94 Slow queries: 0 Opens: 32 Flush tables: 1 Open tables: 26 Queries per second avg: 0.001
--------------
pi@RPI4:~/projects/p5jsdb/database $
sure you can execute a sql script also "from inside" when login already:
mysql -u your_username -p your_password
use db_name
source
now try to setup a NODE web server page again, but
when i try above again ( for this db test project )
i noticed lots of warnings... so instead of a
one line terminal command to make express server
needed:
__________________
sudo npm install -g express-generator
express --view=pug p5jsdb
cd p5jsdb
npm install
npm audit fix
sudo npm install -g npm
DEBUG=p5jsdb:* npm start
__________________
now try install maria db for connect to server:
npm install mariadb
and inside app.js use
const mariadb = require('mariadb') //
node on RPI4
i used the slim desktop pack for install RPI4
and when i try
pi@RPI4:~ $ uname -m
armv7l
pi@RPI4:~ $ node -v
bash: node: command not found
pi@RPI4:~ $ sudo apt list nodejs
Listing... Done
nodejs/stable 10.19.0~dfsg1-1+rpi1 armhf
pi@RPI4:~ $
means that possibly because Node-RED not preinstalled also NO Node ready.
i check here
for LTS see
https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-armv7l.tar.xz
for CURRENT see
https://nodejs.org/dist/v14.3.0/node-v14.3.0-linux-armv7l.tar.xz
and try according this: use now:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install -y nodejs
and now see
pi@RPI4:~ $ node -v
v14.3.0
pi@RPI4:~ $ npm -v
6.14.5
for setup webserver:
sudo npm install -g express-generator
mkdir projects
cd projects
mkdir nodeserver
cd nodeserver
npm init
npm install express-session --save
express --view=pug myapp
creates a other subdir
cd myapp
npm install
DEBUG=myapp:* npm start
chmod +x start
also might need:
nano /home/pi/.config/autostart/nodeserver.desktop
setup current p5.js project by download from online editor into public subdir
start from PC browser:

i still like my PTZ operation, but when i try it from my old Android tablet
a long (click) tip on the canvas works for the X Y rotation ( Tilde adjust )
but a Zoom like use 2 fingers works for the webpage, but not the processing zoom,
and the alternate keyboard operation for PTZ also not usable from tablet,
so i build in 3 more sliders for PTZ tablet operation...
try at: editor.p5js
above scripts for start / autostart at boot work nice,
but i was looking for something modern / snappy
find: pm2
and give it a try:
You install it:
npm install -g pm2
Start a cluster of, for example, 3 processes:
pm2 start app.js -i 3
but here already run into problems.. looks like it restarts the app every 2 seconds? and the SITE is not reachable
And make pm2 starts them at boot:
pm2 startup
later can check it:
pm2 monit