My understanding was that after building/flashing the file should be available to my app in tinker/priv/file.txt.
When I have:
defmodule Tinker.Config do
def configuration do
txt = :atomvm.read_priv("tinker", "file.txt")
:io.format(~c"~p~n", [:erlang.binary_to_list(txt)])
end
end
and run the app like:
defmodule Tinker do
@doc """
Application entry point.
"""
def start do
{ok, _Pid} = :logger_manager.start_link(%{log_level: :debug})
Tinker.Config.configuration()
end
I see garbled output (maybe not handling the binary correctly?).
Tried :tinker instead of “tinker” in the call to read_priv and some other things I don’t recall.
Help?
My idea was to read a file with simple config format e.g key:value on each line or the like and then parse it and use it later when configuring peripherals/services. Is this possible?
Two little problems here. The application name should be an atom, and your file name ”text.txt” does not match the name “secret.txt” that you indicated in the project directory.
They are all binaries - there is a bit of a learning curve, especially with how IO.inspect works…
E.g you see it output a binary <<104, 101, 108, 108, 111, 63, 10>>, but then when you split it, the binary now is outputable/presentable as a (elixir) string, and you get ["hello?", ""] - eg. try and input <<104, 101, 108, 108, 111, 63>> in an iex terminal and you’ll get back:
iex(1)> <<104, 101, 108, 108, 111, 63>>
"hello?"
but you will most likely encounter charlists elsewhere;-) - but mostly you’ll see binaries.
I was going to suggest the same, I have used this and it works great. In fact I plan on adding support for generating the NVS partition if an nvs-partition.cvs file is found in the top level of the esp32 directory to my (still in draft) PR for enhancements to the esp32 build system. This only works of course when building an image, so really only useful for VM developers, or people building custom images.
Perhaps rebar3 and mix tasked could be added, so users using release images could also benefit.
FYI, there are still examples the need to be updated, so you might see Elixir apps using the Erlang io module, but examvlib has an Elixir IO module you can use now ;-).