FHEM Forum

FHEM => Automatisierung => Thema gestartet von: andyclimb am 12 August 2013, 19:28:36

Titel: Presenced - Setup on rPi
Beitrag von: andyclimb am 12 August 2013, 19:28:36
I've been struggling to get this to work reliably.....

I've downloaded : http://svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-rpi-1.1.deb (//svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-rpi-1.1.deb)

and in the rPi run sudo dpkg -i presenced-rpi-1.1.deb which installed correctly.

I have this set up in the remote fhem

define AMiPhone PRESENCE lan-bluetooth 98:B8:E3:7A:38:0F  192.168.1.127:5111 which defines a fhem object that reads "disconnected"

if i restart fhem nothing happens.
if i run presenced -d 5111 on the rPi Then it works briefly, i get active, and sometimes a present, but then it always reads disconnected after a few min
if I run presenced -v then I get this


presenced -v
2013-08-12 18:08:05 - started with PID 3106
print() on closed filehandle PIDFILE at /usr/sbin/presenced line 122.
2013-08-12 18:08:05 - created socket on 0.0.0.0 with port 5111
2013-08-12 18:08:16 - new connection from 192.168.1.209
2013-08-12 18:08:16 - received new command from 192.168.1.209: 98:B8:E3:7A:38:0F|30
2013-08-12 18:08:16 - created thread 1 for processing device 98:B8:E3:7A:38:0F within 30 seconds for peer 192.168.1.209
2013-08-12 18:08:16 - new connection from 192.168.1.209
2013-08-12 18:08:16 - closed connection from 192.168.1.209
2013-08-12 18:08:16 - killing thread 1 for client 192.168.1.209
2013-08-12 18:08:16 - new connection from 192.168.1.209
2013-08-12 18:08:16 - received new command from 192.168.1.209: 98:B8:E3:7A:38:0F|30
2013-08-12 18:08:16 - created thread 2 for processing device 98:B8:E3:7A:38:0F within 30 seconds for peer 192.168.1.209
2013-08-12 18:08:16 - new connection from 192.168.1.209
2013-08-12 18:08:16 - closed connection from 192.168.1.209
2013-08-12 18:08:16 - killing thread 2 for client 192.168.1.209
2013-08-12 18:08:16 - received new command from 192.168.1.209: 98:B8:E3:7A:38:0F|30
------------(lots of the same here.......
2013-08-12 18:12:02 - created thread 224 for processing device 00:26:08:66:B9:6B within 30 seconds for peer 192.168.1.209
2013-08-12 18:12:02 - new connection from 192.168.1.209
2013-08-12 18:12:02 - closed connection from 192.168.1.209
2013-08-12 18:12:02 - killing thread 224 for client 192.168.1.209
2013-08-12 18:12:02 - received new command from 192.168.1.209: 00:26:08:66:B9:6B|30
2013-08-12 18:12:03 - created thread 225 for processing device 00:26:08:66:B9:6B within 30 seconds for peer 192.168.1.209
2013-08-12 18:12:03 - new connection from 192.168.1.209
2013-08-12 18:12:03 - closed connection from 192.168.1.209
2013-08-12 18:12:03 - killing thread 225 for client 192.168.1.209
2013-08-12 18:12:03 - received new command from 192.168.1.209: 00:26:08:66:B9:6B|30
2013-08-12 18:12:03 - created thread 226 for processing device 00:26:08:66:B9:6B within 30 seconds for peer 192.168.1.209
2013-08-12 18:12:03 - new connection from 192.168.1.209
2013-08-12 18:12:03 - closed connection from 192.168.1.209
2013-08-12 18:12:03 - killing thread 226 for client 192.168.1.209
2013-08-12 18:12:03 - received new command from 192.168.1.209: 00:26:08:66:B9:6B|30
2013-08-12 18:12:03 - created thread 227 for processing device 00:26:08:66:B9:6B within 30 seconds for peer 192.168.1.209
2013-08-12 18:12:03 - new connection from 192.168.1.209
pi@raspberrypi ~ $


And then it just stops.....  

Does anyone have any idea why it just stops?

How can I have it auto start....  I have tried

sudo update-rc.d defaults presenced

but this does not seem to work. although it might be because it just crashes...

any help appreciated?

Andrew
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 12 August 2013, 21:56:27
Hi Andrew,

which FHEM version do you have exactly installed? Please run the command "version" in the command line in FHEMWEB.

I fixed this error quite a while ago. Maybe you just need to execute the "update" command in the command line and afterwards perform a "shutdown restart" command.

Cheers
Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 12 August 2013, 22:27:50
Hi,

Thank you for the vey fast reply.  

So, I was running the latest version on my server, and forgot that I've not updated the raspberry pi.....  So performed the update and it works...  

The only thing to change was the rc-d command which is inverted...  the correct command is

sudo update-rc.d presenced defaults

I also wanted to mention for others that the commandref still has the wrong setup for the PRESENCE LAN-Bluetooth...

it currently reads  

Zitatdefine iPhone PRESENCE lan-bluetooth 127.0.0.1:5222 0a:4f:36:d8:f9:89

it should read

Zitatdefine iPhone PRESENCE lan-bluetooth 0a:4f:36:d8:f9:89 127.0.0.1:5222

I actually ended up editing the code of 73_PRESENCE.pm to remove the check for correct bluetooth address...  finding out that it was still none functional.. and then discovering the four post using google translate.....

if you get this error "given address is not a bluetooth hardware address"  then you have the IP and the bluetooth address the wrong way round...

Thank you again for the help.

Andrew
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 12 August 2013, 23:58:10
Hi Andrew,

i just fixed this mistake in the commandref directly.

Thanks for your help too.

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 14 August 2013, 18:41:12
Thanks for fixing that.

I do have another question.  I've been running precenced on two raspberry pi computers.  The only thing is on both of them, on running the standard raspberry pi debian, the other Xbian the presenced process occupies almost all the CPU time.  I've attached a picture.  This seems to be a little high for a bluetooth ping...

have others found this as well?

Andrew
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 14 August 2013, 23:33:26
Hi Andrew,

that sounds a little strange to me, as presenced does not a cpu intensive task.

What is the output of "presenced -v" directly executed on the shell on your Xbian Pi?

Thank you

Markus

Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 11:24:04
Hi,

So the output from the shell with presences -v is below, and it seems to be ok.  no errors.

(siehe Anhang / see attachement)

If I run presenced the CPU usage us low, it is not until a connection is made from either FHEM or Collectord that the CPU goes to 98%.  

I've attached an image below of the sysstat module showing quite clearly when the presenced is running.

(siehe Anhang / see attachement)

I do have a slightly unrelated question.  Im running a raspberry pi with the bluetooth, CUL and an RFXcom, but the main FHEM is being run an ubuntu server machine as it is much faster.  I still have FHEM running on the rPi and a fhem2fhem set up.  it is all working fine.  

I have a lan-ping set up that works perfectly on the rPi and gives me present.  However, on the linux machine, it just gives me active.  I'm confused as everything works..  if I ping my phone from the command line it works.  and the permissions for /bin/ping are ok for everyone to execute.. Do you have any idea what that doesn't work?

Third question, do you know the password of the fhem:dialout user:group that is created on install of fhem?

Sorry for so many question.  

Andrew
Titel: Aw: Presenced - Setup on rPi
Beitrag von: rudolfkoenig am 15 August 2013, 11:29:11
> do you know the password of the fhem:dialout user:group that is created on install of fhem?

The dialout group was created without specifying a passwort.
Up till now I did not know that you can specify a password for a group.
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 12:05:44
Sorry I should have said does anyone know the password for ths user fhem which is in the group dialout when fhem is installed on Linux?

Cheers

Titel: Aw: Presenced - Setup on rPi
Beitrag von: rudolfkoenig am 15 August 2013, 12:12:44
The user does not have a password, and is intended to be used by the FHEM program when started as root from the rc scripts.
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 12:14:58
Hi Andrew,

you're right. I checked my Raspberry's and they have also 100% cpu usage. I changed this and released new deb-Packages which you can download:

presenced-rpi-1.2.deb (//sourceforge.net/p/fhem/code/3703/tree/trunk/fhem/contrib/PRESENCE/deb/presenced-rpi-1.2.deb?format=raw)
presenced-1.2.deb (//sourceforge.net/p/fhem/code/3703/tree/trunk/fhem/contrib/PRESENCE/deb/presenced-1.2.deb?format=raw)

The new package links will be released via update tomorrow.

I'm sorry for this.

Have a nice day.

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 12:58:51
Hi,

Thanks for getting a fix so quickly. I'm not home just now but will try it when I get home.

Have you got any idea why on my rPi fhem installation a LAN-ping give present/absent and works correctly. Whereas on my ubuntu server box I get only "active" as a state. If I ping my phone from the command line it works just fine. I thought it might be permissions that the fhem user is not allowed. But I can't su fhem, as it asks for a password which I don't know. I'm running ubuntu server 13.

Sorry for so many questions.
The help is appreciated.

Andrew

Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 14:05:09
Hi,

I've tried both 1.2 versions (normal and rPi) and i'm still getting immediately 95% CPU usage once the FHEM client connects.


(siehe Anhang / see attachement)
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 14:52:13
You're right. I also saw this right after installing the new deb package on my Pi's. I directly uploaded new deb packages right afterwards, but these links are still pointing to the old version (i hate this new sourceforge system...).

Please use the following links to get the latest version:

http://svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-1.2.deb (//svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-1.2.deb)
http://svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-rpi-1.2.deb (//svn.code.sf.net/p/fhem/code/trunk/fhem/contrib/PRESENCE/deb/presenced-rpi-1.2.deb)

I'm sorry for the confusion.

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 16:14:36
Markus,

All works great!  Thanks for the rapid fix! presenced now does not really register in the top processes, and uses almost nothing.


(siehe Anhang / see attachement)


Can I ask if what the difference if between the normal and rpi version?

any ideas why my lan-ping might not be working?

A
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 16:36:30
Zitat von: andyclimb schrieb am Do, 15 August 2013 16:14Can I ask if what the difference if between the normal and rpi version?

The only difference is the init script. On the raspberry there is an raspberry-like version used. But the presenced binary are both the same.

Zitat von: andyclimb schrieb am Do, 15 August 2013 16:14Any ideas why my lan-ping might not be working?

Could you please set the loglevel attribute to 3 and send me the output of your fhem.log?

Markujs
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 17:11:27
RE 1st question, thank you..  I actually downloaded the wrong one, but they both work fine.

here is the output, I have my logs in reverse......



rtt min/avg/max/mdev = 41.511/107.622/203.713/62.563 ms
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
--- 192.168.1.74 ping statistics ---

64 bytes from 192.168.1.74: icmp_req=4 ttl=64 time=64.3 ms
64 bytes from 192.168.1.74: icmp_req=3 ttl=64 time=41.5 ms
64 bytes from 192.168.1.74: icmp_req=2 ttl=64 time=120 ms
64 bytes from 192.168.1.74: icmp_req=1 ttl=64 time=203 ms
PING 192.168.1.74 (192.168.1.74) 56(84) bytes of data.
2013.08.15 16:05:41 3: PRESENCE (AMwifiiPhone) - ping command returned with output:
2013.08.15 16:05:38 3: PRESENCE_DoLocalPingScan: AMwifiiPhone|192.168.1.74|0|4
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 17:37:37
The reverse logs are no problem (i also use them). Are there any more related loglines you can send me?

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 15 August 2013, 18:26:20
I'm afraid not.  Nothing was generated until i restarted the computer.  then I get the lines you can see, with the ping output shown and then nothing else.  even if send a status request there are no more log lines generated.  Could the ping output be causing it to stop working on the first attempt?

I can generate those lines again if i issue a rereadcfg.  

heres the full output right from loading.

2013.08.15 17:24:41 1: Connection refused from 127.0.0.1:45658

rtt min/avg/max/mdev = 44.757/153.608/213.338/65.089 ms
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
--- 192.168.1.74 ping statistics ---

64 bytes from 192.168.1.74: icmp_req=4 ttl=64 time=213 ms
64 bytes from 192.168.1.74: icmp_req=3 ttl=64 time=190 ms
64 bytes from 192.168.1.74: icmp_req=2 ttl=64 time=165 ms
64 bytes from 192.168.1.74: icmp_req=1 ttl=64 time=44.7 ms
PING 192.168.1.74 (192.168.1.74) 56(84) bytes of data.
2013.08.15 17:24:41 3: PRESENCE (AMwifiiPhone) - ping command returned with output:
2013.08.15 17:24:38 3: PRESENCE_DoLocalPingScan: AMwifiiPhone|192.168.1.74|0|4
2013.08.15 17:24:36 1: Including ./log/fhem.save
DS: WNMiPhone
DS: WNMiPhone
2013.08.15 17:24:36 3: WNMiPhone device opened
2013.08.15 17:24:36 3: Opening WNMiPhone device 192.168.1.127:5111
DS: AMiPhone
2013.08.15 17:24:36 3: AMiPhone device opened
2013.08.15 17:24:36 3: Opening AMiPhone device 192.168.1.127:5111
2013.08.15 17:24:36 3: remoteTELNET: port 7073 opened
2013.08.15 17:24:35 3: localWEB: port 8087 opened
2013.08.15 17:24:35 3: FHEM2FHEM device opened (d3)
2013.08.15 17:24:35 3: FHEM2FHEM opening d3 at 192.168.1.127:7072
2013.08.15 17:24:35 3: FHEM2FHEM device opened (d2)
2013.08.15 17:24:35 3: FHEM2FHEM opening d2 at 192.168.1.127:7072
2013.08.15 17:24:35 1: TRX: TRX_0 device is none, commands will be echoed only
2013.08.15 17:24:35 1: COC device is none, commands will be echoed only
2013.08.15 17:24:35 3: WEBtablet: port 8085 opened
2013.08.15 17:24:35 3: WEBphone: port 8084 opened
2013.08.15 17:24:35 3: WEB: port 8083 opened
2013.08.15 17:24:35 3: telnetPort: port 7072 opened
2013.08.15 17:24:35 1: Including fhem.cfg
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 21:28:07
Hi Andrew,

it seems to me that you have set the "allowfrom" attribute in your TELNET definitions. The problem is, that a loopback connection via 127.0.0.1 is needed to deliver the check results to the main FHEM process.

Please allow connections also from 127.0.0.1, then it should work.

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 15 August 2013, 21:45:26
I placed a patch in FHEM Development (http://forum.fhem.de/index.php?topic=14288.0) so after the patch is applied, it also should work without explicitly allowing 127.0.0.1

Greetings
Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 16 August 2013, 11:34:46
Hi,

Ah that explains everything.  I disabled my 192.168.1.* restriction on the telnet port and bingo it stared working.   I have no idea that the loopback was required.  

Thanks again.

Not had a chance to try out the new patch, I'll test over the weekend if that works as well.  

thanks again for all your help Markus, the rPis are now very happy with 0% CPU usage!

Andrew
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 16 August 2013, 11:43:14
Yeah that's a bit tricky as the user doesn't know that. My patch from yesterday was applied today by Rudi and tomorrow after you execute an update and restart, you can use your allowfrom-filter normal as usual.

Have a nice weekend.

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 18 August 2013, 23:21:26
Hi,

Sorry I've been away for the weekend.  I've had a chance to apply the patches and they work great.  Getting rid of the telnet IP restriction also fixed the ping.  I've not tried to put it back yet, to test the other patch..

On to the next question!!!

I'm trying to get a notify and a watchdog to work of the presence instance, coming from a collectord...  I just cant get it to work...  I've tried

AMiPhone:present
AMiPhone.present
AMiPhone:present*

I've generated a userReading
home {if (Value("AMiPhone")=="present") {Value("AMiPhone")}; if (Value("AMiPhone")=="absent") {Value("AMiPhone")} }
which gives me

2013-08-18_22:11:24 AMiPhone home: present
2013-08-18_22:10:53 AMiPhone home: present
2013-08-18_22:09:45 AMiPhone home: present
2013-08-18_22:09:08 AMiPhone home: present
2013-08-18_22:08:37 AMiPhone home: present

The thought being that the lack of : stopped the event being registered in fhem as presence generates the events shown below in a file log...

2013-08-18_10:40:17 AMiPhone present

but

AMiPhone:home.present as a RegExp does not work for this either...  the reason that im confused is that the code shown below works just fine when the presence module is used with a local-bluetooth device, which suggests an issue with thecollectord... unless of course im doing something totally wrong!  I've just also tested an instance of a pan-bluetooth but talking directly to the presenced instance and that works too (using testbluetooth:present set tvlamp on) .  so this is exclusively something wrong with the presenced implementation...

amiphonebt:present|amiphonewifi:present set amishome_count 0



Sorry for all the trouble..any help appreciated...

Andrew

Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 19 August 2013, 00:02:25
I'm sorry, but i don't really understand what you are trying to achieve.

Could you please post the relevant configuration statements in your fhem.cfg and an explanation of your problem.

In general for notify's and watchdogs, please use "AMiPhone:present". But it also depends on your configuration.

Greetings

Markus

Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 19 August 2013, 11:40:23
I want to write a regexp for AMiPhone that works for notify and watchdog. The problem is that for me it doesn't work when the PRESENCE module uses collectord.  here is the code...

This is the presence a module connecting to a local collectord.

define AMiPhone PRESENCE lan-bluetooth 98:B8:E3:7A:38:0F  0.0.0.0:5222

This is the presence a module connecting to a remote presenced.

define AMiPhone PRESENCE lan-bluetooth 98:B8:E3:7A:38:0F  192.168.1.127:5111

Both of these work and return the correct present/absent..... as they should

The problem is that the notify shown below ONLY works for the AMiPhone (remote presenced) and not the local collectord.  

define testnotify notify AMiPhone:present set lamp on

Does this make sense?
Titel: Aw: Presenced - Setup on rPi
Beitrag von: Markus Bloch am 19 August 2013, 17:42:11
Yes, now i understand :-)

When you use the first definition (local collectord), what readings where created and what state is displayed on the detail view in FHEMWEB?

Markus
Titel: Aw: Presenced - Setup on rPi
Beitrag von: andyclimb am 20 August 2013, 14:27:12
I figured it out!  I made a mistake and defined event-on-change, event-on-update rules which meant that no events were generated for state changes.  

I can't believe that it took me that long to work it out!