diff --git a/install.sh b/install.sh index b63860c8553c9903be2aa8f88bc02f0adc1e05fa..23f8c6649d54481ef5425f778d05ca1e15715293 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,14 @@ #!/bin/bash +echo "=========== OhmPi installation script v1.0.0 ==========" + +echo "--------- Installing additional libraries via apt --------" + # ensure that the libatlas-base-dev library is installed sudo apt-get install -y libatlas-base-dev libopenblas-dev +echo "----------- Creating virtual python environment ----------" + # Create the virtual environment python3 -m venv ohmpy @@ -15,10 +21,14 @@ export CFLAGS=-fcommon # install all required packages in the virtual environment. pip install -r requirements.txt +echo "----------- Setting RPi parameters (I2C, GPIO, ...) --------" + # install a second i2c bus 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 "-------------- Install local MQTT broker --------------" + # install local mqtt broker txtred='\e[0;31m' # Red txtgrn='\e[0;32m' # Green @@ -33,10 +43,15 @@ echo -e "\n${txtgrn}>>> Broker is installed. Starting now...${txtdef}" mosquitto -v 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 9001" | 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 "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}" + cat /etc/mosquitto/mosquitto.conf + +echo "------------- Create config.py file -----------" + +python setup_config.py diff --git a/ohmpi/config.py b/ohmpi/config.py index 40665972ec78fcbb165cf92d2b3b5fb2fe617836..54dd5b25f1f36fdce31e9d72b5f2009855105a3a 100644 --- a/ohmpi/config.py +++ b/ohmpi/config.py @@ -21,51 +21,51 @@ r_shunt = 2. HARDWARE_CONFIG = { 'ctl': {'model': 'raspberry_pi'}, 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, - 'tx': {'model': 'mb_2023_0_X', - '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] - 'r_shunt': r_shunt, # Shunt resistance in Ohms - 'interface_name': 'i2c' - }, - 'rx': {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V - 'sampling_rate': 50., # number of samples per second - 'interface_name': 'i2c', - }, + 'tx': {'model': 'mb_2023_0_X', + '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] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2023_0_X', + 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V + 'sampling_rate': 50., # number of samples per second + 'interface_name': 'i2c', + }, 'mux': # default properties given in config are system properties that will be - # 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 - # omitted properties in config will be set to board specs default values if they exist - {'boards': - {'mux_A': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x70, - 'roles': {'A': 'X'}, - 'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_B': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x71, - 'roles': {'B': 'X'}, - 'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_M': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x72, - 'roles': {'M': 'X'}, - 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_N': - {'model': 'mux_2023_0_X', - 'mux_tca_address': 0x73, - 'roles': {'N': 'X'}, - 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, - 'voltage_max': 12.}, - }, - 'default': {'interface_name': 'i2c', - 'voltage_max': 12., - 'current_max': 3.} - } + # 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 + # omitted properties in config will be set to board specs default values if they exist + {'boards': + {'mux_A': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x70, + 'roles': {'A': 'X'}, + 'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_B': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x71, + 'roles': {'B': 'X'}, + 'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_M': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x72, + 'roles': {'M': 'X'}, + 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, + 'voltage_max': 12.}, + 'mux_N': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x73, + 'roles': {'N': 'X'}, + 'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)}, + 'voltage_max': 12.}, + }, + 'default': {'interface_name': 'i2c', + 'voltage_max': 12., + 'current_max': 3.} + } } # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS diff --git a/setup_config.py b/setup_config.py new file mode 100644 index 0000000000000000000000000000000000000000..c92871d43fe062481a4fc13e3c7853a458240433 --- /dev/null +++ b/setup_config.py @@ -0,0 +1,36 @@ + +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') + +