Qqwy

Qqwy

TypeCheck Core Team

How to build a photobooth with Elixir+Nerves?

So, I finally have a good reason to start tinkering with Nerves! :heart:

I’ve been asked by the student association to jamble together a Photobooth for an upcoming party. So, I want to take this opportunity to write a Nerves-application on top of a Raspberry Pi.

I already found the Picam elixir/nerves library to take pictures with the Raspi’s camera. What I am still looking for is a way to interact with a (touch?)screen from within Elixir/Nerves, because I’d really like to show the camera preview on there.

Should I just go ahead and use the Erlang Wx-bindings for that? Or is there a better way?
And is there already a way to read out touch screen presses from within Nerves?

Most Liked

GregMefford

GregMefford

Cool project! @mobileoverlord and @electricshaman have spent a lot more time on the Le Tote kiosk system than I have, but I’m surprised that it doesn’t load content from localhost. Is it possible that the Phoenix server you’re running is not listening on the localhost interface or is blocking the page due to other security constraints? If you’re not sure, I’ve found it really helpful to remotely attach to the Chrome Remote Debugger from my laptop, so I can see the embedded browser’s error console and such. We have an internal way that we do that at Le Tote, but I don’t fully understand how it works myself, so I’ll defer to the others to explain that process.

In my experience, using a Plug-based MJPEG video streamer with Picam is significantly more performant than passing frames individually over a Phoenix Channel connection. I suspect it’s mostly the overhead of re-encoding the frames as Base64 and wrapping them in the Channel payload, because it’s slow even when you’re viewing it on a modern laptop.

When using MJPEG streaming to a laptop, I’m able to get smooth video performance even at 1080p, but I haven’t tried doing it locally in a kiosk the way you’re describing. I think the “right” way to do that is probably to avoid sending it through JavaScript at all, as you mentioned, but I think we’d need to add some more features to Picam to support that.

outlog

outlog

the camera is easy to hookup and interface.. I did one with phoenix/nerves and after the Drab boilerplate it took like 5 minutes to have it working - press a button, base64 it and show it in the browser.. (accessed from a desktop browser pointed at the phoenix server)

so you could do that, and then interface it from an ipad/laptop or similar.

you can then progress it with GitHub - nerves-web-kiosk/kiosk_system_rpi3: Nerves QtWebEngine Kiosk system for Raspberry Pi 3 · GitHub and a screen/touch interface running on the rpi itself..

so probably what I would recommend, you quickly have a working solution, and then you can progress that to running on the pi itself..

Qqwy

Qqwy

TypeCheck Core Team

It has been quite smooth sailing so far.

  1. Installing Phoenix on a Nerves system is a breeze.
  2. Working with the Raspberry Pi camera using Picam is quite easy.
  3. Using the Kiosk mode is okay, but you will really need the FTDI/UART to USB cable to debug it (since the screen will obv. only show the kiosk webpage).

Only (super minor) gotcha’s I’ve had are:

  1. My router does not seem to like Rpi’s, so connecting using WLAN is not possible over there (I now use my mobile phone as hotspot).
  2. The kiosk connects using the internet connection :nerves_network, :iface rather than whatever you’ve set up as default in your :nerves_network, :default configuration.
  3. The kiosk will only load a local page (like the local phoenix) when using IP address 0.0.0.0. I don’t know why but 127.0.0.1 and localhost will result in an ERR_NETWORK_CHANGE error page in the webkit kiosk browser.
  4. The Picam library has a nice example of streaming camera images to the browser using an mjpg stream. This works fine when connecting to the Pi with an outside device (and using that device’s browser), but the kiosk webkit variant will only load the first frame of the stream.

Currently I’m investigating other ways to load the camera feed as a ‘stream’. Now fetching individual images in an interval, although I think that sending JPGs over a persistent websocket connection (a Phoenix channel) might be faster.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New

We're in Beta

About us Mission Statement