Data acquisition
- class core.management.commands.readSensor.Command(stdout=None, stderr=None, no_color=False, force_color=False)
Bases:
BaseCommandMain commands for service worker wich reads sensor data and writes them to the database.
- check_for_init_request() bool
Check if a sensor initialization has been requested.
- Returns:
True is request has been registered, False otherwise.
- Return type:
bool
- check_init_db_entry() Init
Check if a Init db entry exists. Otherwise a new entry is created.
- Returns:
Updated or new generated initialization information
- Return type:
- check_measurement_db_entry() Measurement
Verify if a system state configuration entry is registered. If not, a new entry is generated.
- Returns:
System configuration state
- com_devices = None
- compute_measurement_data_average(data: dict) dict
Compute mean of sensor measurement results
- Parameters:
data (dict) – list of result entries
- Returns:
Averaged measurement values
- Return type:
dict
- create_measurement_result_entry() MeasurementData
Setup result object holding informaiton about a measurement run. A measurement name is assigned and extended by trailing numbers to ensure uniqueness.
- Returns:
Model instance of new result entry
- Return type:
- ftdi_setups = None
- static gen_color(n=200)
Get a random color with (r/g/b)>n
- getFTDIcount() int
Get number of FTDI
- Returns:
Number of FTDI devices connected to the host system.
- Return type:
int
- getMQTT() MQTTClient
Use MQTT information to establish a connection to a MQTT broker
- Returns:
Client communication interface or if connection failed None.
- Return type:
MQTTClient or None
- get_MUX_ADDRESS_LIST() list
Read all available mux port addresses and convert to list of hex string.
- Retruns:
list[str]: List of hexadecimal strings
- get_sensor_data(dev, state, result) dict
Read data from measurement device. It has to be distinguished between different communication interfaces.
- handle(*args, **options)
The actual logic of the command. Subclasses must implement this method.
- help = 'Reading sensor data and sending to the database'
- initComDevices(comports: list[str]) bool
Initialize devices connected to comports i.e /dev/ttyUSB0
- Parameters:
comports (list[str]) – List of comport paths.
- Returns:
True if sensors were detected, False otherwise
- Return type:
bool
- initFTDI() bool
Initialize FTDI devices and scan for sensors.
- Returns:
True if sensors were detected, false if detection failed.
- Return type:
bool
- initialize_sensor(sensor, result) None
Assing measurement value model according to sensor type.
- label_all_sensors_unconnected()
Set all sensors to unconnected state.
- measurementScheduled(state: Measurement) bool
Check if measurement is currently scheduled.
- Parameters:
state (Measurement) – Current system state
- Returns:
True if measurement is scheduled, False otherwise
- Return type:
bool
- mqtt_client = None
- register_sensor(sensor) None
Write information accquired by driver module to system database.
- reset_measurement_info() None
Set number of connected sensors to 0 this causes the Quick start button to disappear.
- runMeasurement() None
Perfom a measurement while measurement is scheduled and not stopped. Information from sensors is requested and the results are written to the database.
- run_measurement(dev, state, result, mode) None
Check if a measurement has been requested and fetch values from each sensor. If sensors repond faster then requested by the measurement frequency additional values are acquired. An averaged value is returned that matches the meaurement frequency closely.
- sensor_obj = []
- setup_initialzation(dev, *args) None
Depending on the device type select an initialization procedure to check if the device presents one or more sensors and is working properly.
- store_data(data: dict, result: MeasurementData, mode: str) None
Write measurement data to database depending on the selected server mode old measurements are overwritten or a new database entry is generated.
- Parameters:
data (dict) – New measurement values
reult (MeasurementData) – Current measurement case entry
mode (str) – Data retention mode
- updateSensorCounts(state: Measurement) None
Evaluate KnownSensor entries and count sensors communicating via the supported protocols. Update the system state accordingly
- wait_for_db(t=1, mqtt_client=None)
Wait until database is accessbile
Measurement data export
Helper functions
- measurement_server.modules.helpers.get_all_referenced_units()
- measurement_server.modules.helpers.get_sensor_counts(data_query)
- measurement_server.modules.helpers.get_sensor_plot_information(ignore_plot_show=False)
- measurement_server.modules.helpers.isHex(string)