0

How to write to Canary from Ignition using script

Hi,

 

I am trying to write to Canary using the following code but it is not being written into and Ignition is also not throwing an error, can somoen help.

Not sure where I am going wrong, I have tried all 4 path formats but to no avail.

historyprovider = "techren 1 solar"
tagprovider = "default"
paths = ["1000/001/NV/0001/PCS/PCS001/INV1/CMB_01/CMB_Wp"]
#paths = ["[Stellar_Test/default:default]1000/001/NV/0001/PCS/PCS001/INV1/CMB_01/CMB_Wp"]
#paths = ["[Stellar_Test/default:default]Stellar_Test/1000/001/NV/0001/PCS/PCS001/INV1/CMB_01/CMB_Wp"]
#paths = ["[Stellar_Test/default:default]Site_Data/1000/001/NV/0001/PCS001/INV1_CMB_01/CMB_Wp"]
values = [245280]
qualities = [192]
ts = system.date.parse("2019-01-01 00:00:00","YYYY-MM-dd HH:mm:ss")
timestamps = [ts]
system.tag.storeTagHistory(historyprovider,tagprovider,paths, values, qualities, timestamps)

Thanks in advance

10 replies

null
    • christian_pionke
    • 1 yr ago
    • Reported - view

    Hey derrickdvdsn ,

    It looks like you are storing everything at the static timestamp "2019-01-01 00:00:00", is that correct?

      • derrickdvdsn
      • 1 yr ago
      • Reported - view

      christian. pionke yes,that is correct.

      • christian_pionke
      • 1 yr ago
      • Reported - view

      derrickdvdsn 
      I thought it was an issue with compression, but now I can see that's not what is going on here. The path does look like the only thing that could be wrong, the value, quality, and timestamp are all straightforward.
       

      Are you sure that path exists within "trechen 1 solar"? Your other references use "Stellar_Test" as the history provider. Can you attach a screenshot of the path tree with all the folders laid out?

      • derrickdvdsn
      • 1 yr ago
      • Reported - view

      christian. pionke 

      Just to clarify some points.

      1. "techren 1 solar" is the name of the Canary collector configured in the Ignition Gateway.

      2. "Stellar_Test" is the name of the dataset in canry where the raw tags are being stored to.

      3. "Site_Data" is the name of the view in canary.

      I am not sure what you mean by path tree but here is a screenshot of the paths in Ignition. The provider will show "Techren-1" because I am accessing it via a remote gateway but I am running the script local to the site gateway so the provider is "default" in the script.

      • christian_pionke
      • 1 yr ago
      • Reported - view

      derrickdvdsn 

      I think this might be a little beyond me, your Ignition configuration is more advanced than I have used before. It looks like your PCS001 has a "tag" icon, not sure if that's the problem.

      The only other thing I can think of is using the "getDate" and "setTime" function to write your timestamp like shown in the Ignition documentation. https://docs.inductiveautomation.com/display/DOC79/system.tag.storeTagHistory

      • derrickdvdsn
      • 1 yr ago
      • Reported - view

      christian. pionke 

       

      Thanks for trying to help, would it be possible to share a sample script of what you used and what Ignition version you used it on?

      • christian_pionke
      • 1 yr ago
      • Reported - view

      derrickdvdsn 

      Can't remember which version, but here's a bit of the code I wrote.

      for i in range(1,290):
          curSecond = system.tag.readBlocking(["[UH]Second/Second-"+str(i)])[0].value
          curMinute = system.tag.readBlocking(["[UH]Minute/Minute-"+str(i)])[0].value
          curHour = system.tag.readBlocking(["[UH]Hour/Hour-"+str(i)])[0].value
          curDay = system.tag.readBlocking(["[UH]Day/Day-"+str(i)])[0].value
          curMonth = system.tag.readBlocking(["[UH]Month/Month-"+str(i)])[0].value
          curYear = system.tag.readBlocking(["[UH]Year/Year-"+str(i)])[0].value
      
          dayTimestamp = system.date.getDate(2000+curYear, curMonth, curDay)
          curTimestamp = system.date.setTime(dayTimestamp, curHour, curMinute, curSecond)
      
          curStatus = system.tag.readBlocking(["[UH]Status/Status-"+str(i)])[0].value
      
          system.tag.storeTagHistory("billing pc", "UH", ["UH_DateStamp"], [dayTimestamp], [192], [curTimestamp])
          system.tag.storeTagHistory("billing pc", "UH", ["UH_TimeStamp"], [curTimestamp], [192], [curTimestamp])
      
          system.tag.storeTagHistory("billing pc", "UH", ["UH_Status"], [curStatus], [192], [curTimestamp])
      
      • derrickdvdsn
      • 1 yr ago
      • Reported - view

      christian. pionke Thanks  for sharing, can you clarify what "billing pc" is ? And is "UH_DateStamp" name of the tag?

      • christian_pionke
      • 1 yr ago
      • Reported - view

      derrickdvdsn 

      Sure! "billing pc" is the Canary collector in the Ignition gateway. UH_DateStamp is the tag name in Canary within the UH dataset.

    • smason
    • 1 yr ago
    • Reported - view

    With the help of IA support I was finally able to get this to work. The "paths" must be the Ignition path, not the path that Canary uses when providing data back to Ignition, which is "[CanaryProvider/default:default]...". And even though we only act as a historical provider, a realtime provider is still needed in the function. Here is the script I ended up using:

    historyprovider = "Local Ignition"
    tagprovider = "Sample"
    paths = ["Random/RandomInteger2"]
    values = [8]
    qualities = [192]
    date = system.date.getDate(2023, 10, 16)
    histDate = system.date.setTime(date, 10, 02, 44)
    dates = [histDate]
    system.tag.storeTagHistory("Local Ignition",tagprovider,paths,values,qualities,dates)
    

    "Local Ignition" is the collector I have configured in my module. "Sample" is the realtime provider, but it doesn't actually exist.  The "paths" are those as they appear in the Ignition schema.

    I used this as a reference: https://docs.inductiveautomation.com/display/DOC81/system.tag.storeTagHistory

Content aside

print this pagePrint this page
  • 1 yr agoLast active
  • 10Replies
  • 167Views
  • 3 Following