diff --git a/configure_second_I2C_bus.sh b/configure_second_I2C_bus.sh old mode 100644 new mode 100755 diff --git a/create_ohmpi_virtual_environment.sh b/create_ohmpi_virtual_environment.sh deleted file mode 100755 index f5bc4cbdca75346e225a992f1b21aae2e8a4b5b5..0000000000000000000000000000000000000000 --- a/create_ohmpi_virtual_environment.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# ensure that the libatlas-base-dev library is installed -sudo apt-get install -y libatlas-base-dev - -# Create the virtual environment -python3 -m venv ohmpy - -# Activate it -source ohmpy/bin/activate || exit 1 # NOTE: Added || exit to avoid installing requirements in system python if the virtual environment can't be loaded - -# Solve issues associated to storage allocation -export CFLAGS=-fcommon - -# install all required packages in the virtual environment. -pip install -r requirements.txt - diff --git a/dev/start_mqtt_html.py b/dev/start_mqtt_html.py index 32b95cce806d1898b33c200150dbb670e149ce07..5c846e5fe08e5e44c17a0c378b4c02b28572f3eb 100644 --- a/dev/start_mqtt_html.py +++ b/dev/start_mqtt_html.py @@ -7,7 +7,7 @@ import subprocess from ohmpi.utils import change_config #change_config('../configs/config_mb_2023.py', verbose=False) -change_config('../configs/config_mb_2023_4_mux_2023.py', verbose=False) +change_config('../configs/config_mb_2024_0_2__4_mux_2023_dps5005.py', verbose=False) from ohmpi.ohmpi import OhmPi from ohmpi.config import OHMPI_CONFIG diff --git a/dev/test_mb_2024_4_mux_2023.py b/dev/test_mb_2024_4_mux_2023.py index ceceb8041908281afe7c1c9df930dc63aad601f1..bc1c87b7bd96e6de43e7ae2776d75c4dc152f5cd 100644 --- a/dev/test_mb_2024_4_mux_2023.py +++ b/dev/test_mb_2024_4_mux_2023.py @@ -7,9 +7,9 @@ import time import logging from ohmpi.config import HARDWARE_CONFIG -stand_alone = True +stand_alone = False part_of_hardware_system = False -within_ohmpi = False +within_ohmpi = True # Stand alone if stand_alone: @@ -96,12 +96,12 @@ if within_ohmpi: # k._hw.switch_mux([A, B, M, N], state='off') # print(f'OhmPiHardware Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings() - k.load_sequence('sequences/9991_GRAD_16_s1_a1.txt') + k.load_sequence('sequences/test_circuit_1423.txt') k.run_sequence(tx_volt=5, injection_duration=1., nb_stack=2, duty_cycle=0.5) print('using OhmPi') #d = k.run_measurement([A, B, M, N], injection_duration=1., nb_stack=2, duty_cycle=0.5) - # print(d) - # k._hw._plot_readings() + #print(d) + #k._hw._plot_readings() print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings(save_fig=False) diff --git a/install.sh b/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..f9835d0c3d4352a0a901b10d71c25b34e76904b2 --- /dev/null +++ b/install.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# ensure that the libatlas-base-dev library is installed +sudo apt-get install -y libatlas-base-dev libopenblas-dev + +# Create the virtual environment +python3 -m venv ohmpy + +# Activate it +source ohmpy/bin/activate || exit 1 # NOTE: Added || exit to avoid installing requirements in system python if the virtual environment can't be loaded + +# Solve issues associated to storage allocation +export CFLAGS=-fcommon + +# install all required packages in the virtual environment. +pip install -r requirements.txt + +# 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 + +# install local mqtt broker +txtred='\e[0;31m' # Red +txtgrn='\e[0;32m' # Green +txtylw='\e[0;33m' # Yellow +txtdef='\e[0;0m' # Default + +echo -e "${txtgrn}>>> Updating system and installing MQTT broker...${txtdef}" +sudo apt install -y mosquitto mosquitto-clients +sudo systemctl enable mosquitto.service + +echo -e "\n${txtgrn}>>> Broker is installed. Starting now...${txtdef}" +mosquitto -v + +echo -e "\n${txtgrn}>>> Updating configuration to allow anonymous remote connections...${txtdef}" +echo "listener 1883" | 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 -e "\n${txtylw}>>> Adapt it according to your needs!${txtdef}\n" diff --git a/ohmpi/config.py b/ohmpi/config.py index 40665972ec78fcbb165cf92d2b3b5fb2fe617836..abba800afd622de78efddc9ff8fb62855863ab22 100644 --- a/ohmpi/config.py +++ b/ohmpi/config.py @@ -1,6 +1,5 @@ import logging from ohmpi.utils import get_platform - from paho.mqtt.client import MQTTv31 # noqa _, on_pi = get_platform() @@ -20,23 +19,20 @@ OHMPI_CONFIG = { r_shunt = 2. HARDWARE_CONFIG = { 'ctl': {'model': 'raspberry_pi'}, - 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, - 'tx': {'model': 'mb_2023_0_X', + 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, + 'tx': {'model': 'mb_2024_0_2', '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', + 'rx': {'model': 'mb_2024_0_2', + 'coef_p2': 1.00, # slope for conversion for ADS, measurement in V/V + 'latency': 0.010, # latency in seconds in continuous mode + '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': {'boards': {'mux_A': {'model': 'mux_2023_0_X', 'mux_tca_address': 0x70, @@ -55,23 +51,23 @@ HARDWARE_CONFIG = { 'roles': {'M': 'X'}, 'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)}, 'voltage_max': 12.}, - 'mux_N': + '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., + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 100., 'current_max': 3.} - } -} + } + } # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # Execution logging configuration EXEC_LOGGING_CONFIG = { - 'logging_level': logging.INFO, # TODO: set logging level back to INFO + 'logging_level': logging.INFO, 'log_file_logging_level': logging.DEBUG, 'logging_to_console': True, 'file_name': f'exec{logging_suffix}.log',