jpunie

jpunie

Resolving image paths which are defined as constant/static in Scenic on Raspberry PI with Nerves

Hello,

While testing the scenic example in combination with Nerves on a RPi3 with a touchscreen, it became clear that the images where not rendering. At first I thought it would be related to the Scenic RPI driver, but this was not the case. Debugging of the path variables resulted in a clear path resolving issue at compile time.

When looking a the default splash.ex the parrot image is loaded as follows:

 @parrot_path :code.priv_dir(:scenic_example)
               |> Path.join("/static/images/scenic_parrot.png")
 @parrot_hash Scenic.Cache.Support.Hash.file!(@parrot_path, :sha)

:code.priv_dir(:scenic_example) will result with a path on my local file system, not on the target.

I had to fix/change this path issue with a config, but maybe this can be done in a more elegant way. My current workaround:

config/config.exs:

config :scenic_example, :priv_dir, "./_build/dev/lib/scenic_example/priv/"

config/rpi3.exs:

config :scenic_example, :priv_dir, "/srv/erlang/lib/scenic_example-0.1.0/priv"

splash.ex:

@parrot_file "/static/images/scenic_parrot.png"
@parrot_path Application.get_env(:scenic_example, :priv_dir)
               |> Path.join(@parrot_file)
@parrot_hash_path :code.priv_dir(:scenic_example)
               |> Path.join(@parrot_file)
@parrot_hash Scenic.Cache.Support.Hash.file!(@parrot_hash_path, :sha)

The hash has to be calculated at compile time using the file on my local filesystem, hence the double paths.

What would be a more elegant solution to solve this?
Also when the application will be versioned, the path in rpi3.exs has to be changed also, which could be an issue in the future.
Removing the static definitions is always an option, but I think in general the static definitions will work better and easier in the future.

Most Liked

axelson

axelson

Scenic Core Team

Hi @jpunie, indeed that is a known issue/annoyance when working with Scenic, especially when also using Nerves. I wouldn’t worry too much about an elegant way to solve this because Scenic 0.11 is coming soon and how assets work is being re-written, in part because of this specific issue.

Here’s some relevant info:

Hey all. Just pushed an update to v0.11 that refactors the way static assets are built. The main change you will need to make is that most of the config is now moved into the assets.ex module itself.The main benefit is that you can now have multiple asset sources that are merged into the final library. This allows deps to have assets that get pulled into the final application. While I was there, the library format is now a struct and accessing the contents has simplified and has more descriptive function names. The main one you will need to update is that Static.fetch is now Static.meta, which is a better name since it retrieves the metadata. Fetch was ambiguous.Now that we can have multiple asset sources, roboto.ttf and roboto_mono.ttf are moved back into scenic itself and don’t need to be carried by the apps.

defmodule Example.Assets do
  use Scenic.Assets.Static,
    otp_app: :poncho_scenic,
    sources: [
      "assets",
      {:scenic, "apps/scenic/assets"}
    ],
    alias: [
      parrot: "images/parrot.jpg"
    ]
end

The sources: list above will point to your local assets folder and the scenic assets by default if you don’t include it.The required config is now just

config :scenic, :assets, module: PonchoScenic.Assets

I believe @boydm is also actively looking for feedback on the assets setup for 0.11, although he may almost be ready to wrap up that portion of work.

jpunie

jpunie

Hi @axelson,

Great and very valuable feedback. I will look further into the provided info. Also a welcome reminder to keep following the Elixir Slack.

Looking forward to the v0.11 release.

Thank you for all the effort you put into your projects and the support given.

Where Next?

Popular in Questions Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement