system.tag.queryTagHistory stops working when it runs as a gateway script

I am trying to get some duration on and count on info into some tags.

I tested some code off a button in a client screen and had success.

#get data
pump124hourtable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump130daytable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump224hourtable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump230daytable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump124hourDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump130dayDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump224hourDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump230dayDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
#run data through functions for counts
Pump124hourcount = shared.Trending.TotalStarts(pump124hourtable)
Pump130daycount = shared.Trending.TotalStarts(pump130daytable)
Pump224hourcount = shared.Trending.TotalStarts(pump224hourtable)
Pump230daycount = shared.Trending.TotalStarts(pump230daytable)
Pump124hourDuration = shared.Trending.RunningDuration(pump124hourDurationTable)
Pump130dayDuration = shared.Trending.RunningDuration(pump130dayDurationTable)
Pump224hourDuration = shared.Trending.RunningDuration(pump224hourDurationTable)
Pump230dayDuration = shared.Trending.RunningDuration(pump230dayDurationTable)

print Pump124hourcount
print Pump130daycount
print Pump224hourcount
print Pump230daycount
print Pump124hourDuration
print Pump130dayDuration
print Pump224hourDuration
print Pump230dayDuration

When I take the similar code in the gateway I am getting zeros as an output.

#get data
pump124hourtable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump130daytable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump224hourtable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump230daytable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="CountOn", returnFormat='Wide')
pump124hourDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump130dayDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 1/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump224hourDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=24, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
pump230dayDurationTable = system.tag.queryTagHistory(paths=['PumpStation/Pumps/Pump 2/RVSS Aux'], rangeHours=720, returnSize=-1, aggregationMode="DurationOn", returnFormat='Wide')
#run data through functions for counts
Pump124hourcount = shared.Trending.TotalStarts(pump124hourtable)
Pump130daycount = shared.Trending.TotalStarts(pump130daytable)
Pump224hourcount = shared.Trending.TotalStarts(pump224hourtable)
Pump230daycount = shared.Trending.TotalStarts(pump230daytable)
Pump124hourDuration = shared.Trending.RunningDuration(pump124hourDurationTable)
Pump130dayDuration = shared.Trending.RunningDuration(pump130dayDurationTable)
Pump224hourDuration = shared.Trending.RunningDuration(pump224hourDurationTable)
Pump230dayDuration = shared.Trending.RunningDuration(pump230dayDurationTable)
#write to tag
system.tag.write("[<provider>]PumpStation/Trending/Pump124hourCount",Pump124hourcount)
system.tag.write("[<provider>]PumpStation/Trending/Pump130dayCount",Pump130daycount)
system.tag.write("[<provider>]PumpStation/Trending/Pump224hourCount",Pump224hourcount)
system.tag.write("[<provider>]PumpStation/Trending/Pump230dayCount",Pump230daycount)
system.tag.write("[<provider>]PumpStation/Trending/Pump124hourDuration",Pump124hourDuration)
system.tag.write("[<provider>]PumpStation/Trending/Pump130dayDuration",Pump130dayDuration)
system.tag.write("[<provider>]PumpStation/Trending/Pump224hourDuration",Pump224hourDuration)
system.tag.write("[<provider>]PumpStation/Trending/Pump230dayDuration",Pump230dayDuration)

When I started breaking down the data in the gateway script it seemed like the gateway script was returning different data that when it was run on a button in the client.
from client: Dataset [25R ? 2C]
from gateway: com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset@17c40abc

Why is the function returning different data(apparently different data type) when called from client vs gateway?

so there were two issues in the code for the gateway.

I did not need to specify the tag provider when writing to the tag.

I did need to specify the historical tag provider when sending the tag path to the system.tag.queryTagHistory function.

4 Likes