Commit c7c1afb3 authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Modify install script + add a simple python setup for generating config.py

Showing with 96 additions and 45 deletions
+96 -45
#!/bin/bash #!/bin/bash
echo "=========== OhmPi installation script v1.0.0 =========="
echo "--------- Installing additional libraries via apt --------"
# ensure that the libatlas-base-dev library is installed # ensure that the libatlas-base-dev library is installed
sudo apt-get install -y libatlas-base-dev libopenblas-dev sudo apt-get install -y libatlas-base-dev libopenblas-dev
echo "----------- Creating virtual python environment ----------"
# Create the virtual environment # Create the virtual environment
python3 -m venv ohmpy python3 -m venv ohmpy
...@@ -15,10 +21,14 @@ export CFLAGS=-fcommon ...@@ -15,10 +21,14 @@ export CFLAGS=-fcommon
# install all required packages in the virtual environment. # install all required packages in the virtual environment.
pip install -r requirements.txt pip install -r requirements.txt
echo "----------- Setting RPi parameters (I2C, GPIO, ...) --------"
# install a second i2c bus # install a second i2c bus
sudo apt-get install -y i2c-tools sudo apt-get install -y i2c-tools
echo -e "[all]\ndtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=22,i2c_gpio_scl=23" | sudo tee -a /boot/config.txt echo -e "[all]\ndtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=22,i2c_gpio_scl=23" | sudo tee -a /boot/config.txt
echo "-------------- Install local MQTT broker --------------"
# install local mqtt broker # install local mqtt broker
txtred='\e[0;31m' # Red txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green txtgrn='\e[0;32m' # Green
...@@ -33,10 +43,15 @@ echo -e "\n${txtgrn}>>> Broker is installed. Starting now...${txtdef}" ...@@ -33,10 +43,15 @@ echo -e "\n${txtgrn}>>> Broker is installed. Starting now...${txtdef}"
mosquitto -v mosquitto -v
echo -e "\n${txtgrn}>>> Updating configuration to allow anonymous remote connections and websockets...${txtdef}" echo -e "\n${txtgrn}>>> Updating configuration to allow anonymous remote connections and websockets...${txtdef}"
echo "listener 9001" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo "listener 1883" | sudo tee -a /etc/mosquitto/mosquitto.conf echo "listener 1883" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo "listener 9001" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo "protocol websockets" | sudo tee -a /etc/mosquitto/mosquitto.conf echo "protocol websockets" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo "socket_domain ipv4" | sudo tee -a /etc/mosquitto/mosquitto.conf echo "socket_domain ipv4" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo "allow_anonymous true" | sudo tee -a /etc/mosquitto/mosquitto.conf echo "allow_anonymous true" | sudo tee -a /etc/mosquitto/mosquitto.conf
echo -e "\n${txtgrn}>>> Current configuration stored in /etc/mosquitto/mosquitto.conf is displayed below${txtdef}" echo -e "\n${txtgrn}>>> Current configuration stored in /etc/mosquitto/mosquitto.conf is displayed below${txtdef}"
cat /etc/mosquitto/mosquitto.conf cat /etc/mosquitto/mosquitto.conf
echo "------------- Create config.py file -----------"
python setup_config.py
...@@ -21,51 +21,51 @@ r_shunt = 2. ...@@ -21,51 +21,51 @@ r_shunt = 2.
HARDWARE_CONFIG = { HARDWARE_CONFIG = {
'ctl': {'model': 'raspberry_pi'}, 'ctl': {'model': 'raspberry_pi'},
'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},
'tx': {'model': 'mb_2023_0_X', 'tx': {'model': 'mb_2023_0_X',
'voltage_max': 50., # Maximum voltage supported by the TX board [V] 'voltage_max': 50., # Maximum voltage supported by the TX board [V]
'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] 'current_max': 4.80 / (50 * r_shunt), # Maximum voltage read by the current ADC on the TX board [A]
'r_shunt': r_shunt, # Shunt resistance in Ohms 'r_shunt': r_shunt, # Shunt resistance in Ohms
'interface_name': 'i2c' 'interface_name': 'i2c'
}, },
'rx': {'model': 'mb_2023_0_X', 'rx': {'model': 'mb_2023_0_X',
'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V
'sampling_rate': 50., # number of samples per second 'sampling_rate': 50., # number of samples per second
'interface_name': 'i2c', 'interface_name': 'i2c',
}, },
'mux': # default properties given in config are system properties that will be 'mux': # default properties given in config are system properties that will be
# overwritten by properties defined in each the board dict below. # overwritten by properties defined in each the board dict below.
# if defined in board specs, values out of specs will be bounded to remain in specs # if defined in board specs, values out of specs will be bounded to remain in specs
# omitted properties in config will be set to board specs default values if they exist # omitted properties in config will be set to board specs default values if they exist
{'boards': {'boards':
{'mux_A': {'mux_A':
{'model': 'mux_2023_0_X', {'model': 'mux_2023_0_X',
'mux_tca_address': 0x70, 'mux_tca_address': 0x70,
'roles': {'A': 'X'}, 'roles': {'A': 'X'},
'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)}, 'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)},
'voltage_max': 12.}, 'voltage_max': 12.},
'mux_B': 'mux_B':
{'model': 'mux_2023_0_X', {'model': 'mux_2023_0_X',
'mux_tca_address': 0x71, 'mux_tca_address': 0x71,
'roles': {'B': 'X'}, 'roles': {'B': 'X'},
'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)}, 'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)},
'voltage_max': 12.}, 'voltage_max': 12.},
'mux_M': 'mux_M':
{'model': 'mux_2023_0_X', {'model': 'mux_2023_0_X',
'mux_tca_address': 0x72, 'mux_tca_address': 0x72,
'roles': {'M': 'X'}, 'roles': {'M': 'X'},
'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)},
'voltage_max': 12.}, 'voltage_max': 12.},
'mux_N': 'mux_N':
{'model': 'mux_2023_0_X', {'model': 'mux_2023_0_X',
'mux_tca_address': 0x73, 'mux_tca_address': 0x73,
'roles': {'N': 'X'}, 'roles': {'N': 'X'},
'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)},
'voltage_max': 12.}, 'voltage_max': 12.},
}, },
'default': {'interface_name': 'i2c', 'default': {'interface_name': 'i2c',
'voltage_max': 12., 'voltage_max': 12.,
'current_max': 3.} 'current_max': 3.}
} }
} }
# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
......
print('This assistent helps you configure a basic system with a measurement board and from 0 to 4 mux of the same type. For more complex configuration with multiple mux of different types, please have a look in the configs/ folder.')
mb = None
while True:
if mb in ['v2023', 'v2024']:
break
else:
mb = input('Choose a measurement boards: [v2023/v2024]: ')
mux = None
while True:
if mux in ['v2023', 'v2024']:
break
else:
mux = input('Choose a mux boards: [v2023/v2024]: ')
nb_mux = None
while True:
if nb_mux in ['0', '1', '2', '3', '4']:
break
else:
nb_mux = input('Number of multiplexers: [0, 1, 2, 3, 4]: ')
config = 'config_mb_' + mb[1:] + '_' + nb_mux + '_mux_' + mux[1:] + '.py'
print('Using this configuration: ' + config)
import os
import shutil
if os.path.exists('configs/' + config):
shutil.copyfile('configs/' + config, 'ohmpi/config.py')
else:
print('configuration not found')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment