Skip to content

Commit 469a130

Browse files
committed
Advertise device and firmware info on the network
Here's an example: ``` $ mix nerves.discover Discovering Nerves devices (waiting up to 5000ms)... HOSTNAME ADDRESSES SERIAL PRODUCT VERSION PLATFORM UUID nerves-b938.local 192.168.7.79 a64b4b375666b938 circuits_quickstart 0.14.0 rpi5 salute-fog (cb5fd1b6-6903-5f72-5a37-b286a3c517fb) ```
1 parent 2926ac3 commit 469a130

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/circuits_quickstart/application.ex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ defmodule CircuitsQuickstart.Application do
77

88
def start(_type, _args) do
99
if Nerves.Runtime.mix_target() != :host do
10+
advertise_device()
1011
setup_wifi()
1112
end
1213

@@ -19,6 +20,26 @@ defmodule CircuitsQuickstart.Application do
1920
Supervisor.start_link(children, opts)
2021
end
2122

23+
defp advertise_device() do
24+
# See https://hexdocs.pm/nerves_discovery/
25+
MdnsLite.add_mdns_service(%{
26+
id: :nerves_device,
27+
protocol: "nerves-device",
28+
transport: "tcp",
29+
port: 0,
30+
txt_payload: %{
31+
"serial" => Nerves.Runtime.serial_number(),
32+
"product" => Nerves.Runtime.KV.get_active("nerves_fw_product"),
33+
"description" => Nerves.Runtime.KV.get_active("nerves_fw_description"),
34+
"version" => Nerves.Runtime.KV.get_active("nerves_fw_version"),
35+
"platform" => Nerves.Runtime.KV.get_active("nerves_fw_platform"),
36+
"architecture" => Nerves.Runtime.KV.get_active("nerves_fw_architecture"),
37+
"author" => Nerves.Runtime.KV.get_active("nerves_fw_author"),
38+
"uuid" => Nerves.Runtime.KV.get_active("nerves_fw_uuid")
39+
}
40+
})
41+
end
42+
2243
defp setup_wifi() do
2344
kv = Nerves.Runtime.KV.get_all()
2445

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"mdns_lite": {:hex, :mdns_lite, "0.9.1", "fb305081d01aa62d38d86a4e467e9b7eb217aa68d62c22b111105170ca7f198f", [:mix], [{:igniter, "~> 0.5", [hex: :igniter, repo: "hexpm", optional: true]}, {:vintage_net, "~> 0.7", [hex: :vintage_net, repo: "hexpm", optional: true]}], "hexpm", "4f5ae0c6cc69fcc3adadf68bfd54abfc5a284defa703d6faefe40ade2145a601"},
1313
"muontrap": {:hex, :muontrap, "1.7.0", "ff6eda43839194dc342b81e02e764fd75389a8ab166318548f3aaec374846600", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "7bd4a90ae008bf6a25554aa13497b2c05dfa1fcc34be5bdcb8fb4dec9b3422e3"},
1414
"nerves": {:hex, :nerves, "1.13.1", "97cb6ddb1d1a9c29379ac7874948cfd788d19c1b558ce7a6a32c82d845679668", [:make, :mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:interactive_cmd, "~> 0.1.2", [hex: :interactive_cmd, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:nerves_discovery, "~> 0.1.1", [hex: :nerves_discovery, repo: "hexpm", optional: false]}, {:tablet, "~> 0.3.1", [hex: :tablet, repo: "hexpm", optional: false]}], "hexpm", "1af8d4ed4fa7fbbf9e624a7a8d04ec57546eff88b1e83e150cdd7176057f4b5a"},
15-
"nerves_discovery": {:hex, :nerves_discovery, "0.1.1", "ec5b41e164754cae1edba0c32d887739d1cdf677282c729f7c6ef9ec29fb4136", [:mix], [], "hexpm", "01008258f60637d47c5c35e94bdf4ca8588da0a55156562508789316f17b8b5e"},
15+
"nerves_discovery": {:hex, :nerves_discovery, "0.1.2", "9bf4b031cd13c00073cd2ee1053569ecc308da33a16a316997f59b0168c96300", [:mix], [], "hexpm", "87220c31e6de2919b81c9648bdaa647b1e8f67356475d295d7ecf08639ea294c"},
1616
"nerves_logging": {:hex, :nerves_logging, "0.2.4", "7d60c345325c7165a1473be30a399847eaba425dce3258ef97a8aefd6d913160", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "942f9757adea17d56f4f64fbf4e1aaffd4b2471dd2f1bc020ba80ba2ef5238bc"},
1717
"nerves_motd": {:hex, :nerves_motd, "0.1.17", "a0c4ebec82425185dd8cea1c12cd5d310b076cdefc82ba5f4bf516b5733ee4de", [:mix], [{:nerves_runtime, "~> 0.13.9", [hex: :nerves_runtime, repo: "hexpm", optional: false]}, {:nerves_time, "~> 0.4", [hex: :nerves_time, repo: "hexpm", optional: true]}, {:nerves_time_zones, "~> 0.1", [hex: :nerves_time_zones, repo: "hexpm", optional: true]}], "hexpm", "901a99bb22355e3f68b2f33182756cec1b0556531a6f93521a7baa2f0591969d"},
1818
"nerves_pack": {:hex, :nerves_pack, "0.7.1", "f069a9c3cfcde445498aad618af95c846f2ee032a69c2d715a9e5d4f632fb1b5", [:mix], [{:mdns_lite, "> 0.0.0", [hex: :mdns_lite, repo: "hexpm", optional: false]}, {:nerves_motd, "> 0.0.0", [hex: :nerves_motd, repo: "hexpm", optional: false]}, {:nerves_runtime, "> 0.0.0", [hex: :nerves_runtime, repo: "hexpm", optional: false]}, {:nerves_ssh, "> 0.0.0", [hex: :nerves_ssh, repo: "hexpm", optional: false]}, {:nerves_time, "> 0.0.0", [hex: :nerves_time, repo: "hexpm", optional: false]}, {:ring_logger, "> 0.0.0", [hex: :ring_logger, repo: "hexpm", optional: false]}, {:vintage_net, "> 0.0.0", [hex: :vintage_net, repo: "hexpm", optional: false]}, {:vintage_net_direct, "> 0.0.0", [hex: :vintage_net_direct, repo: "hexpm", optional: false]}, {:vintage_net_ethernet, "> 0.0.0", [hex: :vintage_net_ethernet, repo: "hexpm", optional: false]}, {:vintage_net_wifi, "> 0.0.0", [hex: :vintage_net_wifi, repo: "hexpm", optional: false]}], "hexpm", "6b94d38771e3a97c3ed63e62fb5f78b47461208ee162e20bfbcf6e36fd900616"},

0 commit comments

Comments
 (0)