Commit 3e578f0c authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Add OhmPi.set_time() in case RPI running in AP mode without internet

Showing with 35 additions and 8 deletions
+35 -8
import matplotlib import matplotlib
matplotlib.use('TkAgg') matplotlib.use('TkAgg')
from ohmpi.utils import change_config 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 importlib
import time import time
import logging import logging
from ohmpi.config import HARDWARE_CONFIG from ohmpi.config import HARDWARE_CONFIG
import numpy as np
stand_alone = False stand_alone = False
part_of_hardware_system = True part_of_hardware_system = False
within_ohmpi = False within_ohmpi = True
# Stand alone # Stand alone
if stand_alone: if stand_alone:
...@@ -99,18 +100,19 @@ if within_ohmpi: ...@@ -99,18 +100,19 @@ if within_ohmpi:
# k._hw.rx._bias = -1.38 # 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') # 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() # k._hw._plot_readings()
A, B, M, N = (1, 4, 2, 3) abmn = np.array([1, 4, 2, 3]) + 0
# k._hw.switch_mux([A, B, M, N], state='on') k.switch_mux_on(abmn)
# k._hw.vab_square_wave(12., cycle_duration=10., cycles=3) # k._hw.vab_square_wave(12., cycle_duration=10., cycles=3)
# k._hw.switch_mux([A, B, M, N], state='off') # 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') # 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._hw._plot_readings()
print('using OhmPi') 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) print(d)
# k._hw._plot_readings() # 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'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) k._hw._plot_readings(save_fig=False)
# plot_exec_log('ohmpi/logs/exec.log') # plot_exec_log('ohmpi/logs/exec.log')
change_config('../configs/config_default.py', verbose=False) #change_config('../configs/config_default.py', verbose=False)
...@@ -81,6 +81,7 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl ...@@ -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="restartBtn" type="button" class="btn btn-danger">Restart</button>
<button id="shutdownBtn" type="button" class="btn btn-danger">Shutdown</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 --> <!-- Modal for configuration -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <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 ...@@ -903,6 +904,17 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl
} }
let restartBtn = document.getElementById('restartBtn') let restartBtn = document.getElementById('restartBtn')
restartBtn.addEventListener('click', restartBtnFunc) 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 // download data
function downloadBtnFunc() { function downloadBtnFunc() {
......
...@@ -563,6 +563,19 @@ class OhmPi(object): ...@@ -563,6 +563,19 @@ class OhmPi(object):
self.exec_logger.info(f'Restarting pi following command {cmd_id}...') self.exec_logger.info(f'Restarting pi following command {cmd_id}...')
os.system('poweroff') # this may require admin rights 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): def plot_last_fw(self, save_fig=False, filename=None):
"""Plots last full waveform measurement """Plots last full waveform measurement
......
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