Hi,
Is there a query by which we can get the list of measurements for each of the devices in openHistorian?
Thanks and regards,
Dattatreya
You can do this with a SQL query:
For all measurement records by device:
SELECT * FROM ActiveMeasurement ORDER BY Device
For a particular device:
SELECT * FROM ActiveMeasurement WHERE Device = 'SHELBY'
Is this what you are asking?
If you are using the openHistorian Python code, the metadata can already be filtered by device.
Thanks,
Ritchie
Hi Ritchie,
This is exactly what I tried but I am not getting any output. Can you provide me with the Python equivalent of this?
Thanks,
Datta
# Connect to historian
# code omitted for brevity, see: https://pypi.org/project/openhistorian/
# Get a reference to the openHistorian metadata cache
historian.RefreshMetadata()
metadata = historian.Metadata
device = metadata.LookupDeviceByAcronym("SHELBY")
deviceMeasurements = device.Measurements
Thanks Ritchie for the reference
Hi Ritchie,
I am getting an error while executing the code. For executing this code which methods do we need to import?
I expect something like this:
from openHistorian.historianConnection import historianConnection
from openHistorian.historianInstance import historianInstance
from openHistorian.metadataCache import metadataCache
from openHistorian.deviceRecord import deviceRecord
from openHistorian.measurementRecord import measurementRecord
Hi Ritchie,
This is my code and this is the error that I am getting:
from openHistorian.historianConnection import historianConnection
from openHistorian.historianInstance import historianInstance
from openHistorian.historianKey import historianKey
from openHistorian.historianValue import historianValue
from openHistorian.metadataCache import metadataCache
from openHistorian.measurementRecord import SignalType, measurementRecord
from openHistorian.deviceRecord import deviceRecord
from snapDB.timestampSeekFilter import timestampSeekFilter
from snapDB.pointIDMatchFilter import pointIDMatchFilter
from snapDB.enumerations import QualityFlags
from gsf import Ticks
from typing import Optional, List
from datetime import datetime, timedelta
from time import time
import numpy as np
import math
import pandas as pd
import itertools
import smtplib
from email.message import EmailMessage
def readTest():
# Create historian connection (the root API object)
historian = historianConnection("localhost")
instance: Optional[historianInstance] = None
try:
print("Connecting to openHistorian...")
historian.Connect()
if not historian.IsConnected or len(historian.InstanceNames) == 0:
print("No openHistorian instances detected!")
else:
# Get first historian instance
initialInstance = historian.InstanceNames[0]
print(f"Opening \"{initialInstance}\" database instance...")
instance = historian.OpenInstance(initialInstance)
key = historianKey()
value = historianValue()
# Get a reference to the openHistorian metadata cache
historian.RefreshMetadata()
metadata = historian.Metadata
device = metadata.LookupDeviceByAcronym("ECROWE")
deviceMeasurements = device.Measurements
print(deviceMeasurements)
except Exception as ex:
print(f"Failed to connect: {ex}")
finally:
if instance is not None:
instance.Dispose()
if historian.IsConnected:
print("Disconnecting from openHistorian")
historian.Disconnect()
if __name__ == "__main__":
readTest()
Error:
Failed to connect: ‘NoneType’ object has no attribute ‘Measurement’
If you remove the try/catch (or debug) can you determine on which line it is failing?
Hi Ritchie,
The error is in the following line:
deviceMeasurements = device.Measurements
AttributeError: ‘NoneType’ object has no attribute 'Measurements’
Ah, device was not found:
acronym = "SHELBY"
device = metadata.LookupDeviceByAcronym(acronym)
if device is not None:
deviceMeasurements = device.Measurements
else
raise RuntimeError(f"Failed to find device '{acronym}'")
Click on Edit
beside ECROWE
device and verify Acronym
Also, you should be able to enumerate device acronyms in Python metadata using print
to verify you are using correct acronym name.
The screen you are looking at sometimes will remove a subscription prefix like GEP!
for brevity.
Thanks,
Ritchie