Installing the on-board Server

Mike Tango Bravo · Updated 2022-02-07

This section describes the steps to install the Vinophonics on-board server.

These are the specifications for the server:

  • Raspberry Pi 4 - 4GB
    • SANdisk Extreme 64GB
    • HiFiBerry DAC+ADC
  • Arduino Mega
Configuring Raspberry Pi

Install and configure Raspbian

Follow the instructions for installing raspbian, similar to these. The Weather Station

sudo apt-get install python-pip
python -m pip install --upgrade pip setuptools wheel
sudo apt-get install python3-pip

create users and ssh access

Install and configure PyFirmata

From Knight-of-pi.org:

PyFirmata by Tino de Bruijn is an amazing tool for combining the powers of the Raspberry Pi (full operating system, python, …) and the Arduino (high time precision, …). This will allow us to control the Arduino Mega from the Raspberry Pi. This is important, because of two reasons:

The Raspberry Pi has the input data from the ethereum node script.

If we want to use 16 PWM pins, the Arduino Mega only has 14 (or 15), but we could use one (or 2) of the RPI PWM pins.

sudo apt-get -y install arduino python-serial mercurial
git clone https://github.com/tino/pyFirmata
cd pyFirmata
sudo python setup.py install

Using the Arduino IDE, upload the default PyFirmata firmware on the arduino (file → Examples → Firmata → Standard Firmata)

Test using PyFirmata "Hello World"

Download the script from GitHub:

wget https://github.com/JoBergs/RaspiContent/raw/master/pyfirmata_pwm.py

Set the USB port in the following line to match the output from

dmesg | grep tty
pi@vinophonics:~/pyFirmata $ dmesg | grep tty
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 cma=64M cma=256M  smsc95xx.macaddr=DC:A6:32:1A:AB:AE vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=PARTUUID=4224e0ab-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
[    0.000714] console [tty1] enabled
[    0.855408] fe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 33, base_baud = 0) is a PL011 rev2
[ 1911.239197] cdc_acm 1-1.3:1.0: ttyACM0: USB ACM device

Edit pyfirmata_pwm.py to match the device name

board = pyfirmata.Arduino('/dev/ttyACM0')

Then, connect the pin D3 of the Arduino to a LED and a 270Ω resistor on the breadboard.

Now, start the script by typing:

python pyfirmata_pwm.py

The glow of the LED will increase slowly until the full capacity is reached:

Configure static wifi IP address

Edit the file:

/etc/network/interfaces

source-directory /etc/network/interfaces.d

allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.0.74
        netmask 255.255.255.0
        gateway 192.168.0.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Add to the file /etc/dhcpcd.conf the following lines:

interface eth0
static ip_address=192.168.8.252/24
static routers=192.168.8.1
static domain_name_servers=192.168.8.1

interface wlan0
static ip_address=192.168.0.74/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

mbarrow@vinophonics:~ $ sudo systemctl disable dhcpcd

mbarrow@vinophonics:~ $ sudo systemctl enable networking

Configure VPN

mbarrow@vinophonics:~$ sudo apt-get -y install openvpn
[sudo] password for mbarrow:                 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  easy-rsa resolvconf
The following packages will be upgraded:
  openvpn
1 upgraded, 0 newly installed, 0 to remove and 542 not upgraded.
Need to get 470 kB of archives.
After this operation, 4.096 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 openvpn amd64 2.4.4-2ubuntu1.3 [470 kB]
Fetched 470 kB in 1s (333 kB/s)   
Preconfiguring packages ...
(Reading database ... 252781 files and directories currently installed.)
Preparing to unpack .../openvpn_2.4.4-2ubuntu1.3_amd64.deb ...
Unpacking openvpn (2.4.4-2ubuntu1.3) over (2.4.4-2ubuntu1.1) ...
Processing triggers for ureadahead (0.100.0-20) ...
ureadahead will be reprofiled on next reboot
Setting up openvpn (2.4.4-2ubuntu1.3) ...
 * Restarting virtual private network daemon.                            [ OK ] 
Processing triggers for systemd (237-3ubuntu10.9) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

mbarrow@vinophonics:~/vpn/openvino-openvpn.tar$ mv mdv-clofw01-TCP4-1195-india.ovpn /etc/openvpn/openvino_india.conf
mbarrow@vinophonics:~/vpn/openvino-openvpn.tar$ sudo vi /etc/openvpn/auth.txt
  • Edit this file, and add two lines:
    
    • username
      
    • password
      
mbarrow@vinophonics:/etc/openvpn$ sudo ln -s mdv-clofw01-TCP4-1195-india.conf mdv-clofw01-TCP4-1195-india.ovpn

mbarrow@vinophonics:/etc/openvpn$ ls -la

total 48

drwxr-xr-x 4 root root 4096 Jul 11 12:15 .

drwxr-xr-x 146 root root 12288 Jul 11 00:07 ..

-rw-r--r-- 1 root root 17 Jul 11 12:08 auth.txt

drwxr-xr-x 2 root root 4096 Sep 5 2018 client

-rw-r--r-- 1 mbarrow mbarrow 657 Dec 21 2018 mdv-clofw01-TCP4-1195-india-tls.key

-rw-r--r-- 1 root root 371 Jul 11 12:14 mdv-clofw01-TCP4-1195-india.conf

lrwxrwxrwx 1 root root 32 Jul 11 12:15 mdv-clofw01-TCP4-1195-india.ovpn -> mdv-clofw01-TCP4-1195-india.conf

-rw-r--r-- 1 mbarrow mbarrow 4101 Dec 21 2018 mdv-clofw01-TCP4-1195-india.p12

drwxr-xr-x 2 root root 4096 Sep 5 2018 server

-rwxr-xr-x 1 root root 1301 Sep 5 2018 update-resolv-conf

Edit the mdv-clofw01-TCP4-1195-india.conf to reflect auth.txt
auth-user-pass /etc/openvpn/auth.txt


sudo openvpn --config /etc/openvpn/mdv-clofw01-TCP4-1195-india.conf

sudo systemctl enable openvpn@mdv-clofw01-TCP4-1195-india

Setup Dual Network access

To enable configuration of the Vinophonics wifi interface, a default bluetooth networking interface is configured to assure that when MTBMBP is available as a bluetooth interface, a network connection is plumbed. This way, from MTBMBP, an ssh connection is always available, regardless of wifi availability.

After a secure X connection si performed, the itinerant wifi connection can be established:

MTBMBP:~ mbarrow$ xhost +

mbarrow@vinophonics:~$ export DISPLAY=192.168.1.39:0.0

mbarrow@vinophonics:~$ nm-connection-editor

Installing CIFS/Samba support

By default, Raspbian does not include CIFS/Samba support, but this can easily be added. The following commmands will install all the required components for using Samba as a server or a client.

sudo apt update
sudo apt install samba samba-common-bin smbclient cifs-utils
sudo mount.cifs //MTBMBP/vinophonics /home/pi/mac -o user=mbarrow,nounix,sec=ntlmssp