This example demonstrates a basic project for using the Ecto SQLite Adapter.
See scheduler_usage_poller.ex for an example of Sqlite being used.
The example below assumes a Raspberry Pi 0 connected over the USB. Other official and many unofficial Nerves targets work as well.
-
Go to the
hello_sqlite
directory -
Set up your build environment
# Specify the target hardware. See the mix.exs for options export MIX_TARGET=rpi0 # To hard-code WiFi credentials in the firmware, you can set # the SSID and optionally a password here export WIFI_SSID=your_wifi_name export WIFI_PASSPHRASE=your_wifi_password
-
Get dependencies, build firmware, and burn it to an SD card
mix deps.get mix firmware mix firmware.burn
-
Insert the SD card into your target board and power up
-
Wait to finish booting.
-
SSH into the board:
ssh nerves.local
-
from the IEx prompt
# Get 5 entries from the SchedulerUsage table and print them out
HelloSqlite.print_recent(5)
+------------------------------------------------------+
| Scheduler Usage |
+---------------------+---------+----------------------+
| Timestamp | Percent | Util |
+---------------------+---------+----------------------+
| 2021-04-07 14:53:27 | 0.0 | 4.61004300282592e-5 |
| 2021-04-07 14:52:56 | 0.0 | 1.968093695606747e-5 |
| 2021-04-07 14:52:25 | 0.0 | 8.095389473073943e-5 |
| 2021-04-07 14:51:54 | 0.0 | 9.218367384342268e-6 |
+---------------------+---------+----------------------+
:ok
-
Official docs: https://hexdocs.pm/nerves/getting-started.html
-
Official website: https://nerves-project.org/
-
ecto_sqlite3
docs: https://github.com/elixir-sqlite/ecto_sqlite3 -
Ecto Docs: https://hexdocs.pm/ecto/