Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 515cc9f7a2 | |||
| 9b92249fdb | |||
| adcc13b4de | |||
| 5228290eac | |||
| 034b7976cd |
@@ -4,7 +4,7 @@ New goal on pi4 without kotlin and django, and with only one dataserver.
|
||||
# Installation
|
||||
### Get Raspbrain into SD card
|
||||
|
||||
###### Download Raspbian Buster Lite
|
||||
###### Download Raspbian Bullseye Lite
|
||||
|
||||
>https://www.raspberrypi.org/downloads/raspberry-pi-os/
|
||||
|
||||
@@ -14,7 +14,7 @@ New goal on pi4 without kotlin and django, and with only one dataserver.
|
||||
lsblk
|
||||
|
||||
# copy data to sd card
|
||||
sudo dd bs=4M if=yyyy-mm-dd-raspbian-buster.img of=/dev/sdX conv=fsync status=progress
|
||||
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
|
||||
@@ -77,18 +77,22 @@ add ssh.txt in boot folder
|
||||
|
||||
|
||||
###### Install dependencies
|
||||
sudo apt-get install vim git wiringpi build-essential libi2c-dev i2c-tools python-dev libffi-dev python3-pip postgresql
|
||||
sudo apt-get install vim git wiringpi build-essential libi2c-dev i2c-tools python-dev libffi-dev python3-pip postgresql npm
|
||||
|
||||
###### wiringpi conflict
|
||||
need to install wiringpi: https://github.com/WiringPi/WiringPi
|
||||
install instructions: https://github.com/WiringPi/WiringPi/blob/master/INSTALL
|
||||
|
||||
### Setup project
|
||||
###### Clone project
|
||||
###### Clone data server project
|
||||
```
|
||||
cd ~
|
||||
git clone https://gitlab.com/bioproscientific/bioprorelife.git
|
||||
git clone https://gitlab.com/wisetop/controller/wisetopdataserver.git
|
||||
```
|
||||
|
||||
###### Install python dependencies
|
||||
```
|
||||
cd ~/bioprorelife
|
||||
cd ~/wisetopdataserver
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
##### Packages version
|
||||
@@ -112,14 +116,14 @@ psycopg2 2.8.5
|
||||
|
||||
###### Build C extension
|
||||
```
|
||||
cd ~/bioprorelife/python/biopro/ext/
|
||||
cd ~/wisetopdataserver/python/biopro/ext/
|
||||
rm -rf *.so build
|
||||
python3 setup.py build_ext --inplace
|
||||
```
|
||||
|
||||
###### Check setup-uart file
|
||||
```
|
||||
cd ~/bioprorelife
|
||||
cd ~/wisetopdataserver/
|
||||
sudo vim ./run-setup-uart.sh
|
||||
```
|
||||
##### Modify the code as following
|
||||
@@ -149,44 +153,72 @@ sudo raspi-config
|
||||
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:
|
||||
###### add the code following as:
|
||||
```
|
||||
sudo -H -u pi nohup /home/pi/bioprorelife/run-data-server.sh > /home/pi/.data_server.out &
|
||||
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
|
||||
```
|
||||
###### 1.Install mosquitto
|
||||
$sudo apt-get install mosquitto mosquitto-clients
|
||||
|
||||
|
||||
###### 2.Enable Remote Access
|
||||
$sudo vim /etc/mosquitto/conf.d/default.conf
|
||||
|
||||
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
|
||||
```
|
||||
restart mqtt broker
|
||||
```
|
||||
sudo systemctl restart mosquitto
|
||||
```
|
||||
###### 3.restart mqtt broker
|
||||
$sudo systemctl restart mosquitto
|
||||
|
||||
3. Robust MQTT
|
||||
###### 4.Robust MQTT
|
||||
create mosquitto_restart.sh
|
||||
```
|
||||
cd ~
|
||||
sudo vim mosquitto_restart.sh
|
||||
```
|
||||
|
||||
$cd ~
|
||||
$sudo vim mosquitto_restart.sh
|
||||
|
||||
|
||||
add the code following as:
|
||||
```
|
||||
if [ "`ps -aux | grep /usr/sbin/mosquitto | wc -l`" == "1" ]
|
||||
@@ -200,25 +232,129 @@ fi
|
||||
echo "$SERVICE is currently running" >> /home/ubuntu/cron.log
|
||||
exit 0
|
||||
```
|
||||
add mosquitto_restart.sh to root routing
|
||||
```
|
||||
sudo chmod +x mosquitto_restart.sh
|
||||
sudo -i
|
||||
crontab -e
|
||||
```
|
||||
###### 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
|
||||
```
|
||||
3. Auto run MQTT broker when when pi-start
|
||||
```
|
||||
sudo vim /etc/rc.local
|
||||
```
|
||||
###### 6.Auto run MQTT broker when when pi-start
|
||||
$sudo vim /etc/rc.local
|
||||
|
||||
add the code following as:
|
||||
```
|
||||
sudo nohup systemctl restart mosquitto
|
||||
```
|
||||
|
||||
### Setup routed wireless access point
|
||||
### 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
|
||||
|
||||
|
||||
### Set web site
|
||||
$sudo vim ./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
|
||||
|
||||
@@ -1130,7 +1130,8 @@ class CompletedDevice(Device):
|
||||
self._master.log_warn('on_change instruction not found : ' + on_change)
|
||||
|
||||
else:
|
||||
self.call_instruction(on_change)
|
||||
if self._status == 1:
|
||||
self.call_instruction(on_change)
|
||||
|
||||
# device instruction call
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ class DataBaseProcess(Process):
|
||||
|
||||
self._data_raw_create_sql_str = None
|
||||
self._data_raw_update_sql_str = None
|
||||
self._data_raw_recording_sql_str = 'UPDATE "public"."%s_recording_data_raws" SET data = concat(data, %s), end_time=%s, size=%s where id = %s'
|
||||
self._data_raw_recording_sql_str = 'UPDATE "public"."%s_recording_data_raws" SET data = concat(data, %s) where id = %s'
|
||||
self._new_data_raw_recording_sql_str = 'UPDATE "public"."%s_recording_data_raws" SET data = concat(data, %s), end_time=%s, size=%s where id = %s'
|
||||
self._data_mini_recording_sql_str = 'UPDATE "public"."%s_recording_data_minis" SET data_mean = concat(data_mean, %s) where id = %s'
|
||||
|
||||
@property
|
||||
@@ -384,7 +385,7 @@ class DataBaseProcess(Process):
|
||||
para_list.append([_channel, _data_dict[_channel] + '"***"', _end_time_dict[_channel], _size_dict[_channel], _id_dict[_channel]])
|
||||
with self._psql_conn as conn:
|
||||
with conn.cursor() as sql_cursor:
|
||||
execute_batch(sql_cursor, self._data_raw_recording_sql_str, para_list)
|
||||
execute_batch(sql_cursor, self._new_data_raw_recording_sql_str, para_list)
|
||||
except psycopg2.Error as e:
|
||||
print('recording error', e)
|
||||
return None
|
||||
|
||||
@@ -1219,9 +1219,18 @@
|
||||
],
|
||||
"pul_sen_start": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"pa": "ADC_LEVEL_I_15",
|
||||
"pb": "ADC_LEVEL_V_IN_15",
|
||||
"pc": "DAC_LEVEL_V_OUT_15",
|
||||
"pd": "CTRL_HIGH_Z_15",
|
||||
"pe": "SAMPLE_RATE"
|
||||
},
|
||||
"data": [
|
||||
"1X0D;",
|
||||
"1XFF"
|
||||
"1XFF",
|
||||
"4b>pa;4b>pb;",
|
||||
"4b>pc;4b>pd"
|
||||
]
|
||||
},
|
||||
"pul_sen_segment_0": {
|
||||
@@ -1365,9 +1374,18 @@
|
||||
},
|
||||
"dpv_auto_mode_ins_final": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"pa": "ADC_LEVEL_I_15",
|
||||
"pb": "ADC_LEVEL_V_IN_15",
|
||||
"pc": "DAC_LEVEL_V_OUT_15",
|
||||
"pd": "CTRL_HIGH_Z_15",
|
||||
"pe": "SAMPLE_RATE"
|
||||
},
|
||||
"data": [
|
||||
"1X0E;",
|
||||
"1XFF"
|
||||
"1XFF;",
|
||||
"4b>pa;4b>pb;",
|
||||
"4b>pc;4b>pd"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1437,9 +1455,18 @@
|
||||
},
|
||||
"dpv_advanced_mode_ins_final": {
|
||||
"type": "RIS",
|
||||
"parameter": {
|
||||
"pa": "ADC_LEVEL_I_15",
|
||||
"pb": "ADC_LEVEL_V_IN_15",
|
||||
"pc": "DAC_LEVEL_V_OUT_15",
|
||||
"pd": "CTRL_HIGH_Z_15",
|
||||
"pe": "SAMPLE_RATE"
|
||||
},
|
||||
"data": [
|
||||
"1X10;",
|
||||
"1XFF"
|
||||
"1XFF;",
|
||||
"4b>pa;4b>pb;",
|
||||
"4b>pc;4b>pd"
|
||||
]
|
||||
},
|
||||
"dpv_engineering_mode": [
|
||||
|
||||
Reference in New Issue
Block a user