OMC-045 Datalog Format¶
The OMC-045 datalog format is used by a variety of Observator products including OMC-Data-Online. This page documents the API to log data using the OMC-045 Datalog Format. It is not explain the datalog format itself. See the Logger Data Format document for more information about the format itself.
Constructor¶
-
class
logging.
DataLog045
(system_id, substation)¶ Create a OMC045 datalog format object which can be used to log data to a file.
system_id
is the name of the system/productsubstation
is the name of the substation, which is important when multiple dataloggers are used in the same system/product
Methods¶
-
DataLog045.
add_sensor
(name, unit, tag) → SensorField¶ Add a sensor to the header of the file. A new sensor can’t be added logging is started(start function is called).
name
The name of the sensor. Is not allowed to contain\
and;
.unit
The data unit in which the data is logged. Is not allowed to contain\
and;
.tag
The tag of the sensor, also known as the parameter code, which is an abbreviation of the name. This should be unique and is not allowed to contain\
,;
or spaces.
-
DataLog045.
start
() → bool¶ Create a file with the current time in the name and start logging.
Return: True if the file is succesfully created and logging can be started. False if file couldn’t be created.
-
DataLog045.
stop
()¶ Stop logging to the file and close the file currently in use. The logging can be stopped and started again to create a new file with the current timestamp and resume logging.
-
DataLog045.
add_record
(sensor: SensorField, value: number)¶ Add a data record to the file associated to the sensor. When multiple records are received within a second they are logged on the same line.
sensor
The SensorField associated to this data record.value
The data to record, can be a integer or a float.
-
DataLog045.
sync
()¶ Synchronise the file by writing all the data in the buffer to the file.
SensorField Methods¶
The following methods are used to change the status field value of the sensor. This value is saved to the log with every call to
DataLog045.add_record()
.
-
SensorField.set_sensor_number(num: integer):
Sets the index number for this sensor that is used by the DataLog045. This is done automatically.
num
The index number to save.
-
SensorField.is_updated():
Set the ‘not updated’ bit to 0 indicating that the sensor value is updated atleast once.
-
SensorField.data_invalid(invalid: bool):
Set the data invalid bit to 1 or 0.
invalid
True to indicate that the data is invalid, False if data is valid.
-
SensorField.data_above_boundary():
Indicate that the data is above a certain boundary. Reset this status bit with
data_in_range()
.
-
SensorField.data_below_boundary():
Indicate that the data is below a certain boundary. Reset this status bit with
data_in_range()
.
-
SensorField.data_in_range():
Reset the data above/below boundary bits, indicating that the data is in range.
-
SensorField.watchdog_timeout(timed_out: bool):
Indicate that the sensor value is not received within the expected time period.
timed_out
True if the value is not received in time, False if it updated in time.
Example¶
The following code shows an example that logs the internal parameters to a log file, creating a new log file after logging 300 samples.
import logging
import obs
import omc048
log = logging.DataLog045("SYSTEM", "SUB_SYSTEM")
temp = log.add_sensor('Temperature', 'C', 'TPT1')
hum = log.add_sensor('Humidity', 'rh', 'HUM')
bat = log.add_sensor('Coin cell voltage', 'Volt', 'VBAT')
board = omc048.onboard_sensors()
log.start()
index = 0
while True:
index += 1
temperature = board.temp()
humidity = board.hum()
battery = board.vbat()
log.add_record(temp, temperature)
log.add_record(hum, humidity)
log.add_record(bat, battery)
obs.delay(1000)
if index > 300:
index = 0
log.stop()
log.start()