Need to export a PLC tags every 2 seconds on JSON format. I need a good solution, any help will be appreciated.
A gateway timer
or schedule script using system.tag.exportTags should do it. I think the default type is JSON, if not you can set it to JSON.
Welcome to the forum!
Moisis, you probably want to export the tag values, right? system.tag.exportTags will only export the definitions. You can use system.tag.browse to access the value.
Then you can do some python magic to export to a JSON file. I tried but the object isn’t JSON serializable. I created another script that exports to a CSV file so I can backup and restore tag values. Is the JSON format important to you?
Yes, it is and as you said I need to use system.tag.browse and convert everything to python dict and then to json after that another script takes care of the “snapshot” files make it serializable and wrapping them for the data feed.
Are you sure you want to be exporting the tags every 2 seconds? Exports are for configuration, not just the values, and this is going to be a performance nightmare…
At that interval I can only assume what you’re really interested in are the tag values, which you should just be reading with
well, I’m exporting the tags but only interested in the following fields:
There is a scripts which deletes all old files to avoid running out of storage but, how can I improved the performance of this task?
What about enabling Tag History and store data every two seconds?
but then how I will feed the data to the uploading application? it must be in json format for the application to be able to transfer the data.
incendium.dataset.to_json might help you.
If you know the names of your tags, I’d recommend making a list and using system.tag.readBlocking().
If not, I’d recommend a separate script to construct the tag names and either store them in the db or into a dataset memory tag. This one wouldn’t have to run as often, as they shouldn’t change often.
readBlocking would still read your qualified tag values.
Or transaction group