Search code examples
phppythonodbcaspen

How to query data from an AspenTech IP21 Historian using PHP?


Is it possible to query data from InfoPlus 21 (IP21) AspenTech using php?

I am willing to create a php application that can access tags and historical data from AspenTech Historian.

Is ODBC my answer? Even thinking that is, I am not quite sure how to proceed.

UPDATE: I ended up using python and pyODBC. This worked like a charm! Thank you all for supporting.


Solution

  • As asked by @DaveTheAI, I am sharing how I solve the issue here:

    I was able to read data from AspenTech historians using pyODBC connector. At first you need to make sure that you have the required ODBC drivers installed (I am using Windows). Important point here is to have compatible drivers with your python/anaconda version: 32/64 bits

    After that:

    import pyodbc
    #---- Connect to IP21
    conn = pyodbc.connect("DRIVER={AspenTech ODBC driver for Production Record Manager};HOST=hostname;PORT=port")
    
    #---- Query string
    tag = 'YOUR_TAG'
    start = '2019-01-01 12:00:00'
    end = '2019-01-02 12:00:00'
    sql = "select TS,VALUE from HISTORY "\
            "where NAME='%s'"\
            "and PERIOD = 60*10"\
            "and REQUEST = 2"\
            "and REQUEST=2 and TS between TIMESTAMP'%s' and TIMESTAMP'%s'" % (tag, start, end)
    data = pd.read_sql(sql,conn) # Pandas DataFrame with your data!