Atomic File Reads and Writes/Calling Python script from app.js
Lastly, if this isn't a good way to achieve what I want should I instead use the H2 database? If so, I'm having trouble connecting to it. Do I need to change the blank username and password in env.properties file? The sql console works but the sql datasource isn't working for me. I'd also be interested to know how to query and publish to the sql database from code so that I can save and retrieve files, thanks.
You can create your own new java.io.FileOutputStream(new java.io.File("/path/to/file")) and write() to it.
Here's an example of someone using Java code in a script to read from a file, https://forum.infiniteautomation.com/topic/2970/is-it-possible-to-read-several-csv-documents-by-scripting
You do not need to change the blank username and password - your username and password are probably blank. Meaning, for the SQL data source you should be able to connect with the right driver (org.h2.Driver), the connection string in a similar syntax to the env.properties db.url as the path to your Mango/databases/mah2
Edit: I see now you probably meant scripting from the front end. The webpage definitely cannot access the file system, and the only way I can think of offhand to execute something like that would be the script-utils endpoint, which should give you the ability to submit a script for execution that could do the things discussed in the first part of this post. Or you can set relevant details to a context point that triggers a script.
Edit again: If all you need to do is trigger a python script, you can use a process event handler and set a value to a point that causes the event. You can use requests and the API in the python script to get the relevant information.
@avilla can you explain more what issue you are trying to solve. What kind of corruption are you trying to avoid and what kind of data are you trying to save?
Hi thanks for the reply.
I've now decided to use the built in h2 database to save and load my data. To answer your question @JoelHaggar the system is an automated temperature/vacuum chamber that needs to read and save some temperatures and voltages every time it runs a test. It will also need to load data from previous tests. The way I have it set up, each test will get its own row in the jsondata table. I was able to figure out how to insert and modify values into the JSONDATA table so saving files is done, but not how to load.
You can do that with the SQL Data Source. If you read the documentation available in the "?" icon it gives good examples of how to use it.
@joelhaggar I looked at that documentation and i figured out how to do everything except get a list of values for each row under the name column. I can only get info for the first column, whether I'm doing row or column based query.