saveString

I need to save some values for my server so that different scripts/devices can interact. Without the script, I would have a link that with some php I copied from the net would change a txt file content, but it is pretty limitate as it has to reload every time the page; Is there a way to save some variables then? I tried saveStrings in javascript mode in local but it does nothing.

Answers

  • saveStrings won't work in Javascript mode, as browsers do not have permission to access file system. So you either need to create a request and make php to do the job, or if you can use Java Mode you can use a network library and create a server side sketch that would do it for you. I do not know about other options.

  • So there is no direct way to save data for later usege? I've searched Google but most results are about cookies, which is the opposite of what i'm looking for; anyway how should that php work? As I said my old script opened a link that triggered the php part,but honestly as of now the whole server making process seems magic to me.

  • Submitting data via POST/GET to a script on the server (as you already appear to have tried) is the most straightforward approach; but can be slow. It could be quicker if you were feeding into a database rather than writing to a text file; which isn't going to handle simultaneous connections at all...

    If you need really fast data throughput then a websocket connection would be the best option.

    The best approach depends on how quickly you need to apply updates; and from how many inputs... You need to clarify your requirements: it's not clear what devices will be connected and how etc...

  • no,speed isn't a problem. I'm probably going to write once every 5 seconds, a few lines of 0 and 1s and probably 6 devices at most connected at the same time(not necessarily writing though); Writing to a database could have been a good idea, but I'm afraid that some of the devices I'm using don't support them; What vould happen if the file was written by two scripts in the same moment? would it cause errors or just save the last one?The last one wouldn't be a problem.

    So as you are suggesting POST/GET as I've already done that; the problem is that I did something that somehow worked, but I've actually no idea how i did it. Also while messing with processing javaScript I deleted accidentally the old "working" script, so I'm gonna have to start from zero.

  • Sounds like a PHP script could do what you want then. You just need all attached devices to be able to generate a GET or POST request (depends on you script and requirements) containing the data you want stored on the server and to pass this to a URL where your PHP script sits. It should then process the form submission and write to the text file.

    Alternatively if you'e running Processing on the server the Simple HTTP Server library might allow you to get data straight into your sketch...

Sign In or Register to comment.