diff --git a/.dev/test_mb_2024_2_mux_2024.py b/.dev/test_mb_2024_2_mux_2024.py index dc4565eb84895514b6508818400431b398dba975..3c6e6fcd41a790f07e1f058210420a500d905791 100644 --- a/.dev/test_mb_2024_2_mux_2024.py +++ b/.dev/test_mb_2024_2_mux_2024.py @@ -1,15 +1,16 @@ import matplotlib matplotlib.use('TkAgg') from ohmpi.utils import change_config -change_config('../configs/config_mb_2024_0_2__2_mux_2024_dph5005.py', verbose=False) +#change_config('../configs/config_mb_2024_0_2__2_mux_2024_dph5005.py', verbose=False) import importlib import time import logging from ohmpi.config import HARDWARE_CONFIG +import numpy as np stand_alone = False -part_of_hardware_system = True -within_ohmpi = False +part_of_hardware_system = False +within_ohmpi = True # Stand alone if stand_alone: @@ -99,18 +100,19 @@ if within_ohmpi: # k._hw.rx._bias = -1.38 # print(f'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 = (1, 4, 2, 3) - # k._hw.switch_mux([A, B, M, N], state='on') + abmn = np.array([1, 4, 2, 3]) + 0 + k.switch_mux_on(abmn) # k._hw.vab_square_wave(12., cycle_duration=10., cycles=3) # 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() print('using OhmPi') - d = k.run_measurement([A, B, M, N], injection_duration=1., nb_stack=2, duty_cycle=0.5) + d = k.run_measurement(abmn, injection_duration=0.5, nb_stack=2, duty_cycle=0.5) + k.switch_mux_off(abmn) 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') + 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) # plot_exec_log('ohmpi/logs/exec.log') -change_config('../configs/config_default.py', verbose=False) +#change_config('../configs/config_default.py', verbose=False) diff --git a/index.html b/index.html index 2fb4799672f62ad0ca5b77206b85cedc8340e40d..3a742d82d6cca8abaa002426e163f77f63d46692 100755 --- a/index.html +++ b/index.html @@ -81,6 +81,7 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl <button id="restartBtn" type="button" class="btn btn-danger">Restart</button> <button id="shutdownBtn" type="button" class="btn btn-danger">Shutdown</button> + <button id="setTimeBtn" type="button", class="btn btn-secondary">Set Time</button> <!-- Modal for configuration --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> @@ -903,6 +904,17 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl } let restartBtn = document.getElementById('restartBtn') restartBtn.addEventListener('click', restartBtnFunc) + + // set time + function setTimeBtnFunc() { + d = new Date() + sendCommand('{"cmd": "set_time", "kwargs": {"date": "' + d.toISOString() + '"}}', + function(x) { + console.log('time set') + }) + } + let setTimeBtn = document.getElementById('setTimeBtn') + setTimeBtn.addEventListener('click', setTimeBtnFunc) // download data function downloadBtnFunc() { diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index a0a187e549c675c9c4ef50fe8c43d92b9e65dcf6..d07aa6d963e2d87f3c6a4c1e0cea3068ee50fd90 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -563,6 +563,19 @@ class OhmPi(object): self.exec_logger.info(f'Restarting pi following command {cmd_id}...') os.system('poweroff') # this may require admin rights + def set_time(self, date, cmd_id=None): + """Set date of the RPI remotely. + + Parameters + ---------- + date : str + ISO datetime string such as 2024-07-23T20:00:01.345Z. + cmd_id : str, optional + Unique command identifier. + """ + os.system('date --set ' + date) + self.exec_logger.info(f'New time set following command {cmd_id}...') + def plot_last_fw(self, save_fig=False, filename=None): """Plots last full waveform measurement