Save video file from sd-card DCS-942L to local

This flow is meant to copy the last video file that is saved to the DSC-942l IP camera sd card to a local folder.

A check for new video files is made from minute to minute.

When a new file is found, a check is made every 6 seconds if the file was recorded on the memory card of the camera.

When the file is finished writing to the SD card, the file is then uploaded to a local folder.

The REST API is based on the standard follow:

Network Video Server CGI Application Programming Interface (NVSCGI API)

Source: http://gurau-audibert.hd.free.fr/josdblog/wp-content/uploads/2013/09/EV1180-NVSCGI-API-V1.4a.pdf

[{"id":"338362f0.590e6e","type":"tab","label":"Workflow_Camera","disabled":false,"info":""},{"id":"4e932890.811e18","type":"inject","z":"338362f0.590e6e","name":"start ...","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":100.71438598632812,"y":58.428558349609375,"wires":[["a2cdaaa8.82ee2"]]},{"id":"3e13fbd6.cfd664","type":"http request","z":"338362f0.590e6e","name":"","method":"GET","ret":"txt","url":"","tls":"","x":665.71435546875,"y":144.28570556640625,"wires":[["b10b7802.9b6eb"]]},{"id":"28edc2b5.17d2ce","type":"function","z":"338362f0.590e6e","name":"creat url","func":"var date;\ndate = { payload: dataAtualFormatada()};\nif (msg.payload === 0){\n    msg.payload={};\n    msg.payload.url = \"http://10.200.0.100/config/sdcard_list.cgi?path=\"+date.payload+\"&pagesize=100\";\n    flow.set(\"numberfile\",-1);\n} else if (msg.payload === 1){\n    msg.payload={};\n    msg.payload.url = \"http://10.200.0.100/config/sdcard_list.cgi?path=\"+date.payload+\"&pagesize=100\";\n}\nreturn msg;\n//####### Function ################\nfunction dataAtualFormatada(){\n    var data = new Date(),\n        dia = data.getDate();\n    if (dia.toString().length == 1)\n      dia = \"0\"+dia;\n    var mes = data.getMonth()+1;\n    if (mes.toString().length == 1)\n      mes = \"0\"+mes;\n    var ano = data.getFullYear();  \n    return ano+mes+dia;\n}\n","outputs":"1","noerr":0,"x":470.00006103515625,"y":308.14283752441406,"wires":[["bf6b0fa5.b790c8"]],"inputLabels":["msg.payload"]},{"id":"bf6b0fa5.b790c8","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload.url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570.0000610351562,"y":97.14283752441406,"wires":[["3e13fbd6.cfd664"]]},{"id":"9df1720a.30166","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload.url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1144.0000610351562,"y":472.14280700683594,"wires":[["e8c34860.7b57e8"]]},{"id":"e8c34860.7b57e8","type":"http request","z":"338362f0.590e6e","name":"","method":"GET","ret":"txt","url":"","tls":"","x":1147.0000610351562,"y":533.1428070068359,"wires":[["972cfd43.b2aae"]]},{"id":"31b77dba.e0a9d2","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1157.0000610351562,"y":644.1428375244141,"wires":[["366121aa.46d6f6"]]},{"id":"366121aa.46d6f6","type":"http request","z":"338362f0.590e6e","name":"","method":"GET","ret":"bin","url":"","tls":"","x":1150.0000610351562,"y":718.1428070068359,"wires":[["14299558.eac673","56eea519.554834"]]},{"id":"972cfd43.b2aae","type":"function","z":"338362f0.590e6e","name":"url&filename","func":"var size = msg.payload.length,\n    nameoffile_t,\n    pos_ini,\n    pos_fin,\n    nameoffile,\n    pathfull,\n    msg;\n\nif (size > 110){\n    nameoffile_t = msg.payload.toString().slice(pos_fin-35,size);\n    pos_ini      = nameoffile_t.indexOf(\":\");\n    pos_fin      = nameoffile_t.indexOf(\".mp4|\");\n    nameoffile   = nameoffile_t.slice(pos_ini+1,pos_fin+4);\n    nameoffile   = {payload : nameoffile};\n    pos_ini      = msg.payload.toString().indexOf(\"path=\");\n    pos_fin      = msg.payload.toString().indexOf(\"page=\");\n    pathfull     = msg.payload.toString().slice(pos_ini+5,pos_fin-2);\n    pathfull     = {payload : pathfull};\n}else{\n    nameoffile=\"none\";\n}\nmsg          = { payload: 'http://'+flow.get('host')+'/config/sdcard_download.cgi?path='+pathfull.payload+'&file='+nameoffile.payload};\nmsg.filename = '/tmp/test/'+nameoffile.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"x":1156.0000610351562,"y":588.1428375244141,"wires":[["31b77dba.e0a9d2"]]},{"id":"14299558.eac673","type":"file","z":"338362f0.590e6e","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","x":1158.0000610351562,"y":774.1428375244141,"wires":[]},{"id":"bde51349.73b2c","type":"switch","z":"338362f0.590e6e","name":"","property":"payload.switch","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"false","outputs":2,"x":1010.0000610351562,"y":97.14283752441406,"wires":[["6c498439.fb013c"],["ba3f14f1.cb4a08"]]},{"id":"b10b7802.9b6eb","type":"function","z":"338362f0.590e6e","name":"url&numberfile&numfile","func":"var size = msg.payload.length,\n    pos_ini,\n    pos_fin,\n    lasthour_t,\n    lasthour,\n    numfile,\n    lasthour2,\n    path,\n    pathfull_t,\n    pathfull,\n    test;\n//######### Checks if file for the day ################\nif (size){\n    //#### Checks if this is the first recording time of the day #####\n    test = msg.payload.toString().indexOf(\":\");\n    //#### if(test > 1) there is more recording time #########\n    if(test > 1){    \n        pos_ini     =  msg.payload.toString().indexOf(\"items=\");\n        pos_fin     =  msg.payload.length;\n        lasthour_t  =  msg.payload.toString().slice(pos_fin-12,pos_fin-1);\n        pos_ini     =  lasthour_t.toString().indexOf(\"n|\");\n        pos_fin     =  lasthour_t.length;\n        numfile     =  { payload: lasthour_t.toString().slice(pos_ini+2,pos_fin-1)};\n        pos_ini     =  lasthour_t.toString().indexOf(\":\");\n        pos_fin     =  lasthour_t.toString().indexOf(\"|\");\n        lasthour    =  { payload: lasthour_t.toString().slice(pos_ini+1,pos_fin)};\n        pos_ini     =  msg.payload.toString().indexOf(\"path=\");\n        pos_fin     =  msg.payload.toString().indexOf(\"page=\");\n        path        =  { payload: msg.payload.toString().slice(pos_ini+5,pos_fin-2)};\n        pathfull_t  =  path.payload+\"/\"+lasthour.payload;\n        pathfull    =  { payload: pathfull_t.toString()};\n    }else{\n        pos_ini     =  msg.payload.toString().indexOf(\"items=\");\n        pos_fin     =  msg.payload.length;\n        lasthour    =  { payload: msg.payload.toString().slice(pos_ini+6,pos_ini+8)};\n        numfile_t   =  { payload: msg.payload.toString().slice(pos_ini+6,pos_fin-1)};\n        pos_ini     =  numfile_t.toString().indexOf(\"n|\");\n        numfile     =  { payload: numfile_t.toString().slice(pos_ini+2,pos_fin)};\n        pos_ini     =  msg.payload.toString().indexOf(\"path=\");\n        pos_fin     =  msg.payload.toString().indexOf(\"page=\");\n        path        =  { payload: msg.payload.toString().slice(pos_ini+5,pos_fin-2)};\n        pathfull_t  =  path.payload+\"/\"+lasthour.payload;\n        pathfull    =  { payload: pathfull_t.toString()};\n    }\n    msg.payload            = {};\n    msg.payload.url        = 'http://'+flow.get('host')+'/config/sdcard_list.cgi?path='+pathfull.payload+'&pagesize=100';\n    msg.payload.notify     = 'http://'+flow.get('host')+'/config/notify.cgi';\n    msg.payload.numfile    = Number(numfile.payload);\n    msg.payload.numberfile = flow.get('numberfile');\n    //msg.payload.teste      = lasthour_t;\n    flow.set('url','http://'+flow.get('host')+'/config/sdcard_list.cgi?path='+pathfull.payload+'&pagesize=100');\n    return msg;\n}else{\n    //##### TODO \n    msg.payload=\"Não tem arquivo\";\n    return msg;\n}","outputs":"1","noerr":0,"x":810.0000610351562,"y":97.14283752441406,"wires":[["e87601dd.c36db"]]},{"id":"56eea519.554834","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":402.00006103515625,"y":487.14283752441406,"wires":[["28edc2b5.17d2ce"]]},{"id":"140d0c97.50b02b","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1335.7144775390625,"y":122.85713195800781,"wires":[["28edc2b5.17d2ce"]]},{"id":"6c498439.fb013c","type":"delay","z":"338362f0.590e6e","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1134.285888671875,"y":59.99998474121094,"wires":[["140d0c97.50b02b"]]},{"id":"e87601dd.c36db","type":"function","z":"338362f0.590e6e","name":"check new file","func":"/*\nThis node is responsible for defining:\n- if is the first time to run option: \"msg.payload.numberfile === -1\"\n- if there is no new file     option: \"msg.payload.numberfile === msg.payload.numfile\"\n- if there is new file        option: \"msg.payload.numberfile < msg.payload.numfile\"\n\n*/\nif (msg.payload.numberfile === -1){\n    msg.payload.switch=true;\n    flow.set(\"numberfile\",Number(msg.payload.numfile));\n}else if(msg.payload.numberfile === msg.payload.numfile){\n    msg.payload.switch=false;\n}else if(msg.payload.numberfile < msg.payload.numfile){\n    msg.payload.switch=true;\n    flow.set(\"numberfile\",Number(msg.payload.numfile));\n}\nreturn msg;","outputs":"1","noerr":0,"x":940.0000610351562,"y":147.14285278320312,"wires":[["bde51349.73b2c"]]},{"id":"6813200f.f749f","type":"http request","z":"338362f0.590e6e","name":"","method":"GET","ret":"txt","url":"","tls":"","x":1322.0001220703125,"y":213.14283752441406,"wires":[["4f2c7e0a.62ebf"]]},{"id":"4f2c7e0a.62ebf","type":"function","z":"338362f0.590e6e","name":"Recording","func":"var total   =  msg.payload,\n    pos_ini,\n    pos_fin,\n    recording;\n    \npos_ini           = msg.payload.toString().indexOf(\"recording=\");\npos_fin           = msg.payload.toString().indexOf(\"vsignal=\");\nrecording         = msg.payload.toString().slice(pos_ini+10,pos_fin-2);\nmsg.payload       = {};\nmsg.payload.rec   = recording;\nmsg.payload.total = total;\nreturn msg;","outputs":1,"noerr":0,"x":1490.0000610351562,"y":255.14283752441406,"wires":[["7f982891.d534a8"]]},{"id":"7f982891.d534a8","type":"switch","z":"338362f0.590e6e","name":"","property":"payload.rec","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"false","outputs":2,"x":981.0000610351562,"y":373.14283752441406,"wires":[["63333579.75ce24"],["e8c60cb9.70b3a"]]},{"id":"ba3f14f1.cb4a08","type":"change","z":"338362f0.590e6e","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"payload.notify","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1134.285888671875,"y":135.7142791748047,"wires":[["6813200f.f749f"]]},{"id":"e8c60cb9.70b3a","type":"function","z":"338362f0.590e6e","name":"get url","func":"msg.payload.url=flow.get(\"url\");\nreturn msg;","outputs":1,"noerr":0,"x":1133.0000610351562,"y":410.14283752441406,"wires":[["9df1720a.30166"]]},{"id":"63333579.75ce24","type":"delay","z":"338362f0.590e6e","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1143.0000610351562,"y":290.14283752441406,"wires":[["6813200f.f749f"]]},{"id":"a2cdaaa8.82ee2","type":"function","z":"338362f0.590e6e","name":"flow variables ","func":"flow.set('host','10.200.0.100');\nreturn msg;","outputs":1,"noerr":0,"x":247.85723876953125,"y":174.0475616455078,"wires":[["28edc2b5.17d2ce"]]}]
tiagopina

Flow Info

created 3 months, 1 week ago

Node Types

Core
  • change (x6)
  • delay (x2)
  • file (x1)
  • function (x7)
  • http request (x4)
  • inject (x1)
  • switch (x2)
Other
  • tab (x1)

Tags

  • DSC-942l
  • camera
  • IP
  • save
  • local
  • file
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option