[SOLVED] Grabbing and sending webcam pic via telegram problem

Begonnen von claudio, 26 Februar 2018, 02:45:49

Vorheriges Thema - Nächstes Thema

claudio

Hi all

I'm trying to get a snapshot of a webcam on command via telegram. It works, I receive the picture but it send me always the previous pic, not the latest one.
If there is no pictures already grabbed in the folder, the log said that the pic is not found which is weird because I launch the grab with the command "get firstcam image" then only send the image via telegram.

Got any ideas ?

Zitat
robotTelegram:msgText.* {
   if ($EVTPART1 eq 'cmdGrab1') {
      my $time = localtime();
      fhem("get firstcam image");
      
      sleep 5;
      my $snapshot = ReadingsVal("firstcam", "last", "");
      my $storage = AttrVal("firstcam","storage","");
      my $path = "${storage}/${snapshot}";
      fhem("set robotTelegram sendImage $path $time");
   } else {
   
   }
}


MadMax-FHEM

I'm not sure if that is the problem but the sleep you use is blocking fhem so nothing will happen in between (from fhem).

If you use a fhem sleep (see commandref) then maybe that is at least what your intention of the sleep was...
But not sure if that "fixes" your problem...

Short because just mobile phone...

Bye, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

RaspiLED

Try using to start the following commands in an FHEM at command for testing.
Regards Arns


Raspi2 mit FHEM, CUL, Signalduino, MySensors, HomeBridge, Presence, Bravia, ...
Raspberry Pi mit FHEM, CUL, Signalduino, MySensors, HomeBridge, Presence, WifiLight2, Bravia, ...

claudio

Zitat von: MadMax-FHEM am 26 Februar 2018, 07:18:40
I'm not sure if that is the problem but the sleep you use is blocking fhem so nothing will happen in between (from fhem).

If you use a fhem sleep (see commandref) then maybe that is at least what your intention of the sleep was...
But not sure if that "fixes" your problem...

Short because just mobile phone...

Bye, Joachim

Thanks you ! that was it

I changed

fhem("set robotTelegram sendImage $path $time");


To :


fhem("sleep 2; set robotTelegram sendImage $path $time");


And removed the previous sleep 5 in between. It worked. I found 2 seconds seem's enough, but may change it in the future.

I've also removed the notify and put the code in a function in 99_myUtils.pm. But since I've have a few cameras, I would like to pass arguments to this function to select different camera devices. Do you know how to do it ?

this is my function :


sub
snap2telegram
{
my $time = localtime();
fhem("get firstcam image");
my $snapshot = ReadingsVal("firstcam", "last", "");
my $storage = AttrVal("firstcam","storage","");
my $path = "${storage}/${snapshot}";
fhem("sleep 2; set robotTelegram sendImage $path $time");
}


My next move is to launch a command to grab a video on demand with ffmpeg. All advises are welcome !

Thanks again

MadMax-FHEM

#4
Parameters work like that:


sub mySub($$$)
{
  my($Param1, $Param2, $Param3) = @_;

  if($Param1 eq "Hello")
  {
  }
 
  if(Param2 == 3)
  {
  }

  Log3(undef, 3, "Param3: $Param3);
}


calling like:


{mySub("Value1", Value2, Value3)}


in WebCmd or Notify or or or...

The number of '$' corresponds with the number of parameters you need.
The same for my($x1, $x2, $x3, ...) = @_;

Calling system functions goes like:

qx(SystemCmd) or system("SystemCmd") when using in perl or just put it in (" ") (if I'm not wrong) when using directly from fhem...
(http://www.perlmonks.org/?node_id=928192)

If this is solved then you could mark the thread as solved: rename e.g. [solved] Grabbing and sending webcam pic via telegram problem

Have fun, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

claudio

thanks you very much MadMax you've been a great help.

I'll try to pass arguments like you suggest; I know php but not perl, so it's a little confusing to me.

Have a nice evening