I'm a beginner. My knowledge of PI is very limited. Get the list of stale and bad points from PI SMT 2012. How do I automate it ? What's the query to get the list of stale and bad tags?
The query is just looking at all tags which are defined to be stale or bad. By default, a tag is considered stale if its current value is older than 4 hours, and considered bad if it has a system digital state. These definitions are both configurable.
As to automation, where are we trying to automate it? What's the end goal, a list of stale and bad tags generated daily?
It may also be worthwhile to check out KB00384 on tools for monitoring stale data:
Have automated it by creating a bat file with the following commands
cd to PI\adm\
piconfig < showstalebadpitags.txt
@ostr tag,time, status
@select tag = * , time < '*-1h' and time > '*-1d'
Of course it has produced the output with the list of all the tags, time & status. What's the name of the field to add pointsource to the output file?
I need to add point source to the following statement:
@ostr tag, time, status
What's the exact field name for Point Source? (Tried as pointsource/ Point Source.....No luck).
The point source is an attribute of the PIPOINT table. I do not believe that you can extract data from multiple tables using the same output structure. So while you can access this information using "pointsource", you will not be able to easily output it as a fourth property of your current output structure.
A possible workaround if you would want to run this for particular point sources, you could use a script that exports all of the tags with a specific point source. Then, use this as an input file for the next script which uses that list of tags to generate the stale/bad list.
Have you tried using PI-OLEDB combined with SSRS to schedule a report?
Here is a sample VBScript code with PI-SDK calls that generates a text file with information of tags with bad values and stale tags:
' Output file preparation
Dim objFSO, objFSOText, objFolder, objFile
Dim strDirectory, strFile
strDirectory = "C:\PITxtFiles"
strFile = "\BadAndStaleTags_" & myDateFormat(Date) & "_" & myTimeFormat(Time) & ".txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Reference or create the Folder
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Set objFolder = objFSO.CreateFolder(strDirectory)
' Create the file
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
' PI data retrieval
Dim pisdk, srv, pt, pv
' Create the PI SDK object
Set pisdk = CreateObject("PISDK.PISDK")
' Open connection to server
Set srv = pisdk.Servers.DefaultServer
' Loop through the points of the server
For Each pt in srv.PIPoints
' Get current value
Set pv = pt.Data.Snapshot
' Check snapshot status
If pv.IsGood Then
' Check if difference between now and timestamp of snapshot is more than 1 hour (if it is, then we consider it a stale tag)
If (Now - pv.Timestamp.LocalDate) * 24 > 1 Then
' Write to file information of stale tag
objFile.WriteLine(pt.PointAttributes("pointsource") & ", " & pt.Name & ", " & pv.TimeStamp.LocalDate & ", " & pv.Value & ", Stale Tag")
' Write to file information of tag with bad value
objFile.WriteLine(pt.PointAttributes("pointsource") & ", " & pt.Name & ", " & pv.TimeStamp.LocalDate & ", " & pv.Value & ", Bad Value")
' Close the connection to the PI Server
' Close the file
' Auxiliary functions
' Function to generate string of date with desired format
d = WhatEver(Day(myDate))
m = WhatEver(Month(myDate))
y = Year(myDate)
myDateFormat= y & "-" & m & "-" & d
' Function to generate string of time with desired format
h = WhatEver(Hour(myTime))
m = WhatEver(Minute(myTime))
s = WhatEver(Second(myTime))
myTimeFormat= h & "-" & m & "-" & s
' Function to generate string of number always with two digits
I am trying to just look at a certain set of tags and I don't want to look at all of our tags, so how would I specify which tags I want to look at?
You can use PI-SDK or PI-OLEDB data access tools to get similar results as PI-SMT for bad and stale points. Here is the PI-OLEDB query
Ideally Daniel's VB Script & Venut's PI-OLEDB query are very useful. Thanks a lot Emma & Henlo as well...
Retrieving data ...