diff --git a/dev/start_mqtt_html.py b/dev/start_mqtt_html.py index 4c88810bbadc1b2f9fcf73a9f079bf7d6345b38b..0e7dd6cf67694ad0de19c613bd235af4b055fbce 100644 --- a/dev/start_mqtt_html.py +++ b/dev/start_mqtt_html.py @@ -3,15 +3,25 @@ # to message from the MQTT broker 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_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) +# start html interface +import subprocess +subprocess.Popen(['python', '-m', 'http.server']) + +# start ohmpi listener from ohmpi.ohmpi import OhmPi from ohmpi.config import OHMPI_CONFIG -ohmpi = OhmPi(settings=OHMPI_CONFIG['settings']) -if ohmpi.controller is not None: - ohmpi.controller.loop_forever() +k = OhmPi(settings=OHMPI_CONFIG['settings']) +import os +k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner16.txt')) +k.reset_mux() +#k.run_multiple_sequences(sequence_delay=20, nb_meas=3) + +if k.controller is not None: + k.controller.loop_forever() # restore default config change_config('../configs/config_default.py', verbose=False) diff --git a/dev/test_mb_2023_4_mux_2023.py b/dev/test_mb_2023_4_mux_2023.py index ca9c9c669028d077929a075488e37c40f928fb04..9dd195d0bfaa893fa836770444651d26431d5b0a 100644 --- a/dev/test_mb_2023_4_mux_2023.py +++ b/dev/test_mb_2023_4_mux_2023.py @@ -85,10 +85,10 @@ if within_ohmpi: print('Starting test with OhmPi.') k = OhmPi() # k.get_data() - k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner.txt')) - k.reset_mux() + # k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner16.txt')) + # k.reset_mux() # k.run_multiple_sequences(sequence_delay=20, nb_meas=3) - k.run_sequence(injection_duration=0.2) + # k.run_sequence(injection_duration=0.2) # k.rs_check(tx_volt=4) # k.test_mux(mux_id=None, activation_time=0.2) # k._hw.switch_mux([A, B, M, N], state='on') @@ -103,11 +103,11 @@ 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() - # A, B, M, N = (16, 13, 15, 14) + A, B, M, N = (17, 20, 18, 19) # A, B, M, N = (1, 4, 2, 3) - # d = k.run_measurement([A, B, M, N], injection_duration=0.5, nb_stack=2, duty_cycle=0.5) - # print(d) - # k._hw._plot_readings() + d = k.run_measurement([A, B, M, N], injection_duration=0.5, nb_stack=2, duty_cycle=0.5) + 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/index.html b/index.html index 88914ca66ea3ce37f1ac43f43d8eb224504ba276..99805072828a1187878bb6a598d9143ccec8105f 100755 --- a/index.html +++ b/index.html @@ -220,6 +220,12 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl // process data msg = payload // for accessing the variable from the console console.log('DATA LOG:', payload) + + // replace NaN values by null to make them acceptable for json parser + payload = payload.replace(/\bNaN\b/g, "null"); + payload = payload.replace(/\bnan\b/g, "null"); + + // parse to json let ddic = JSON.parse(payload.split('INFO:')[1]) // RS check data @@ -516,7 +522,6 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl // xpos.push((Math.min(ab, mn) + dist/2)*elec_spacing) // ypos.push(- (Math.sqrt(2)/2*dist)*elec_spacing) } - console.log('========', app, xpos, ypos) // update the trace and redraw the figure trace['x'] = xpos trace['y'] = ypos @@ -825,6 +830,10 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl output.innerHTML = 'Status: ' + x['status'] + ' (all data cleared)' console.log('all data removed') }) + data = {} + quads = [] + getData() + document.getElementById('quadSelect').innerHTML = '' } let removeDataBtn = document.getElementById('removeDataBtn') removeDataBtn.addEventListener('click', removeDataBtnFunc) diff --git a/ohmpi/config.py b/ohmpi/config.py index f3f566ba70a9fb3bf7797821b95578b28d48a232..0763f48ca2240311e01b281a1eea9571c324defd 100644 --- a/ohmpi/config.py +++ b/ohmpi/config.py @@ -1,7 +1,7 @@ import logging from ohmpi.utils import get_platform -from paho.mqtt.client import MQTTv31 # noqa +from paho.mqtt.client import MQTTv31 _, on_pi = get_platform() # DEFINE THE ID OF YOUR OhmPi @@ -17,36 +17,26 @@ OHMPI_CONFIG = { 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE } -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' + 'ctl': {'model' : 'dummy_ctl' + }, + 'tx' : {'model' : 'dummy_tx', + 'current_max': 4800 / 50 / 2, # Maximum current mA + 'r_shunt': 2, # Shunt resistance in Ohms + 'low_battery': 12. # Volts }, - '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': 'dummy_rx', }, - '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': {}, - 'default': {'interface_name': 'i2c', - 'voltage_max': 100., - 'current_max': 3.} - } + 'mux': {'model' : 'dummy_mux', + 'max_elec': 64, + '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.DEBUG, # 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', @@ -70,8 +60,8 @@ DATA_LOGGING_CONFIG = { # State of Health logging configuration (For a future release) SOH_LOGGING_CONFIG = { 'logging_level': logging.INFO, - 'logging_to_console': True, 'log_file_logging_level': logging.DEBUG, + 'logging_to_console': True, 'file_name': f'soh{logging_suffix}.log', 'max_bytes': 16777216, 'backup_count': 1024, diff --git a/run_http_interface.sh b/run_http_interface.sh index faa4924d61a7f83f76439c26130c3bdcd560a416..f80be4e3f91b765dd3b625978c37c0777f21cea0 100755 --- a/run_http_interface.sh +++ b/run_http_interface.sh @@ -1,5 +1,3 @@ export PYTHONPATH=`pwd` source $PYTHONPATH/ohmpy/bin/activate -python dev/start_mqtt_html.py & # run ohmpi.py to capture the commands -python -m http.server # run web GUI - +python dev/start_mqtt_html.py