Elixir/Nerves/Phoenix - A Pocket Webserver on a Raspberry Pi
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
firmware
ui
.gitignore
LICENSE.md
README.md
button-and-leds-circuit.png
dev.fish
env.fish-example
env.sh-example
thermometer-circuit.png

README.md

Pocket Web README

Based on Hello Phoenix from Nerves-Examples.

For Raspberry Pi 3

BREADBOARD CIRCUIT

  LEDS:
  
  <PIN 18>-----<BLUE  LED>----<220Ohm>----<GRD>
  <PIN 23>-----<GREEN LED>----<220Ohm>----<GRD>
  <PIN 24>-----<RED   LED>----<220Ohm>----<GRD>

  PUSH-BUTTON:

  <PIN 26>-----<10kOhm>---+---<10kOhm>----<+3V>
                          |
                          ----<BUTTON>----<GRD>

Pocket Web

Features

  • Set Blink Duration for Raspberry's build in LEDs
  • Switch on LEDs Blue, Green, and Red via Web-interface
  • Turn off all LEDs via Web-Interface
  • Web Interface shows state of color LEDs
  • Push button on breadboard turns all leds off when pressed
  • Push button on breadboard turns random leds on when released

First Setup and Burn SSD

  export MIX_ENV=prod
  export MIX_TARGET=rpi3
  export MIX_HOST=nerves.local
  export MIX_PORT=80
  export PORT-80

  cd ui
  mix deps.get
  cd assets
  npm install
  node_modules/brunch/bin/brunch build --production
  cd ..
  mix phx.digest

  cd ../firmware
  mix deps.get
  mix firmware
  mix firmware burn

Update SSD via WiFi

  export MIX_ENV=prod
  export MIX_TARGET=rpi3
  export MIX_HOST=nerves.local
  export MIX_PORT=80
  export PORT-80

  cd ui
  mix deps.get
  cd assets
  npm install
  node_modules/brunch/bin/brunch build --production
  cd ..
  mix phx.digest

  cd ../firmware
  mix deps.get
  mix firmware
  mix firmware push nerves.local

Hello Phoenix

This example demonstrates a basic poncho project for deploying a Phoenix Framework-based application to a Nerves device. A "poncho project" is similar to an umbrella project except that it's actually multiple separate-but-related Elixir apps that use path dependencies instead of in_umbrella dependencies. You can read more about the motivations behind this concept on the embedded-elixir blog post about Poncho Projects.

Hardware

This example serves a Phoenix-based web page over the network. The steps below assume you are using a Raspberry Pi Zero, which allows you to connect a single USB cable to the port marked "USB" to get both network and serial console access to the device. By default, this example will use the virtual Ethernet interface provided by the USB cable, assign an IP address automatically, and make it discoverable using mDNS (Bonjour). For more information about how to configure the network settings for your environment, including WiFi settings, see the hello_network example.

How to Use this Repository

  1. Connect your target hardware to your host computer or network as described above

  2. Prepate your Phoenix project to build JavaScript and CSS assets:

    # These steps only need to be done once.
    cd ui
    mix deps.get
    cd assets
    npm install
  3. Build your assets and prepare them for deployment to the firmware:

    # Still in ui/assets directory from the prior step.
    # These steps need to be repeated when you change JS or CSS files.
    node_modules/brunch/bin/brunch build --production
    cd ../
    mix phx.digest
  4. Change to the firmware app directory

    cd ../firmware
  5. Specify your target and other environment variables as needed:

    export MIX_TARGET=rpi0
    # If you're using WiFi:
    # export NERVES_NETWORK_SSID=your_wifi_name
    # export NERVES_NETWORK_PSK=your_wifi_password
  6. Get dependencies, build firmware, and burn it to an SD card:

    mix deps.get
    mix firmware
    mix firmware.burn
  7. Insert the SD card into your target board and connect the USB cable or otherwise power it on

  8. Wait for it to finish booting (5-10 seconds)

  9. Open a browser window on your host computer to http://nerves.local/

  10. You should see a "Welcome to Phoenix!" page

Learn More