If you are asking a question, please follow this template:
My goal is: To be able to download a string from an URL and save it persistent to the device in MJS. If the device reboots (electric outage), and the device has no internet connection, the firmware should be able to read the string from the last saved.
My actions are: I have tested FS.Put and FS.Get but I cannot find any function to decode base64 from the get file
The result I see is: Base64 encoded string which I cannot parse for what I need
My expectation & question is: Be be able to save a httpget string directly to a file or to be able to decode the string from FS.Get in RPC Local
Sounds like all you need is to call the JS equivalent to mgos_sys_config_set_yourvarname("string") to save the string, then call then call mgos_sys_config_get_yourvarname() to retrieve your string.
Just keen in mind that this will be stored in conf9.json and so will not survive factory reset (if you are using this feature)
In my experience the only reason to use the FS is when the strings become really large
The string (if saved as a file) weights 20Kb, that won’t fit into the config json file (have already tried).
I have done a call to a mDash RPC, which requests a get from an URL, then the body (which is already B64), call RPC.Local FS.Put, but I have memory errors, although the whole B64 string is less than 20Kb
Your firmware is using a lot of RAM. At the moment of the OOM error, there are ~188kB allocated.
You don’t need to use RPC calls to write files on the local filesystem. The standard fopen, fwrite, fclose can be used. If the original string is base64 encoded, you will need additional memory to decode it (~8/6*strlen(b64_string) IIRC). cs_base64_decode
Might be, because it is not a heavy use app`. It just opens a relay when an RPC method from mDash is received. But now I need some validations from a string. I think the best option is when I request the initial string, to divide it into chunks, and make a json file that list all this files, so later I can check it on every chunk.
From MJS how can we decode the B64 file (where I put the string)?. I will try to test the chunks now so I can reduce the RAM load.