main content

read data from a pi server -凯发k8网页登录

this example shows you how to read data from an osisoft™ pi server using the read method. the read capability of industrial communication toolbox™ for pi provides a variety of options and flexible ways to get the data from your server. running this example requires that an osisoft pi system is installed. the demo tags used in this example were provided by osisoft and may be downloaded from the following location:

the pi server is capable of storing decades of real-time data from hundreds of assets. the matlab® interface for the pi system leverages the system's asset framework (af) to access time series data of your assets.

create client/server connection and retrieve required tags

connect to a pi server using the function. in this example the windows computer name is used as the pi af server name. your situation may vary depending on pi system configuration.

host = getenv("computername");
client = piclient(host);

request a list of related to the asset of interest. for more detailed information see .

tagsturbine = tags(client, name = "osidemo_gu4 turbine*")
tagsturbine=17×1 table
                                               tags                                            
    ___________________________________________________________________________________________
    "osidemo_gu4 turbine.bearing temperature.c73204fa-e8f2-5513-1bc9-b5f097831d16"             
    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"               
    "osidemo_gu4 turbine.cooling water intake temperature.f987e786-7a17-5027-1492-0482f0ae04b9"
    "osidemo_gu4 turbine.cooling water output temperature.62d8d7be-2b82-53bc-09f1-660ffa00aa70"
    "osidemo_gu4 turbine.cooling water pressure output.7c04f479-ae18-5207-0690-514252308c5b"   
    "osidemo_gu4 turbine.hours since last maintenance.ec8ae125-0ae5-5d45-1de6-0643ffac4983"    
    "osidemo_gu4 turbine.lubricant oil intake temperature.7fc3f299-b6ee-5e2e-3e7b-ca4ca59a9d9c"
    "osidemo_gu4 turbine.lubricant oil output temperature.03c2ec47-7719-5f48-32b5-6c961d1a7912"
    "osidemo_gu4 turbine.lubricant oil pressure output.9dd81865-26b3-57fb-0791-bf7a3cfea158"   
    "osidemo_gu4 turbine.oil level.201c4312-8852-50be-1d8b-297c216712ec"                       
    "osidemo_gu4 turbine.total hours running.4438ad34-9e54-5075-1c76-19e3ac3fb728"             
    "osidemo_gu4 turbine.turbine vibration.e4c9f243-d5c9-5f5c-3b82-ed8076592ff9"               
    "osidemo_gu4 turbine.vane angle.3ddc1860-a9cc-54ee-2d41-595eb92fc677"                      
    "osidemo_gu4 turbine.water flow.cf5b9b79-af11-5637-2317-f518e59b0c9f"                      
    "osidemo_gu4 turbine.water in oil.562f483e-a814-5b11-3dd7-44b9735068ca"                    
    "osidemo_gu4 turbine.water ph intake.2f31c444-6f9a-5005-083c-db8531de4d07"                 
      ⋮

read latest value of tag

read the most recent recorded value of a tag using the method.

vibrationlatesttt = read(client, tagsturbine.tags(2))
vibrationlatesttt=1×3 timetable
              time                                                   tag                                         value    status
    _________________________    ____________________________________________________________________________    _____    ______
    21-december-2021 15:40:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.8      good 

read values over period of time

to read values over a period of time, you first define a period. for example, to read values of a tag over the last two days, use the daterange name-value pair to specify a starting datetime and ending datetime. set the start date to two days ago.

startdate = datetime("now") - days(2);

set the end date to now.

enddate = datetime("now");

use these to specify the starting datetime and ending datetime in your request.

vibrationtwodaystt = read(client, tagsturbine.tags(2), daterange = [startdate, enddate])
vibrationtwodaystt=559×3 timetable
              time                                                   tag                                         value    status
    _________________________    ____________________________________________________________________________    _____    ______
    19-december-2021 10:45:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.83      good 
    19-december-2021 10:50:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.86      good 
    19-december-2021 10:55:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    1.03      good 
    19-december-2021 11:00:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.85      good 
    19-december-2021 11:05:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.8      good 
    19-december-2021 11:10:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.88      good 
    19-december-2021 11:15:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.89      good 
    19-december-2021 11:20:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.89      good 
    19-december-2021 11:25:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.79      good 
    19-december-2021 11:30:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.88      good 
    19-december-2021 11:35:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.84      good 
    19-december-2021 11:40:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.7      good 
    19-december-2021 11:45:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    1.04      good 
    19-december-2021 11:50:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.83      good 
    19-december-2021 11:55:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.82      good 
    19-december-2021 12:00:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.74      good 
      ⋮

read all recorded values of a tag

to read all recorded values of a tag, it is useful to know when data recording began. you may use the earliest name-value pair to determine this.

vibrationearliesttt = read(client, tagsturbine.tags(2), earliest = true)
vibrationearliesttt=1×3 timetable
              time                                                   tag                                         value    status
    _________________________    ____________________________________________________________________________    _____    ______
    04-november-2021 20:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     nan      bad  

notice the value of this tag at the earliest recorded time is a nan. this is often the case for the first data point in a series as the pi server indicates a status of bad for this data point upon creation. you may take actions to exclude this from your data set if desired.

this earliest data point identifies the time of the first recorded value. you may now use this information to establish a starting datetime for your request.

startdate = datetime(vibrationearliesttt.time(1));

set the ending datetime to now.

enddate = datetime("now", timezone = "local");

depending on your system, this query may return a large amount of data. if you have an extensive history of data that makes this too slow or impractical, you may want to skip this step.

vibrationalltt = read(client, tagsturbine.tags(2), daterange = [startdate, enddate])
vibrationalltt=13171×3 timetable
              time                                                   tag                                         value    status
    _________________________    ____________________________________________________________________________    _____    ______
    04-november-2021 20:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     nan      bad  
    04-november-2021 20:30:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.72      good 
    04-november-2021 20:35:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.73      good 
    04-november-2021 20:40:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.86      good 
    04-november-2021 20:45:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.75      good 
    04-november-2021 20:50:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.73      good 
    04-november-2021 20:55:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.85      good 
    04-november-2021 21:00:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.83      good 
    04-november-2021 21:05:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.97      good 
    04-november-2021 21:10:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.77      good 
    04-november-2021 21:15:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.72      good 
    04-november-2021 21:20:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    1.02      good 
    04-november-2021 21:25:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.83      good 
    04-november-2021 21:30:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.89      good 
    04-november-2021 21:35:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.88      good 
    04-november-2021 21:40:00    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.95      good 
      ⋮

reduce dataset using linear interpolation provided by pi server

notice the large number of datapoints in the result of the previous step. you may reduce the dataset by using the interval name-value pair. for example the following read requests data with an interval of 30 minutes. the interval name-value pair requests the pi server to perform linear interpolation on recorded values and provide results at the specified interval.

vibrationinterpolatedtt = read(client, tagsturbine.tags(2), daterange = [startdate, enddate], interval = minutes(30))
vibrationinterpolatedtt=2247×3 timetable
              time                                                   tag                                          value     status
    _________________________    ____________________________________________________________________________    _______    ______
    04-november-2021 20:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"        nan     bad  
    04-november-2021 20:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.84713     good 
    04-november-2021 21:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.8386     good 
    04-november-2021 21:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.80423     good 
    04-november-2021 22:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.86857     good 
    04-november-2021 22:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.80717     good 
    04-november-2021 23:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.71863     good 
    04-november-2021 23:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.96133     good 
    05-november-2021 00:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.8542     good 
    05-november-2021 00:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"        0.8     good 
    05-november-2021 01:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.74573     good 
    05-november-2021 01:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.72857     good 
    05-november-2021 02:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.79997     good 
    05-november-2021 02:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"     0.8385     good 
    05-november-2021 03:25:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.79857     good 
    05-november-2021 03:55:43    "osidemo_gu4 turbine.bearing vibration.64a3ce99-f31e-593c-3e29-595f32095ce7"    0.74147     good 
      ⋮

cleanup

when you are finished working with the pi server, disconnect and remove the client by clearing its variable from the workspace.

clear client;
网站地图