Built using Elixir and Phoenix. Deployed using Nerves.
The competition was hosted on a Raspberry Pi Zero W with 3 LEDs. The goal was to get all three LEDs to light up.
- Figure out SSID and password to get on the same network as the RPi. Provided by hints on the spot.
- Find the IP of the RPi. Do a local scan or brute force search. The RPi responds to ping.
- Find the port of the webserver. Portscan or provided by hints
- Find the API at /api
- Follow the instructions on the API. Three questions needs to be answered. Each question lights up an LED.
- After all three questions are correctly answered, you get a 4 character code to verify you are a winner.
The hardware setup is a connection of 3 LEDs with resistors to protect the LEDs. The Fritzing file can be found here.
If you have never used Elixir, Phoenix and Nerves before, you need to install these on you computer first. In addition the setup uses Slack to notify the hosts on what is going on (including notifying winners), and timber.io to log system events and exceptions.
Elixir is the main language of this setup. Head over to https://elixir-lang.org and follow instructions there to install Elixir.
Phoenix framework is the webserver. Follow instructions at http://www.phoenixframework.org to install.
Nerves is used to bundle everything in a nice image to the SD card of the RPi. It wraps together the OS, runtime and your code in a package, and helps you burn the image to the SD card. Go to http://nerves-project.org to install.
The setup needs a Slack webhook to post notifications to. Follow the instructions on Slack to create a webhook. Use the URL in the config (described below).
The setup uses timber.io for logging. Head over to timber.io, sign up and get an API key. Use the API key in the config file (described below).
To avoid getting secret leaking to github (or any other source controls), you need to create the following file: /apps/firmware/config/prod.secret.exs
and fill in the blanks from the template below.
use Mix.Config
config :firmware, :wlan0,
ssid: "<WLAN SSID>",
psk: "<WLAN password>"
config :timber,
api_key: "<API key from timber.io>"
config :api, Api.Endpoint,
secret_key_base: "<random secure key - can reuse the one in confix.exs>"
config :api, :questions,
q1: "What is 1+1",
a1: 2,
q2: "What is 2+2?",
a2: 5,
q3: "What is the Answer to the Ultimate Question of Life, The Universe, and Everything?",
a3: 42
config :api, :slack,
url: "<url to slack webhook>"
With all the above in place, you can follow these steps to get up and running (instructions verified on MacOS, might differ on Windows):
- Go to the folder
/apps/firmware
- Set target (hardware type):
export MIX_TARGET=rpi0
- Set environment:
export MIX_ENV=prod
- Download dependecies:
mix deps.get
- Compile:
mix compile
- Generate firmware image:
mix firmware
- Plug in SD card to your computer
- Burn image to SD card:
mix firmware.burn
- Plug the SD card into the RPi
- Power up the RPi