-
• #2
Works fine for me. Though I had to use settings1 as variable name because settings is already reserved for the settings of my watch face.
Maybe it is something similar for you? Is the settings variable already set to something before your code run?
EDIT: have you checked how many test.json files you have? Maybe it is related to this post?
-
• #3
I think it may be a mix of both.
I changed the settings variable in my app and widget and now saving works.
But at one time during testing, I really had two test.json files on the watch. -
• #5
Can you reproduce how it came to the two test.json files
Never happened again...
-
• #6
Can you reproduce how it came to the two test.json files?
Yes, if you ever can it'd be amazingly helpful in trying to find a fix!
-
• #7
So I could reproduce writing duplicate files with a mixture of
writeJSON
andwrite
Not sure it is what happened here and with the alarm app though, but maybe it is related:let set={"id":1,"test":2}; let sto=require("Storage"); sto.writeJSON("test.json",set); sto.write("test.json","test123"); sto.list("test.json"); =[ "test.json", "test.json" ] >sto.read("test.json") ="test123" >sto.readJSON("test.json") Uncaught SyntaxError: Expecting a valid value, got ID at line 1 col 8 test123 ^
So both
read
andreadJSON
then only can read the latter file. -
• #8
mixture of writeJSON and write
My code used this too.
I changed everything to writeJSON yesterday.
That could really be the culprit. -
• #9
Thanks for this! Although what firmware are you using? I just tried this on the KickStarter firmware and latest, and I get:
let set={"id":1,"test":2}; let sto=require("Storage"); sto.writeJSON("test.json",set); sto.write("test.json","test123"); sto.list("test.json"); =[ "test.json" ]
So it doesn't seem to reproduce it for me :(
-
• #10
VERSION: "2v05", GIT_COMMIT: "09aa0d84",
Strange indeed. I just tested it again with the same code and it did not work this time.
-
• #11
I was 100% sure yesterday, that my inital code worked before (stored the info to memory).
Then it stopped working, why I opened this thread.
With another app (Chrono Widget) I had to delete the JSON file from time to time or I would get strange behavior. Maybe something corrupt in the file or file system?
Loading the file it looked ok though. -
• #12
Thanks everyone! Got it!
Wow, that was painful.
s=require("Storage"); s.eraseAll(); s.write("a",new Uint8Array(4000)); s.write("b",new Uint8Array(100)); s.write("b",new Uint8Array(10));
Issue filed at https://github.com/espruino/Espruino/issues/1801 with a bit of explanation too
-
• #13
All fixed - if you install firmware from http://www.espruino.com/binaries/travis/master/
-
• #14
Yup... Can't reproduce the Alarms issue on v2.05.440 anymore. Nice!
-
• #15
Wohoo!
Hi,
I do not know why the JSON is not saved.
I am setting a variable
Then I store this to a JSON file
Then I change the variable
Then I store again
And reload
Why is the counter (settings2.counter) not stored? It is 0 after reload, not 12345.
This is the full code.
Thanks
Christian