Autor Thema: [SOLVED] Grabbing and sending webcam pic via telegram problem  (Gelesen 710 mal)

Offline claudio

  • New Member
  • *
  • Beiträge: 20
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 {
   
   }
}

« Letzte Änderung: 26 Februar 2018, 22:20:31 von claudio »

Online MadMax-FHEM

  • Hero Member
  • *****
  • Beiträge: 3825
  • NIVEAu ist keine Creme...
Antw:Grabbing and sending webcam pic via telegram problem
« Antwort #1 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
FHEM 5.8 PI3: HM-CFG-USB, 40x HM, ZWave-USB, 6x ZWave, EnOcean-PI, 3x EnOcean, DashButtons, CO2, ESP-Multisensor, FireTV, NanoLeaf, ...
FHEM 5.8 PI2: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, KODI, ha-bridge, ...
FHEM 5.8 PI3 (Test): HM-MOD-PCB, Alexa (alexa-fhem), Google Home

Offline RaspiLED

  • Hero Member
  • *****
  • Beiträge: 1722
  • Es begann alles so klein ;-)
Antw:Grabbing and sending webcam pic via telegram problem
« Antwort #2 am: 26 Februar 2018, 19:38:47 »
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, ...

Offline claudio

  • New Member
  • *
  • Beiträge: 20
Antw:Grabbing and sending webcam pic via telegram problem
« Antwort #3 am: 26 Februar 2018, 20:53:01 »
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

Online MadMax-FHEM

  • Hero Member
  • *****
  • Beiträge: 3825
  • NIVEAu ist keine Creme...
Antw:Grabbing and sending webcam pic via telegram problem
« Antwort #4 am: 26 Februar 2018, 21:29:56 »
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
« Letzte Änderung: 26 Februar 2018, 21:34:35 von MadMax-FHEM »
FHEM 5.8 PI3: HM-CFG-USB, 40x HM, ZWave-USB, 6x ZWave, EnOcean-PI, 3x EnOcean, DashButtons, CO2, ESP-Multisensor, FireTV, NanoLeaf, ...
FHEM 5.8 PI2: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, KODI, ha-bridge, ...
FHEM 5.8 PI3 (Test): HM-MOD-PCB, Alexa (alexa-fhem), Google Home

Offline claudio

  • New Member
  • *
  • Beiträge: 20
Antw:Grabbing and sending webcam pic via telegram problem
« Antwort #5 am: 26 Februar 2018, 22:20:17 »
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