2023-04-20 23:28:32 +08:00
2021-12-20 14:52:55 +08:00
2023-04-20 23:28:32 +08:00
2022-12-01 15:18:47 +08:00
2021-12-20 14:52:55 +08:00
2021-12-20 14:52:55 +08:00
2021-12-20 14:52:55 +08:00
2022-05-06 11:25:30 +08:00
2021-12-20 14:52:55 +08:00
2021-12-20 14:52:55 +08:00
2021-12-20 14:52:55 +08:00

Introduction

New goal on pi4 without kotlin and django, and with only one dataserver.

Installation

Get Raspbrain into SD card

Download Raspbian Bullseye Lite

https://www.raspberrypi.org/downloads/raspberry-pi-os/

Copy raspbian.img into SD card
# check disk
lsblk

# copy data to sd card
sudo dd bs=4M if=yyyy-mm-dd-raspios-bullseye-armhf-lite.img of=/dev/sdX conv=fsync status=progress

# enable ssh on first boot
add ssh.txt in boot folder

Setup pi3 environment

raspi-config setting
* means neccessary
△ means under some circumstances not need to change the options

* Change Password

* Change Locale
    - sudo nano /etc/locale.gen
        * uncomment # en_US.UTF-8 UTF-8 -> en_US.UTF-8 UTF-8
    - sudo raspi-config
        * Localisation Options
        * Change Locale
        * en_US.UTF-8 UTF-8
        * en_US.UTF-8 UTF-8 (Configuring locales)

* Change TimeZone
    - Localisation Options
        * Change Timezone
        * Asia
        * Taipei

△ Change Keyboard Layout
    - Localisation Options
        * Change Keyboard Layout
        * Generic 105-key PC (intl.) (default)
        * Other (escape UK menu)
        * English (US)
        * The default for the keyboard layout
        * No compose key

* Change Wifi Country
    - Localisation Options
        * Change WLAN Country
        * TW Taiwan

△ Wifi setting
    - Network Options
        * Wireless LAN
        * SSID (wifi-name)
        * password (wifi-pass)

△ Enable SSH service
    - Interfacing Options
        * SSH
        * Yes

* Reboot
    sudo reboot

* System update
    sudo apt-get update
    sudo apt-get upgrade
Install dependencies
sudo apt-get install vim git wiringpi build-essential libi2c-dev i2c-tools python-dev libffi-dev python3-pip postgresql npm
sudo apt-get install libatlas-base-dev
sudo apt-get install python3-numpy
wiringpi conflict

need to install wiringpi: https://github.com/WiringPi/WiringPi install instructions: https://github.com/WiringPi/WiringPi/blob/master/INSTALL

Setup project

Clone data server project
cd ~
git clone https://gitlab.com/wisetop/controller/wisetopdataserver.git
Install python dependencies
 cd ~/wisetopdataserver
pip3 install -r requirements.txt
pip3 install SQLAlchemy
Packages version
fake-rpi                      0.6.3
gprof2dot                     2019.11.30
matplotlib                    3.2.1
objgraph                      3.4.1
paho-mqtt                     1.5.0
pycrypto                      2.6.1
PyInstaller                   3.6
pyserial                      3.4
RPi.GPIO                      0.7.0
smbus-cffi                    0.5.1
Sphinx                        2.4.4
sphinx-autodoc-typehints      1.10.3
spidev                        3.2
yappi                         1.2.3
psycopg2                      2.8.5
Build C extension
cd ~/wisetopdataserver/python/biopro/ext/
rm -rf *.so build
python3 setup.py build_ext --inplace
Check setup-uart file
cd ~/wisetopdataserver/
sudo vim ./run-setup-uart.sh
Modify the code as following
# for pi3
if [ -z "$(grep dtoverlay=pi3-disable-bt /boot/config.txt)" ]; then
   echo 'dtoverlay=pi3-disable-bt' >> /boot/config.txt
fi
# for pi4
if [ -z "$(grep dtoverlay=pi4-disable-bt /boot/config.txt)" ]; then
   echo 'dtoverlay=pi4-disable-bt' >> /boot/config.txt
fi

Enable uart, spi, serial_port and disable bluetooth

sudo ./run-setup-uart.sh

sudo raspi-config
    Interfacing options
    serial
    no
    yes
reboot
Set pi password
cd ~
passwd
Current password:raspberry
New password:5k6zj454778225
Retype new password:5k6zj454778225
Auto run program when device start
sudo vim /etc/rc.local
add the code following as:
sudo -H -u pi nohup /home/pi/wisetopdataserver/run-data-server.sh > /home/pi/.data_server.out &
#sudo -H -u pi nohup /home/pi/wisetopdataserver/run-data-server.sh > /home/pi/.wisetop_data_$now.out &
/etc/rc.local
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

now=$(date +'%F_%T')

sudo nohup systemctl restart apache2
sudo nohup systemctl restart mosquitto

nohup node /home/pi/wisetopapiserver/dist/app.js > /home/pi/.api_server.out &

sleep 5

sudo -H -u pi nohup /home/pi/wisetopdataserver/run-data-server.sh > /home/pi/.data_server.out &
#sudo -H -u pi nohup /home/pi/wisetopdataserver/run-data-server.sh > /home/pi/.wisetop_data_$now.out &

exit 0

MQTT broker install

1.Install mosquitto

sudo apt-get install mosquitto mosquitto-clients

2.Enable Remote Access

sudo vim /etc/mosquitto/conf.d/default.conf

add the code following as:

listener 1883
protocol mqtt
listener 8083
protocol websockets
allow_anonymous true
3.restart mqtt broker

sudo systemctl restart mosquitto

4.Robust MQTT

create mosquitto_restart.sh

cd ~ sudo vim mosquitto_restart.sh

add the code following as:

if [ "`ps -aux | grep /usr/sbin/mosquitto | wc -l`" == "1" ]

then
        echo "mosquitto wasnt running so attempting restart" >> /home/ubuntu/cron.log
        systemctl restart mosquitto
        exit 0
fi

echo "$SERVICE is currently running" >> /home/ubuntu/cron.log
exit 0
5.add mosquitto_restart.sh to root routing

sudo chmod +x mosquitto_restart.sh sudo -i crontab -e

add the code following as:

*/5 * * * * /home/pi/mosquitto_restart.sh
6.Auto run MQTT broker when when pi-start

sudo vim /etc/rc.local

add the code following as:

sudo nohup systemctl restart mosquitto

Setting up a Routed Wireless Access Point

1.Install AP and Management Software

sudo apt install hostapd sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo apt install dnsmasq sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent

2.Set up the Network Router

sudo nano /etc/dhcpcd.conf

interface wlan0
    static ip_address=192.168.2.1/24
    nohook wpa_supplicant

sudo nano /etc/sysctl.d/routed-ap.conf

# Enable IPv4 routing
net.ipv4.ip_forward=1

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo netfilter-persistent save sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

sudo nano /etc/dnsmasq.conf

interface=wlan0 # Listening interface
dhcp-range=192.168.2.2,192.168.2.255,255.255.255.0,24h
                # Pool of IP addresses served via DHCP
domain=wlan     # Local wireless DNS domain
address=/gw.wlan/192.168.2.1
                # Alias for this router
3.Ensure Wireless Operation

sudo rfkill unblock wlan

4.Configure the AP Software

sudo nano /etc/hostapd/hostapd.conf

country_code=TW
interface=wlan0
ssid=WTP_NONE
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=00000000
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

# 802.11n support
ieee80211n=1
# make raspberry pi dongle fast
wme_enabled=1
# ht_capab: HT capabilities, enable 40MHz
ht_capab=[HT40+][SHORT-GI-40]
5.Running the new Wireless AP

sudo systemctl reboot

Install Apache2

sudo apt install apache2

Deploy web site

sudo vim /etc/apache2/sites-available/000-default.conf

<VirtualHost *:8080> #80------>8080
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin bioprovue@localhost
    DocumentRoot /var/www/bioprovuebuild
</VirtualHost>
raspberry website document:

https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md

ChangeLog

[2022.12.28] change meta_project_info to project_metas change project_report to project_reports alter table project_meta column cycle type string to jsonb

[2022.11.16] add python package SQLAlchemy add new column project(int4) in postgresSQL table recording_meta_datas add new postgresSQL table project_report add new postgresSQL table meta_project_info

[2022.10.18] socektTimeout from 1s -> 5s socketListen from 3 -> 20

[2022.09.30] add new column cycle(jsonb) in postgresSQL table projects

[2022.9.28] add python package numpy

S
Description
No description provided
Readme 2.1 MiB
Languages
Python 90.3%
C 9.3%
Shell 0.4%