# Local Network Device Discovery

**URL:** <https://community.openenergymonitor.org/t/local-network-device-discovery/9719>\
**Category:** Labs\
**Tags:** emonpi, find, emoncms, emonhub\
**Created:** [9 January 2019 11:52 UTC](https://community.openenergymonitor.org/t/local-network-device-discovery/9719 "2019-01-09T11:52:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emrys](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/emrys/32/7050_2.png) [@emrys](https://community.openenergymonitor.org/u/emrys)\
**Post date:** [9 January 2019 11:52 UTC](https://community.openenergymonitor.org/t/local-network-device-discovery/9719/1 "2019-01-09T11:52:44Z")

</div>

**Device Scanner**

We have produced a tool that scans the local network for devices. This is JavaScript tool that can be tested on your network if you follow the instructions GitHub page for this module [https://github.com/emoncms/find](https://github.com/emoncms/find)

There is also an online version hosted at **[Emoncms - find](https://emoncms.org/find)**, however you must first update the emoncms devices before scanning as there are some minor changes to get this to work.

 ![image](https://community.openenergymonitor.org/uploads/default/original/2X/d/d11f908ec53ee0b76302f35702e37b1d8e2e4510.png)

I have copied in the readme below:

## Problem

It can sometimes be an difficult finding a emonbase/emonpi on a home network to access the EmonCMS interface, hostname support can be tempremental and its easy to forget the router passwords to access the device list on the router. A network scan can be done using a 3rd party app like [fing](https://play.google.com/store/apps/details?id=com.overlook.android.fing) however this adds another step and complexity.

## Solution

We have created an emoncms module that can be accessed from an existing EmonCMS intallation or from [emoncms.org](https://emoncms.org/find) that can scan the local network for devices with EmonCMS installed.

#### This is done in 2 stages.

1. Read the local IP Address
2. Check every entry on the network for an EmonCMS installation.

The results are shown in a list along with the IP Address and type of device that returned a response. You can click any found device to access it’s control panel.

### Requirements

These changes will be available with the normal EmonPi and EmonCMS updates. In the mean time you can use the following to test.

#### emonpi

The device type is set using the [emonpi](https://github.com/openenergymonitor/emonpi) repository. To update the code run the following:

```auto
$ cd /home/pi/emonpi
$ git checkout master
$ git pull 

```

#### emoncms

For the device to respond with it’s correct type you have to use the master branch of [emoncms](https://github.com/emoncms/emoncms).

```auto
$ cd /var/www/emoncms
$ git checkout master
$ git pull

```

### TLDR;

This is written in JavaScript and only ran in the user’s browser using a standard API (webRTC). Nothing is transmitted outside the local network.

1. The RTCPeerConnection API allows the browser to open a connection to another ip address. Once this connection is initialised the local ip address can be read.

> This example shows what is returned by the WebRTC api ([https://codepen.io/emrys/full/aPKPzv](https://codepen.io/emrys/full/aPKPzv))

1. Send 253 ajax requests (0.0.0.1 - 0.0.0.254) to every IPv4 address possible in the current subnet testing for responses from an EmonCMS install (eg `http://192.168.1.136/emoncms/describe` ). Only correctly formatted responses are displayed in the list, anything else is ignored.

4 different expected types are returned from an EmonCMS installation at the API endpoint `/describe` :-

1. emonpi
2. emonbase
3. emoncms
4. smartplug

The module asks for confirmation from the user because it must open another tab changing from `https` to `http` .

This tool does not work using `https` as the local installation of EmonCMS doesn’t use TLS to encrypt the communication between the client and server. The ajax requests would fail if done over `https` and no devices would be found.
