opennethome feel people!

Functionality and usage of the OpenNethome Server
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

opennethome feel people!

Post by Nasty76 »

Hey again i look some handy way to get feature like your nethome know users in home so i look ideas how this can be made I found handy Linux program arp-scan where you can give example your wlan dhcp range like arp-scan 10.10.1.2-10.10.1.50 that scan that Ip area and show lan device ips and mac address. Now if we make that log file where is list of devices and nethome plugin read log now nethome know which phones are network. Now if nethome plugin named like dad and give that mac address ur phone nethome know if dad if home or not :) then we can make some cool functions like if phone x not network shutdown lamp y. Maybe some group plugin like if any configurated phone not are wlan
all power.what u guys think is this handy.
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: opennethome feel people!

Post by stefangsbb »

Yes, it wold be nice to be able to use the phones wlan connection to determine if someone is home and configure rules for that to switch lamps on and off. I have looked in to it a bit, and at a first glance arp-scan seems to work quite well. Unfortunately it seems like there is no way to access the needed API:s direct from Java.

From what I understand I would actually have to make NetHome call the arp-scan command and interpret the response. This has a number of drawbacks, first of all it is only available on Linux machines, so I would have to drop Windows support for that HomeItem. Secondly, arp-scan is not by default installed on linux machines, so it requires that the user have installed the package. Third, arp-scan requires root access to run. The best way to solve the last obstacle is probably to require that the user sets the SETUID-bit on the command so any user can run it.

Nevertheless, it would be kind of cool to get it working, so I will experiment a bit with it to see how well it seems to work in practice. But I am a bit worried about the amount of support mails I will get with a function that has so many external dependencies...
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Well I make some research and found some help I test this in success full in java my Ubuntu server default-jre and default-jdk

Code: Select all

import java.io.*;
import java.net.*;
import java.util.*;
import static java.lang.System.out;
public class JavaTest{
  public static void main(String[] argv) throws Exception {
String str2 = "00:13:E8:D6:EC:83";

  Process p = Runtime.getRuntime().exec("sudo arp-scan 192.168.1.2-192.168.1.20");

  p.waitFor();
  BufferedReader buf = new BufferedReader(new InputStreamReader(
          p.getInputStream()));
  String line = "";
  String output = "";

  while ((line = buf.readLine()) != null) {
    output += line + "\n";
  }

  System.out.println(output);
if(output.toLowerCase().contains(str2.toLowerCase()))
{
System.out.println("laptop mac found!");

}



 }


}
Yeah mac and windows client cannot use that apr-scan is only Linux :(. I have some tutorial where u get macs in java directly but that bugged when android phone come range :( that tell phone find and crash when try solve mac.
In my opion raspberry pi is best platform to nethome , crash free , easy to make backup , cheap you can buy extra machine if something happened etc... but ofc u make good job allways and if something homeitem not work they spam mail for you and ask help :P.
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: opennethome feel people!

Post by stefangsbb »

Well, I was a bit curious about this, so I actually implemented some Items for this. The main Item is the ArpScan-Item. There you configure the arp scan command and how often it should scan.

The ArpScan-Item only works on Linux, and you have to have arp-scan installed. You also have to make arp-scan possible to run from nethome, since it normally requires root access. The easiest way to do this is to make it set-uid root:

Code: Select all

sudo chmod u+s  /usr/bin/arp-scan
This makes the command runnable by any user, but it also may have some security implications on the machine.

Then there is the MacDevice-Item where you configure a mac-address and action to perform when the device comes on net and action to perform when the device goes off net.

There is also a MacDeviceGroup-Item where you configure a list of mac-addresses and action to perform when all of them go off net (no one at home).

I have been trying these out a bit, but it does not seem to work as well as I hoped. My iPhone for example is not very good at answering the arp scan every time, so quite often it does not show up on the scan and is indicated as off net. I am also a bit worried that this may decrease battery life on the phones, as they have to fire up the WLAN to answer these requests all the time...

You can try it out for a while, but if I don't get it to work more reliably, I may have to remove the items again...
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Thanks man you are awesome. I start test that. And dont worry phone battery life on Finland all use WLAN cos facebook and other message system.
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Ok I update last nightly , all work good realy good , but can we get some ip range settings in that arp-scan item , I think that now scan whole range which not needed I think I make dhcp ip range something 192.168.1.2-192.168.1.30 , and move all other machines out of that area so arp-scan not need scan every ip. Still damn good job I realy love nethome , example knx cant be make all cool stuff what nethome can :D , ps. is that time in arp-scan minutes or seconds? maybe in future you add minute or seconds string there so people know which numbers that mean :D.
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Never mind i figure that my own :P , i use this line to arp-scan module seems work.
/usr/bin/arp-scan 192.168.1.2-192.168.1.35 --interface=eth0
Btw , i have debug that little , seems android keep wlan live when phone is connected wlan but lumia 925 dropping connection some power save mode , i need debug that problem little more.
in this moment lumia is funny , wlan sleeped , i sent debug im message phone which is " nasty phone out of range". ok then i get message , after that nethome again see phone and sent message " nasty phone in home" , and that start loop :P i try look some fix for this.
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Well little debug today , lumia 925 and apple ipad1 seems to work weird , after some seconds when not used , wlan go some powersave mode and not answer arp scan but that last ip answer to ping so maybe that item get some better working if there is ip table example when phone come wlan lumia and ipad1 connect network and answer arp-scan so maybe some update function example. when phone is range update ip table this mac. and nethome try arp-scan if not answer try ping that last knowing ip and if answer is yeah figure out if phone is range or not.
more notes , windows ping not wake up lumia but rasberry ping command seems answer even phone is idle.
how hard that is test example that mac item contain last ip and if not arp scan not answer that try ping couple packets that device?
I make some notes ping command not take much power in rasberry and arp-scan take about 30% cpu time couple seconds , so i dont know but maybe better way is update ip tables arp-tables less and check ip , i think my telewell homerouter never change ip so i dont know is that is bad feature?
BTW, if lumia is charging arp-scan get mac alltime :P


Best Regrards Nasty76
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: opennethome feel people!

Post by stefangsbb »

This is what I was afraid of. I looked a bit at what you suggested, but at least my iPhone5S does not wake up by a ping from RPi. As you say, it only answers arp-scan when it is active, as soon as it goes to sleep it stops. We will have to find an alternative way, otherwise this does not really fly... One way would of course be if there is some app that always answers on a known port on the phone or an app that can connect to a configured address as soon as it is on the wlan.
Nasty76
Posts: 145
Joined: Tue Dec 09, 2014 1:20 am

Re: opennethome feel people!

Post by Nasty76 »

Oh no I don't have any other apple devices than ipad1 but I have realy intrest test that ping relative system , can you sent me sources of mac items so I can easy mess them and test with my system if I get that work plugin mode?.
or do you have some time some day to change that item like arp-scan update some ip information that and try ping that example? lumia has approx. 1sec delay answer ping if you are on phone same time so try time maybe need be 2 sec to wait ping answer?
I think that work , lumia phones and anroid so maybe if that work need only make apple applet which answer to reguest?
Post Reply