Can anybody help?
(ps my understanding of written German is good, my writing not)
in 99_myUtils I have:
sub TestGSM {
my $myCounter = 0;
Log 1, "1a";
fhem("set PGSMHarry statusRequest");
while(($myCounter <= 100) && (Value('PGSMHarry') eq "absent")) {
sleep(1);
Log 1, "PGSMHarry: ".Value('PGSMHarry');
$myCounter++
}
Log 1, "End PGSMHarry: ".Value('PGSMHarry');
Log 1, "1b";
}
When I switch on Wifi on my GSM, wait till it is connected and then start the routine from the web interface I get:
2013.04.12 15:52:12 1: 1a
2013.04.12 15:52:12 1: 1a
2013.04.12 15:52:12 1: 1b
2013.04.12 15:52:14 1: PGSMHarry: absent
2013.04.12 15:52:15 1: PGSMHarry: absent
[...]
2013.04.12 15:53:54 1: PGSMHarry: absent
2013.04.12 15:53:54 1: End PGSMHarry: absent
2013.04.12 15:53:54 1: 1b
2013.04.12 15:53:54 1: 1a
2013.04.12 15:53:54 1: 1b
I don't understand why I get multiple "1a" and "1b" lines. And it seems I didn't trigger Presence to start an ad-hoc check. Can anybody explain what I do wrong?
Thanks
{HT}
Ok, forget about the multiple 1a and 1b. That was because I used the same in another procedure which was scheduled. But I still don't understand why Presence doesn't do what I want.
{HT}
you can not wait it a busy loop with sleeping. nothing in the background will be execued during sleep. fhem ist just blocked. you have to use a notify to react to state changes in presence.
regards
andre
While your subroutine is executed, FHEM cannot do anything. FHEM is currently a single-threaded application and does not support parrallel thread execution or similiar.
When you execute a statusRequest it just starts a check, but doesn't wait for the result.
Zitat von: Markus Bloch schrieb am Fr, 12 April 2013 19:53When you execute a statusRequest it just starts a check, but doesn't wait for the result.
And there is no way how I can force to check and then continue? A way of calling Presence itself or so?
{HT}
a possible solution would be to split up your sub and create a temporary notify which is executing the rest of your function, when the state is set:
(not tested)
sub TestGSM {
Log 1, "1a";
fhem("set PGSMHarry statusRequest");
fhem("define tmp_ReportTestGSM notify PGSMHarry {ReportTestGSM()}");
}
sub ReportTestGSM()
{
fhem("delete tmp_ReportTestGSM");
Log 1, "End PGSMHarry: ".Value('PGSMHarry');
Log 1, "1b";
}
to wait for the event blocking everything else is realy the wrong approach.
why do you want to wait for something instead of letting fhem do all the work and being notified if this something happens?
Zitat von: HarryT schrieb am Fr, 12 April 2013 20:01Zitat von: Markus Bloch schrieb am Fr, 12 April 2013 19:53When you execute a statusRequest it just starts a check, but doesn't wait for the result.
And there is no way how I can force to check and then continue? A way of calling Presence itself or so?
{HT}
If this would possible, the whole FHEM process would do nothing for about 1-10 seconds, depending on if your present or not. In this time FHEM cannot react on incoming rf communication or other commands.
It's just the same if you use a sleep command in your subs. The whole FHEM process will sleep for the given time.
Zitat von: Markus Bloch schrieb am Fr, 12 April 2013 20:07a possible solution would be to split up your sub and create a temporary notify which is executing the rest of your function, when the state is set:
(not tested)
sub TestGSM {
Log 1, "1a";
fhem("set PGSMHarry statusRequest");
fhem("define tmp_ReportTestGSM notify PGSMHarry {ReportTestGSM()}");
}
sub ReportTestGSM()
{
fhem("delete tmp_ReportTestGSM");
Log 1, "End PGSMHarry: ".Value('PGSMHarry');
Log 1, "1b";
}
Thanks for your suggestions.
Where I want to use it is to detect when a door is opened without my GSM (or the GSM of my wife) is registered on my Fritzbox. In that case an alert is raised. As the GSM may registered when I approach, if it is detected that the door is opened and my GSM is not detected by Presence I want to check it once again on that moment to see if my GSM is registered since the last Presence check. If that check also fails the alert is raised. This approach will always give falls positives but I would like to minimize the number of them.
BTW I think it is impossible to use bluetooth on the Fritzbox, otherwise I could check this too.
if you can live with an alarm that is a little delayed a much better aproach with no false positives woud be to use a watchdog. start it if the door is opened and let it fire if no gsm is deteced in x minutes after the door is opened. this eleminates the busy waiting and takes care of the gsm approaching and even the unreliable ping. if a gsm is detected reset the watchdog.
this would basicaly turn arount the problem from 'don't raise the alarm if the door is opened and a gsm is there' to 'raise the alarm if the door is opened and after x minutes no gsm is there' which is much more reliable to do.