camera snapshot stops working Topic is solved

Moderator: leecollings

Post Reply
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

camera snapshot stops working

Post by Ctenberge »

hello,
I have a script running to take a snapshot from my frontdoor camera and send it via Telegram to my phone. It runs flawless until the shortly. Today I realised that I keep getting the same image for some days now.
So the script is running perfectly, it shows in the logging, but the imagefile in the scripts directory is not updating anymore.
What is going on?
This is the logging:
2020-04-20 20:36:55.001 Status: dzVents: Info: ------ Start internal script: deurbelfoto: Device: "bel naar zolder (bel doorgeven)", Index: 203
2020-04-20 20:36:55.001 Status: dzVents: Info: ------ Finished deurbelfoto
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: camera snapshot stops working

Post by hoeby »

Not easy to help, with only that kind of information.

Which script are you using?
Which OS are you using?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

Domoticz runs on a raspberry pi 3B with Buster and Domoticz update this year.
Its a lua-script from the internet but, a long time ago and I don't remember the site. It worked for some years now.
This is the script:

Code: Select all

return {
    on = { 
       devices = {'Deurbel'},
    },
    execute = function(domoticz, device)
        if(device.state == 'On') then
            local teleTok   = aaaaaaaaa:etcetera
            local chatId    = 123456789
            local snapFile  = '/home/pi/domoticz/scripts/camera_'
            local domoReq   = 'http://192.168.1.35:8080/camsnapshot.jpg?idx=1'
            local camName   = 'Voordeur'
            os.execute('wget -O "/home/pi/domoticz/scripts/camera_Voordeur.jpg" "http://192.168.1.240:80/cgi-bin/snapshot.cgi?chn=1"')
            os.execute('curl -s -X POST "https://api.telegram.org/ aaaaaaaaa:etcetera /sendPhoto?"chat_id=123456789/sendphoto -F  photo="@/home/pi/domoticz/scripts/camera_Voordeur.jpg"')
        end
    end
}
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: camera snapshot stops working

Post by waaren »

Ctenberge wrote: Monday 20 April 2020 21:53 It worked for some years now.
What do see if you enter the commands separately from the Command Line Interface?

Code: Select all

sudo wget -O "/home/pi/domoticz/scripts/camera_Voordeur.jpg" "http://192.168.1.240:80/cgi-bin/snapshot.cgi?chn=1"
sudo curl -s -X POST "https://api.telegram.org/ aaaaaaaaa:etcetera /sendPhoto?"chat_id=123456789/sendphoto -F  photo="@/home/pi/domoticz/scripts/camera_Voordeur.jpg
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: camera snapshot stops working

Post by hoeby »

I use exactly the same script, but mine has an extra row.

This row is added in my script;

Code: Select all

 os.execute("rm " ..snapFile..camName..'.jpg')
When removing it, i notice when the camera_voordeur.jpg file is not there it works. When there is a camera_voordeur.jpg file it doesn't refresh it with a new image. By adding the remove row, it works for me

Yours will look like this with the extra row added.:

Code: Select all

return {
    on = { 
       devices = {'Deurbel'},
    },
    execute = function(domoticz, device)
        if(device.state == 'On') then
            local teleTok   = aaaaaaaaa:etcetera
            local chatId    = 123456789
            local snapFile  = '/home/pi/domoticz/scripts/camera_'
            local domoReq   = 'http://192.168.1.35:8080/camsnapshot.jpg?idx=1'
            local camName   = 'Voordeur'
            os.execute('wget -O "/home/pi/domoticz/scripts/camera_Voordeur.jpg" "http://192.168.1.240:80/cgi-bin/snapshot.cgi?chn=1"')
            os.execute('curl -s -X POST "https://api.telegram.org/ aaaaaaaaa:etcetera /sendPhoto?"chat_id=123456789/sendphoto -F  photo="@/home/pi/domoticz/scripts/camera_Voordeur.jpg"')
            os.execute('rm /home/pi/domoticz/scripts/camera_Voordeur.jpg')
        end
    end
}

Just some extra fune for this script.
When you change one row in the script to this, than your image has text in telegram

Code: Select all

os.execute('curl -s -X POST "https://api.telegram.org/ aaaaaaaaa:etcetera /sendPhoto?"chat_id=123456789/sendphoto -F  photo="@/home/pi/domoticz/scripts/camera_Voordeur.jpg" -F caption="Er wordt aangebeld aan de voordeur."')
The extra fun will look like this

Code: Select all

return {
    on = { 
       devices = {'Deurbel'},
    },
    execute = function(domoticz, device)
        if(device.state == 'On') then
            local teleTok   = aaaaaaaaa:etcetera
            local chatId    = 123456789
            local snapFile  = '/home/pi/domoticz/scripts/camera_'
            local domoReq   = 'http://192.168.1.35:8080/camsnapshot.jpg?idx=1'
            local camName   = 'Voordeur'
            os.execute('wget -O "/home/pi/domoticz/scripts/camera_Voordeur.jpg" "http://192.168.1.240:80/cgi-bin/snapshot.cgi?chn=1"')
            os.execute('curl -s -X POST "https://api.telegram.org/ aaaaaaaaa:etcetera /sendPhoto?"chat_id=123456789/sendphoto -F  photo="@/home/pi/domoticz/scripts/camera_Voordeur.jpg" -F caption="Er wordt aangebeld aan de voordeur."')
            os.execute('rm /home/pi/domoticz/scripts/camera_Voordeur.jpg')
        end
    end
}
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

the reaction on wget:
Connecting to 192.168.1.240:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37829 (37K) [image/jpeg]
Saving to: ‘/home/pi/domoticz/scripts/camera_Voordeur.jpg’

/home/pi/domoticz/scripts/camera_Voor 100%[=========================================================================>] 36.94K --.-KB/s in 0.003s

2020-04-21 23:04:40 (13.7 MB/s) - ‘/home/pi/domoticz/scripts/camera_Voordeur.jpg’ saved [37829/37829]
The second command sends the photo to my phone.
So that all works fine, but the lua script has no wget command because, as you know, it is on the commandline.
I can put it on the switch itself, there one can give a command and that fires a script. But it does not solve this peculiar problem.
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: camera snapshot stops working

Post by waaren »

Ctenberge wrote: Tuesday 21 April 2020 23:17 So that all works fine, but the lua script has no wget command because, as you know, it is on the commandline.
not sure I completely understand your statement on the wget not being in the Lua.
Below script works for me (after entering my teleTok and chatId )

Code: Select all

return 
{
    on = 
    { 
        devices = 
        {
            'Deurbel'
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'sendPicture',
    },

    execute = function(domoticz, device)
    
        local function osCommand(cmd)
            if dz == nil then dz = domoticz end -- make sure dz is declared as domoticz object if not already done earlier 
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end
    
        if device.state == 'On' then
            local teleTok = 'aaaaaaaaa:etcetera'
            local chatId = '123456789'
            local snapFile = '/home/pi/domoticz/scripts/camera_'
            local domoReq = 'http://192.168.1.240:80/cgi-bin/snapshot.cgi?chn=1'
            
            osCommand('wget -O '.. snapFile .. ' ' .. domoReq)
            osCommand('curl -s -X POST "https://api.telegram.org/bot' ..teleTok .. '/sendPhoto?chat_id=' .. chatId .. '" -F  photo=@' .. snapFile .. ' &')
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

I meant that wget is not a command in lua itself. In your script you call it via osCommand. That part is not in my original script, as you can see, and it was never in my script by now. I have got it working now with the adjustments as mentioned here.

So thanks to the contributors for they're comments and instructions. It has set me on the right path.
For me this item can be closed.
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

sorry for the wget not being in my script, I was to fast with my reply. It is there.

But once more, why did it stop making the photo when the script is fired? The only thing changed was the Domoticz-update.
No change in configuration this year. Out of the blue no more photo's taken by the event. I saw the same picture for days but I realised it only this week.
As you can see, in my script there is no deleting of the photo, it gets overwritten by the new photo.
When I deleted the picture by hand, there was no new one when the doorbel was ringing.
Maybe I was not clear on that. Telegram has been working all of the time. The problem was in the making of the photo.

But as I mentioned in my (way to soon) post, It has been solved.
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: camera snapshot stops working

Post by hoeby »

When i read your reply, than i would say it is a rights problem to the directory the image needs to be written in.
This parts doesn't give an error, there should be an image, but it is not you have written.
When rights are not correct, than writting images is not possible.

Don't know if domoticz updates can change rights to directories.
Check which rights your /home/pi/domoticz/scripts directory has.
Ctenberge wrote: Tuesday 21 April 2020 23:17 the reaction on wget:
Connecting to 192.168.1.240:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37829 (37K) [image/jpeg]
Saving to: ‘/home/pi/domoticz/scripts/camera_Voordeur.jpg’

/home/pi/domoticz/scripts/camera_Voor 100%[=========================================================================>] 36.94K --.-KB/s in 0.003s
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

I have checked the rights to the directory, seems normal:
drwxr-xr-x 8 pi pi 4096 Apr 21 23:04 scripts

Buster runs on a SSD. But I don't think that's relevant.

Last night I tested the commands on commandline and there it was, the snapshot in the /scripts directory. It answers your question as well.
Now I have an executable script with these commands and let it start by the device. Works nice so I let the lua go.
I used your comment too, to notify me that there is someone at the door. Thanks for that.
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
jadijkstra2000
Posts: 58
Joined: Monday 26 May 2014 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: camera snapshot stops working

Post by jadijkstra2000 »

How are you using Telegram? As mine stopped working after the update :(
Ctenberge
Posts: 40
Joined: Friday 03 January 2020 15:41
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Zwolle, the Netherlands
Contact:

Re: camera snapshot stops working

Post by Ctenberge »

Telegram is still working for me after the last update of Domoticz,I think jadijkstra2000 that you have another problem. Propably with the account with Telegram.
To me, this post in question, camera snapshot stops working, is closed for I have found a bypass.
Thanks to all who contributed.
Raspberry Pi 3B, Raspberry Pi 4, RFXCOM - RFXtrx433, Z-wave, ESP8266
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest