Half the problems of figuring out if a device is up during dev is about figuring out if a device came up and with what hostnames?
For pis you get nerves.local or whatever you set plus a nerves-1234.local. When juggling devices you sometimes get collisions, sometimes you unwittingly switch hostname.
I guess we could do a mix command to check mDNS info locally. Would need some different implementation between platforms but…
Given there’s no C code I’d naively expect it to work cross platform. By my understanding it’s UDP/TCP underneight mDNS, which should just work on the beam.
@fhunleth what do you think about mix upload maybe checking what appropriate mdns hosts are around and listing them if no hostname is given?
If only one shows up it could try that one as long as it indicates clearly it is going for that particular one. I asusme the current logic is default to nerves.local?
I definitely think easier and better device discovery would be super helpful to anyone using Nerves.
As for mDNS (or SSDP which some people have used with Nerves too), I’ve gotten a little discouraged with Elixir-based CLI tool usage. The main reason being that ideally the tools would query the system responders and there’s no cross-platform API. Starting a new responder (e.g., using mdns_lite on MacOS) conflicts the the system one and can lead to surprises - like the system and CLI are out of sync.
If I could propose an alternative strategy and that’s to implement a really simple discovery protocol that won’t conflict with existing responders, doesn’t do any caching, doesn’t use a privileged port number, and can be implemented in pure Elixir. I haven’t done a review of all that’s out there, but the Mikrotik Neighbor Discovery Protocol seems like it could be made to work really well. Wireshark decodes it so debugging would be easier.
Currenty the UDP socket is opening on 0.0.0.0 so that i can receive packets from all interfaces.
I’ve also added error handling to the parsing and did extensive research about the header values. It’s still unclear and i think the values changes from Version 6 to 7 because i have a device with each version and the sequence number is represented by different bytes. Unfortunately there is no official spec for the headers and some of the fields are unclear. Even the Wireshark dissector has no clue
TODO:
Find out about first 4 bytes
Find out about additional TLVs
Find out about unpack values
Next i will add functionality to broadcast your own discovery packet!