Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discovering embedded device in local network?

I am trying to build an embedded device that would be connected to a router. But I want to be able to know if the device is connected to the router or not using a PC or Mobile.

For example: How can the PC detect if the google chromecast is connected on the same network or not ?

  • Do I need to communicate with each IP in the network on a specific port to ask ?
  • Or do I need to let the embedded device broadcast some information every N seconds ?

Thanks,

like image 807
Xedar Avatar asked Apr 14 '26 08:04

Xedar


1 Answers

In any case you should consider doing a Gratuitous ARP on your embedded device. A gratuitous ARP will announce to all of the devices on your LAN that a new device has joined so they can update their ARP cache.

As far as a PC/Mobile device discovering your embedded device goes, you have a few options:

Option 1

If we can assume that this is a typical flat home network where all of the devices are on a single subnet and there is one gateway router * then you can give your embedded device a unique OUI. If you intend to sell this device you will need to apply for an OUI with the IEEE anyway unless whoever made your chipset supplies it with a MAC address already. Your PC/Mobile app can periodically check its ARP cache for an OUI that matches the unique OUI that you expect.

This will not work if the network is not flat and there are multiple routed subnets or VLANS. Here is a possible scenario: Lets suppose your embedded device connects to a client bridge range extender. If your PC/Mobile app is on the main access point it will never see the MAC address of the embedded device - instead it will see the MAC address of the client bridge. Multiple IPs will be mapped to the client bridge because the client bridge and the client bridge will be switching packets.

*I put the term router in italics because most home routers are merely doing NAT between the WAN/LAN and the LAN side of the router operates like a layer 2 switch.

Option 2

You can do a broadcast ping request, eg. ping xxx.xxx.xxx.255. You'll get a response back from all devices that will accept a broadcast ping request. Just make sure your device does. Then once you have a list of IP addresses you can attempt to open a TCP socket over the arbitrary port of your choosing with all of those IP addresses and then send some unique handshake packet. Your embedded device should be listening over this port and should have some unique reply to this unique packet. Most of the devices on the lan should generally not allow this socket to open, but if they do they should not understand the unique handshake message you send.

Option 3

Send a broadcast UDP datagram with some unique handshake payload. Then your embedded device should reply to the sender of this broadcast UDP packet with some unique response. After this response has been received by your PC/Mobile app you can then open a TCP socket with the IP address the response came from.

like image 142
Nick Avatar answered Apr 17 '26 08:04

Nick