49_SSCam.pm 331 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751
  1. #########################################################################################################################
  2. # $Id: 49_SSCam.pm 16273 2018-02-25 19:46:25Z DS_Starter $
  3. #########################################################################################################################
  4. # 49_SSCam.pm
  5. #
  6. # (c) 2015-2018 by Heiko Maaz
  7. # e-mail: Heiko dot Maaz at t-online dot de
  8. #
  9. # This Module can be used to operate Cameras defined in Synology Surveillance Station 7.0 or higher.
  10. # It's based on and uses Synology Surveillance Station API.
  11. #
  12. # This script is part of fhem.
  13. #
  14. # Fhem is free software: you can redistribute it and/or modify
  15. # it under the terms of the GNU General Public License as published by
  16. # the Free Software Foundation, either version 2 of the License, or
  17. # (at your option) any later version.
  18. #
  19. # Fhem is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. # GNU General Public License for more details.
  23. #
  24. # You should have received a copy of the GNU General Public License
  25. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  26. #
  27. #########################################################################################################################
  28. # Versions History:
  29. #
  30. # 3.3.0 25.02.2018 code review, API bug fix of runview lastrec, commandref revised (forum:#84953)
  31. # 3.2.4 18.11.2017 fix bug don't retrieve SSCam_getptzlistpreset if cam is disabled
  32. # 3.2.3 08.10.2017 set optimizeParams, get caminfo (simple), minor bugfix, commandref revised
  33. # 3.2.2 03.10.2017 make functions ready to use "SYNO.SurveillanceStation.PTZ" version 5, minor fixes, commandref
  34. # revised
  35. # 3.2.1 02.10.2017 change some "SYNO.SurveillanceStation.Camera" methods to version 9
  36. # 3.2.0 27.09.2017 new command get listLog, change to $hash->{HELPER}{".SNAPHASH"} for avoid huge "list"-report
  37. # 3.1.0 26.09.2017 move extevent from CAM to SVS model, Reading PollState enhanced for CAM-Model, minor fixes
  38. # 3.0.0 23.09.2017 Internal MODEL SVS or CAM -> distinguish/support Cams and SVS in different devices
  39. # new comand get storedCredentials, commandref revised
  40. # 2.9.0 20.09.2017 new function get homeModeState, minor fixes at simu_SVSversion, commandref revised
  41. # 2.8.2 19.09.2017 some preparations for version 9 of API "SYNO.SurveillanceStation.Camera", SSCam_logout added to function
  42. # get scanVirginirgin
  43. # 2.8.1 17.09.2017 attr simu_SVSversion changed, $mjpegHttp quotes dependend if noQuotesForSID set, commandref revised
  44. # 2.8.0 07.09.2017 Home Mode, commandref revised
  45. # 2.7.1 28.08.2017 minor fixes
  46. # 2.7.0 20.08.2017 bugfix if credentials not set, set maximum password lenth to 20
  47. # 2.6.3 12.08.2017 get snapGallery can also be triggered by at or notify (better use than "set"), commandref revised
  48. # 2.6.2 11.08.2017 set snapGallery can be triggered by at or notify
  49. # 2.6.1 07.08.2017 some changes in composegallery if createSnapGallery used, room Snapshots changed to SnapGalllery
  50. # commandref revised
  51. # 2.6.0 06.08.2017 new command createSnapGallery
  52. # 2.5.4 05.08.2017 analyze $hash->{CL} in SetFn bzw. GetFn, set snapGallery only if snapGalleryBoost=1 is set,
  53. # some snapGallery improvements and fixes
  54. # 2.5.3 02.08.2017 implement snapGallery as set-command
  55. # 2.5.2 01.08.2017 get snapGallery with or without snapGalleryBoost (some more attributes for snapGallery)
  56. # 2.5.1 31.07.2017 sub composegallery (no polling necessary)
  57. # 2.5.0 31.07.2017 logtext revised, new get snapGallery command
  58. # 2.4.1 29.07.2017 fix behavior of state when starting lastsnap_fw, fix "uninitialized value in pattern match (m//)
  59. # at ./FHEM/49_SSCam.pm line 2895"
  60. # 2.4.0 28.07.2017 new set command runView lastsnap_fw, commandref revised, minor fixes
  61. # 2.3.2 28.07.2017 code change of getcaminfo (params of Internaltimer)
  62. # 2.3.1 28.07.2017 code review creating log entries when pollnologging is set/unset
  63. # 2.3.0 27.07.2017 new "get snapinfo" command, minor fixes
  64. # 2.2.4 25.07.2017 avoid error "Operation Getptzlistpreset of Camera ... was not successful" if cam is disabled
  65. # 2.2.3 30.06.2017 fix if SVSversion small "0", create events for "snap"
  66. # 2.2.2 11.06.2017 bugfix SSCam_login, SSCam_login_return,
  67. # Forum: https://forum.fhem.de/index.php/topic,45671.msg646701.html#msg646701
  68. # 2.2.1 15.05.2017 avoid FW_detailFn because of FW_deviceOverview is active (double streams in detailview if on)
  69. # 2.2.0 10.05.2017 check if JSON module has been loaded successfully, DeviceOverview available, options of
  70. # runView changed image->live_fw, link->live_link, link_open->live_open, lastrec ->lastrec_fw,
  71. # commandref revised
  72. # 2.1.4 08.05.2017 commandref changed
  73. # 2.1.3 05.05.2017 issue of operation error if CAMID is set and SID isn't valid, more login-errorcodes evaluation
  74. # 2.1.2 04.05.2017 default login retries increased to 3
  75. # 2.1.1 17.04.2017 SSCam_runliveview routine changed, {HELPER}{SID_STRM} deleted
  76. # 2.1.0 12.04.2017 some codereview, getapisites cached, CAMID cached, rewrite logs from verbose 4 to 5,
  77. # get scanVirgin, commandref replenished
  78. # 2.0.0 10.04.2017 redesign login procedure, fix Reading SVSversion use SMALL version, new attr loginRetries
  79. # 1.42 15.03.2017 SSCam_camop changed to get all cam id's and names
  80. # 1.41 15.03.2017 minor bugfix of blank character in state "disabled" (row 3383)
  81. # 1.40 21.01.2017 downgrade of API apicammaxver in SVS 8.0.0
  82. # 1.39 20.01.2017 compatibility to SVS 8.0.0, Version in Internals, execute getsvsinfo after set credentials
  83. # 1.37 10.10.2016 bugfix Experimental keys on scalar is now forbidden (Perl >= 5.23)
  84. # (Forum: #msg501709)
  85. # 1.36 18.09.2016 bugfix of get presets, get patrols of zoom-cams without pan/tilt
  86. # 1.35 17.09.2016 internal timer of start-routines optimized
  87. # 1.34 15.09.2016 simu_SVSversion changed, added 407 errorcode message, external recording changed
  88. # for SVS 7.2
  89. # 1.33 21.08.2016 function get stmUrlPath added, fit to new commandref style, attribute showStmInfoFull added
  90. # 1.32.1 18.08.2016 empty event LastSnapId fixed
  91. # 1.32 17.08.2016 Logging of verbose 4 changed
  92. # 1.31 15.08.2016 Attr "noQuotesForSID" added, avoid possible 402 - permission denied problems
  93. # in some SVS/DS-combinations
  94. # 1.30 15.08.2016 commandref revised, more v4 logging in special case
  95. # 1.29 02.07.2016 add regex for adaption SVS version, url call for "snap" changed
  96. # 1.28 30.06.2016 Attr "showPassInLog" added, per default no password will be shown in log
  97. # 1.27 29.06.2016 Attr "simu_SVSversion" added, sub login_nonbl changed,
  98. # sub camret_nonbl changed (getlistptzpreset) due to 7.2 problem
  99. # 1.26.3 28.06.2016 Time::HiRes added
  100. # 1.26.2 05.05.2016 change: get "snapfileinfo" will get back an Infomessage if Reading "LastSnapId"
  101. # isn't available
  102. # 1.26.1 27.04.2016 bugfix module will not load due to Unknown warnings category 'experimental'
  103. # when using an older perl version
  104. # 1.26 22.04.2016 Attribute "disable" to deactivate the module added
  105. # 1.25 18.04.2016 motion detection parameters can be entered if
  106. # motion detection by camera or SVS is used
  107. # 1.24 16.04.2016 behavior of "set ... on" changed, Attr "recextend" added
  108. # please have a look at commandref and Wiki
  109. # bugfix: setstate-warning if FHEM will restarted and SVS is not reachable
  110. # (Forum: #308)
  111. # 1.23.2 12.04.2016 code review, no functional changes
  112. # 1.23.1 07.04.2016 command check for set cmd's don't work completely
  113. # 1.23 02.04.2016 change to RemoveInternalTimer for functions
  114. # 1.22 27.03.2016 bugfix "link_open" doesn't work after last update
  115. # 1.21 23.03.2016 added "lastrec"," lastrec_open" to playback last recording
  116. # 1.20.3 19.03.2016 change: delay of InternalTimer(s) changed
  117. # "ptzlistpresets" - "id" changed to "position" according to Synology-ticket
  118. # run "SSCam_geteventlist" automatically after recording-stop
  119. # 1.20.2 14.03.2016 change: routine "SSCam_initonboot" changed
  120. # 1.20.1 12.03.2016 bugfix: default recordtime 15 s is used if attribute "rectime" is set to "0"
  121. # 1.20 09.03.2016 command "extevent" added
  122. # 1.19.3 07.03.2016 bugfix "uninitialized value $lastrecstarttime",
  123. # "uninitialized value $lastrecstoptime",
  124. # new attribute "videofolderMap"
  125. # 1.19.2 06.03.2016 Reading "CamLastRec" added which contains Path/name
  126. # of last recording
  127. # 1.19.1 28.02.2016 enhanced command runView by option "link_open" to
  128. # open a streamlink immediately
  129. # 1.19 25.02.2016 functions for cam-livestream added
  130. # 1.18.1 21.02.2016 fixed a problem that the state is "disable" instead of
  131. # "disabled" if a camera is disabled and FHEM will be restarted
  132. # 1.18 20.02.2016 function "get ... eventlist" added,
  133. # Reading "CamEventNum" added which containes total number of
  134. # camera events,
  135. # change usage of reading "LastUpdateTime"
  136. # 1.17 19.02.2016 function "runPatrol" added that starts predefined patrols
  137. # of PTZ-cameras,
  138. # Reading "CamDetMotSc" added
  139. # 1.16.1 17.02.2016 Reading "CamExposureControl" added
  140. # 1.16 16.02.2016 set up of motion detection source now possible
  141. # 1.15 15.02.2016 control of exposure mode day, night & auto is possible now
  142. # 1.14 14.02.2016 The port in DEF-String is optional now,
  143. # if not given, default port 5000 is used
  144. # 1.13.2 13.02.2016 fixed a problem that manual updates using "getcaminfoall" are
  145. # leading to additional pollingloops if polling is used,
  146. # attribute "debugactivetoken" added for debugging-use
  147. # 1.13.1 12.02.2016 fixed a problem that a usersession won't be destroyed if a
  148. # function couldn't be executed successfully
  149. # 1.13 feature for retrieval snapfilename added
  150. # 1.12.1 09.02.2016 bugfix: "goAbsPTZ" may be unavailable on Windows-systems
  151. # 1.12 08.02.2016 added function "move" for continuous PTZ action
  152. # 1.11.1 07.02.2016 entries with loglevel "2" reviewed, changed to loglevel "3"
  153. # 1.11 05.02.2016 added function "goPreset" and "goAbsPTZ" to control the move of PTZ lense
  154. # to absolute positions
  155. # refere to commandref or have a look in forum at:
  156. # http://forum.fhem.de/index.php/topic,45671.msg404275.html#msg404275 ,
  157. # http://forum.fhem.de/index.php/topic,45671.msg404892.html#msg404892
  158. # 1.10 02.02.2016 added function "svsinfo" to get informations about installed SVS-package,
  159. # if Availability = " disconnected" then "state"-value will be "disconnected" too,
  160. # saved Credentials were deleted from file if a device will be deleted
  161. # 1.9.1 31.01.2016 a little bit code optimization
  162. # 1.9 28.01.2016 fixed the problem a recording may still stay active if fhem
  163. # will be restarted after a recording was triggered and
  164. # the recordingtime wasn't be over,
  165. # Enhancement of readings.
  166. # 1.8 25.01.2016 changed define in order to remove credentials from string,
  167. # added "set credentials" command to save username/password,
  168. # added Attribute "session" to make login-session selectable,
  169. # Note: You have to adapt your define-strings !!
  170. # Refere to commandref or look in forum at:
  171. # http://forum.fhem.de/index.php/topic,45671.msg397449.html#msg397449
  172. # 1.7 18.01.2016 Attribute "httptimeout" added
  173. # 1.6 16.01.2016 Change the define-string related to rectime.
  174. # Note: See all changes to rectime usage in commandref or here:
  175. # http://forum.fhem.de/index.php/topic,45671.msg391664.html#msg391664
  176. # 1.5.1 11.01.2016 Vars "USERNAME" and "RECTIME" removed from internals,
  177. # Var (Internals) "SERVERNAME" changed to "SERVERADDR",
  178. # minor change of Log messages,
  179. # Note: use rereadcfg in order to activate the changes
  180. # 1.5 04.01.2016 Function "Get" for creating Camera-Readings integrated,
  181. # Attributs pollcaminfoall, pollnologging added,
  182. # Function for Polling Cam-Infos added.
  183. # 1.4 23.12.2015 function "enable" and "disable" for SS-Cams added,
  184. # changed timout of Http-calls to a higher value
  185. # 1.3 19.12.2015 function "snap" for taking snapshots added,
  186. # fixed a bug that functions may impact each other
  187. # 1.2 14.12.2015 improve usage of verbose-modes
  188. # 1.1 13.12.2015 use of InternalTimer instead of fhem(sleep)
  189. # 1.0 12.12.2015 changed completly to HttpUtils_NonblockingGet for calling websites nonblocking,
  190. # LWP is not needed anymore
  191. #
  192. #
  193. # Definition: define <name> SSCam <camname> <ServerAddr> [ServerPort]
  194. #
  195. # Example of defining a Cam-device: define CamCP1 SSCAM Carport 192.168.2.20 [5000]
  196. # Example of defining a SVS-device: define SDS1 SSCAM SVS 192.168.2.20 [5000]
  197. #
  198. package main;
  199. eval "use JSON qw( decode_json );1;" or my $SScamMMDBI = "JSON"; # Debian: apt-get install libjson-perl
  200. use Data::Dumper; # Perl Core module
  201. use strict;
  202. use warnings;
  203. use MIME::Base64;
  204. use Time::HiRes;
  205. use HttpUtils;
  206. # no if $] >= 5.017011, warnings => 'experimental';
  207. my $SSCamVersion = "3.3.0";
  208. # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API)
  209. my %SSCam_errauthlist = (
  210. 100 => "Unknown error",
  211. 101 => "The account parameter is not specified",
  212. 102 => "API does not exist",
  213. 400 => "Invalid user or password",
  214. 401 => "Guest or disabled account",
  215. 402 => "Permission denied - DSM-Session: make sure user is member of Admin-group, SVS-Session: make sure SVS package is started, make sure FHEM-Server IP won't be blocked in DSM automated blocking list",
  216. 403 => "One time password not specified",
  217. 404 => "One time password authenticate failed",
  218. 405 => "method not allowd - maybe the password is too long",
  219. 407 => "Permission denied - make sure FHEM-Server IP won't be blocked in DSM automated blocking list",
  220. );
  221. my %SSCam_errlist = (
  222. 100 => "Unknown error",
  223. 101 => "Invalid parameters",
  224. 102 => "API does not exist",
  225. 103 => "Method does not exist",
  226. 104 => "This API version is not supported",
  227. 105 => "Insufficient user privilege",
  228. 106 => "Connection time out",
  229. 107 => "Multiple login detected",
  230. 117 => "need manager rights in SurveillanceStation for operation",
  231. 400 => "Execution failed",
  232. 401 => "Parameter invalid",
  233. 402 => "Camera disabled",
  234. 403 => "Insufficient license",
  235. 404 => "Codec activation failed",
  236. 405 => "CMS server connection failed",
  237. 407 => "CMS closed",
  238. 410 => "Service is not enabled",
  239. 412 => "Need to add license",
  240. 413 => "Reach the maximum of platform",
  241. 414 => "Some events not exist",
  242. 415 => "message connect failed",
  243. 417 => "Test Connection Error",
  244. 418 => "Object is not exist",
  245. 419 => "Visualstation name repetition",
  246. 439 => "Too many items selected",
  247. 502 => "Camera disconnected",
  248. 600 => "Presetname and PresetID not found in Hash",
  249. );
  250. # Standardvariablen
  251. my $SSCam_slim = 3; # default Anzahl der abzurufenden Schnappschüsse mit snapGallery
  252. my $SSCAM_snum = "1,2,3,4,5,6,7,8,9,10"; # mögliche Anzahl der abzurufenden Schnappschüsse mit snapGallery
  253. sub SSCam_Initialize($) {
  254. my ($hash) = @_;
  255. $hash->{DefFn} = "SSCam_Define";
  256. $hash->{UndefFn} = "SSCam_Undef";
  257. $hash->{DeleteFn} = "SSCam_Delete";
  258. $hash->{SetFn} = "SSCam_Set";
  259. $hash->{GetFn} = "SSCam_Get";
  260. $hash->{AttrFn} = "SSCam_Attr";
  261. # Aufrufe aus FHEMWEB
  262. $hash->{FW_summaryFn} = "SSCam_FWview";
  263. # $hash->{FW_detailFn} = "SSCam_FWview";
  264. $hash->{FW_deviceOverview} = 1;
  265. $hash->{AttrList} =
  266. "disable:1,0 ".
  267. "httptimeout ".
  268. "htmlattr ".
  269. "livestreamprefix ".
  270. "loginRetries:1,2,3,4,5,6,7,8,9,10 ".
  271. "videofolderMap ".
  272. "pollcaminfoall ".
  273. "snapGalleryBoost:0,1 ".
  274. "snapGallerySize:Icon,Full ".
  275. "snapGalleryNumber:$SSCAM_snum ".
  276. "snapGalleryColumns ".
  277. "snapGalleryHtmlAttr ".
  278. "pollnologging:1,0 ".
  279. "debugactivetoken:1 ".
  280. "rectime ".
  281. "recextend:1,0 ".
  282. "noQuotesForSID:1,0 ".
  283. "session:SurveillanceStation,DSM ".
  284. "showPassInLog:1,0 ".
  285. "showStmInfoFull:1,0 ".
  286. "simu_SVSversion:7.2-xxxx,7.1-xxxx,8.0.0-xxxx ".
  287. "webCmd ".
  288. $readingFnAttributes;
  289. return undef;
  290. }
  291. sub SSCam_Define($@) {
  292. # Die Define-Funktion eines Moduls wird von Fhem aufgerufen wenn der Define-Befehl für ein Gerät ausgeführt wird
  293. # Welche und wie viele Parameter akzeptiert werden ist Sache dieser Funktion. Die Werte werden nach dem übergebenen Hash in ein Array aufgeteilt
  294. # define CamCP1 SSCAM Carport 192.168.2.20 [5000]
  295. # ($hash) [1] [2] [3] [4]
  296. #
  297. my ($hash, $def) = @_;
  298. my $name = $hash->{NAME};
  299. return "Error: Perl module ".$SScamMMDBI." is missing. Install it on Debian with: sudo apt-get install libjson-perl" if($SScamMMDBI);
  300. my @a = split("[ \t][ \t]*", $def);
  301. if(int(@a) < 4) {
  302. return "You need to specify more parameters.\n". "Format: define <name> SSCAM <Cameraname> <ServerAddress> [Port]";
  303. }
  304. my $camname = $a[2];
  305. my $serveraddr = $a[3];
  306. my $serverport = $a[4] ? $a[4] : 5000;
  307. $hash->{SERVERADDR} = $serveraddr;
  308. $hash->{SERVERPORT} = $serverport;
  309. $hash->{CAMNAME} = $camname;
  310. $hash->{VERSION} = $SSCamVersion;
  311. $hash->{MODEL} = ($camname =~ m/^SVS$/i)?"SVS":"CAM";
  312. # benötigte API's in $hash einfügen
  313. $hash->{HELPER}{APIINFO} = "SYNO.API.Info"; # Info-Seite für alle API's, einzige statische Seite !
  314. $hash->{HELPER}{APIAUTH} = "SYNO.API.Auth";
  315. $hash->{HELPER}{APISVSINFO} = "SYNO.SurveillanceStation.Info";
  316. $hash->{HELPER}{APIEVENT} = "SYNO.SurveillanceStation.Event";
  317. $hash->{HELPER}{APIEXTREC} = "SYNO.SurveillanceStation.ExternalRecording";
  318. $hash->{HELPER}{APIEXTEVT} = "SYNO.SurveillanceStation.ExternalEvent";
  319. $hash->{HELPER}{APICAM} = "SYNO.SurveillanceStation.Camera";
  320. $hash->{HELPER}{APISNAPSHOT} = "SYNO.SurveillanceStation.SnapShot";
  321. $hash->{HELPER}{APIPTZ} = "SYNO.SurveillanceStation.PTZ";
  322. $hash->{HELPER}{APICAMEVENT} = "SYNO.SurveillanceStation.Camera.Event";
  323. $hash->{HELPER}{APIVIDEOSTM} = "SYNO.SurveillanceStation.VideoStreaming";
  324. $hash->{HELPER}{APISTM} = "SYNO.SurveillanceStation.Streaming";
  325. $hash->{HELPER}{APIHM} = "SYNO.SurveillanceStation.HomeMode";
  326. $hash->{HELPER}{APILOG} = "SYNO.SurveillanceStation.Log";
  327. # Startwerte setzen
  328. if(SSCam_IsModelCam($hash)) {
  329. $attr{$name}{webCmd} = "on:off:snap:enable:disable"; # initiale Webkommandos setzen
  330. } else {
  331. $attr{$name}{webCmd} = "homeMode";
  332. $attr{$name}{webCmdLabel} = "HomeMode";
  333. }
  334. $hash->{HELPER}{ACTIVE} = "off"; # Funktionstoken "off", Funktionen können sofort starten
  335. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0"; # Loggingfunktion für Polling ist an
  336. $hash->{HELPER}{RECTIME_DEF} = "15"; # Standard für rectime setzen, überschreibbar durch Attribut "rectime" bzw. beim "set .. on-for-time"
  337. readingsBeginUpdate($hash);
  338. readingsBulkUpdate($hash,"PollState","Inactive"); # es ist keine Gerätepolling aktiv
  339. if(SSCam_IsModelCam($hash)) {
  340. readingsBulkUpdate($hash,"Availability", "???"); # Verfügbarkeit ist unbekannt
  341. readingsBulkUpdate($hash,"state", "off"); # Init für "state" , Problemlösung für setstate, Forum #308
  342. } else {
  343. readingsBulkUpdate($hash,"state", "Initialized"); # Init für "state" wenn SVS
  344. }
  345. readingsEndUpdate($hash,1);
  346. SSCam_getcredentials($hash,1); # Credentials lesen und in RAM laden ($boot=1)
  347. # initiale Routinen nach Restart ausführen , verzögerter zufälliger Start
  348. RemoveInternalTimer($hash, "SSCam_initonboot");
  349. InternalTimer(gettimeofday()+int(rand(30)), "SSCam_initonboot", $hash, 0);
  350. return undef;
  351. }
  352. ################################################################
  353. sub SSCam_Undef($$) {
  354. my ($hash, $arg) = @_;
  355. SSCam_logout($hash);
  356. RemoveInternalTimer($hash);
  357. return undef;
  358. }
  359. ################################################################
  360. sub SSCam_Delete($$) {
  361. my ($hash, $arg) = @_;
  362. my $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  363. # gespeicherte Credentials löschen
  364. setKeyValue($index, undef);
  365. # löschen snapGallerie-Device falls vorhanden
  366. my $sgdev = "SSCam.$hash->{NAME}.snapgallery";
  367. CommandDelete($hash->{CL},"$sgdev");
  368. return undef;
  369. }
  370. ################################################################
  371. sub SSCam_Attr($$$$) {
  372. my ($cmd,$name,$aName,$aVal) = @_;
  373. my $hash = $defs{$name};
  374. my ($do,$val);
  375. # $cmd can be "del" or "set"
  376. # $name is device name
  377. # aName and aVal are Attribute name and value
  378. if ($aName eq "disable") {
  379. if($cmd eq "set") {
  380. $do = ($aVal) ? 1 : 0;
  381. }
  382. $do = 0 if($cmd eq "del");
  383. if(SSCam_IsModelCam($hash)) {
  384. $val = ($do == 1 ? "inactive" : "off");
  385. } else {
  386. $val = ($do == 1 ? "disabled" : "initialized");
  387. }
  388. readingsSingleUpdate($hash, "state", $val, 1);
  389. readingsSingleUpdate($hash, "PollState", "Inactive", 1) if($do == 1);
  390. readingsSingleUpdate($hash, "Availability", "???", 1) if($do == 1 && SSCam_IsModelCam($hash));
  391. }
  392. if ($aName eq "showStmInfoFull") {
  393. if($cmd eq "set") {
  394. $do = ($aVal) ? 1 : 0;
  395. }
  396. $do = 0 if($cmd eq "del");
  397. if ($do == 0) {
  398. delete($defs{$name}{READINGS}{StmKeymjpegHttp});
  399. delete($defs{$name}{READINGS}{StmKeyUnicst});
  400. delete($defs{$name}{READINGS}{LiveStreamUrl});
  401. delete($defs{$name}{READINGS}{StmKeyUnicstOverHttp});
  402. }
  403. }
  404. if ($aName eq "snapGallerySize") {
  405. if($cmd eq "set") {
  406. $do = ($aVal eq "Icon")?1:2;
  407. }
  408. $do = 0 if($cmd eq "del");
  409. if ($do == 0) {
  410. delete($hash->{HELPER}{".SNAPHASH"}) if(AttrVal($name,"snapGalleryBoost",0)); # Snaphash nur löschen wenn Snaps gepollt werden
  411. Log3($name, 4, "$name - Snapshot hash deleted");
  412. } elsif (AttrVal($name,"snapGalleryBoost",0)) {
  413. # snap-Infos abhängig ermitteln wenn gepollt werden soll
  414. my ($slim,$ssize);
  415. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  416. $slim = AttrVal($name,"snapGalleryNumber",$SSCam_slim); # Anzahl der abzurufenden Snaps
  417. $ssize = $do;
  418. RemoveInternalTimer("getsnapinfo");
  419. InternalTimer(gettimeofday()+0.7, "getsnapinfo", "$name:$slim:$ssize", 0);
  420. }
  421. }
  422. if ($aName eq "snapGalleryBoost") {
  423. if($cmd eq "set") {
  424. $do = ($aVal == 1)?1:0;
  425. }
  426. $do = 0 if($cmd eq "del");
  427. if ($do == 0) {
  428. delete($hash->{HELPER}{".SNAPHASH"}); # Snaphash löschen
  429. Log3($name, 4, "$name - Snapshot hash deleted");
  430. } else {
  431. # snapgallery regelmäßig neu einlesen wenn Polling ein
  432. return "When you want activate \"snapGalleryBoost\", you have to set the attribute \"pollcaminfoall\" first because the functionality depends on retrieving snapshots periodical."
  433. if(!AttrVal($name,"pollcaminfoall",0));
  434. my ($slim,$ssize);
  435. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  436. $slim = AttrVal($name,"snapGalleryNumber",$SSCam_slim); # Anzahl der abzurufenden Snaps
  437. my $sg = AttrVal($name,"snapGallerySize","Icon"); # Auflösung Image
  438. $ssize = ($sg eq "Icon")?1:2;
  439. RemoveInternalTimer("getsnapinfo");
  440. InternalTimer(gettimeofday()+0.7, "getsnapinfo", "$name:$slim:$ssize", 0);
  441. }
  442. }
  443. if ($aName eq "snapGalleryNumber" && AttrVal($name,"snapGalleryBoost",0)) {
  444. my ($slim,$ssize);
  445. if($cmd eq "set") {
  446. $do = ($aVal != 0)?1:0;
  447. }
  448. $do = 0 if($cmd eq "del");
  449. if ($do == 0) {
  450. $slim = 3;
  451. } else {
  452. $slim = $aVal;
  453. }
  454. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  455. my $sg = AttrVal($name,"snapGallerySize","Icon"); # Auflösung Image
  456. $ssize = ($sg eq "Icon")?1:2;
  457. RemoveInternalTimer("getsnapinfo");
  458. InternalTimer(gettimeofday()+0.7, "getsnapinfo", "$name:$slim:$ssize", 0);
  459. }
  460. if ($aName eq "simu_SVSversion") {
  461. delete $hash->{HELPER}{APIPARSET};
  462. delete $hash->{HELPER}{SID};
  463. delete $hash->{CAMID};
  464. RemoveInternalTimer($hash, "getsvsinfo");
  465. InternalTimer(gettimeofday()+0.5, "getsvsinfo", $hash, 0);
  466. }
  467. if ($cmd eq "set") {
  468. if ($aName =~ m/httptimeout|snapGalleryColumns|rectime|pollcaminfoall/ ) {
  469. unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 1-9 !";}
  470. }
  471. }
  472. if ($cmd eq "del") {
  473. if ($aName =~ m/pollcaminfoall/ ) {
  474. # Polling nicht ausschalten wenn snapGalleryBoost ein (regelmäßig neu einlesen)
  475. return "Please switch off \"snapGalleryBoost\" first if you want to deactivate \"pollcaminfoall\" because the functionality of \"snapGalleryBoost\" depends on retrieving snapshots periodical."
  476. if(AttrVal($name,"snapGalleryBoost",0));
  477. }
  478. }
  479. return undef;
  480. }
  481. ################################################################
  482. sub SSCam_Set($@) {
  483. my ($hash, @a) = @_;
  484. return "\"set X\" needs at least an argument" if ( @a < 2 );
  485. my $name = $a[0];
  486. my $opt = $a[1];
  487. my $prop = $a[2];
  488. my $prop1 = $a[3];
  489. my $prop2 = $a[4];
  490. my $prop3 = $a[5];
  491. my $camname = $hash->{CAMNAME};
  492. my $success;
  493. my $setlist;
  494. my @prop;
  495. return "module is deactivated" if(IsDisabled($name));
  496. if(SSCam_IsModelCam($hash)) {
  497. # selist für Cams
  498. $setlist = "Unknown argument $opt, choose one of ".
  499. "credentials ".
  500. "expmode:auto,day,night ".
  501. "on ".
  502. "off ".
  503. "motdetsc:disable,camera,SVS ".
  504. "snap ".
  505. (AttrVal($name, "snapGalleryBoost",0)?(AttrVal($name,"snapGalleryNumber",undef) || AttrVal($name,"snapGalleryBoost",0))?"snapGallery:noArg ":"snapGallery:$SSCAM_snum ":" ").
  506. "createSnapGallery:noArg ".
  507. "enable ".
  508. "disable ".
  509. "optimizeParams ".
  510. "runView:live_fw,live_link,live_open,lastrec_fw,lastrec_open,lastsnap_fw ".
  511. "stopView:noArg ".
  512. ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : "").
  513. ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "goPreset:".ReadingsVal("$name", "Presets", "")." " : "").
  514. ((ReadingsVal("$name", "CapPTZAbs", "false") ne "false") ? "goAbsPTZ"." " : "").
  515. ((ReadingsVal("$name", "CapPTZDirections", "0") > 0) ? "move"." " : "");
  516. } else {
  517. # setlist für SVS Devices
  518. $setlist = "Unknown argument $opt, choose one of ".
  519. "credentials ".
  520. "extevent:1,2,3,4,5,6,7,8,9,10 ".
  521. ($hash->{HELPER}{APIHMMAXVER}?"homeMode:on,off ": "");
  522. }
  523. if ($opt eq "on" && SSCam_IsModelCam($hash)) {
  524. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  525. if (defined($prop)) {
  526. unless ($prop =~ /^\d+$/) { return " The Value for \"$opt\" is not valid. Use only figures 0-9 without decimal places !";}
  527. $hash->{HELPER}{RECTIME_TEMP} = $prop;
  528. }
  529. SSCam_camstartrec($hash);
  530. } elsif ($opt eq "off" && SSCam_IsModelCam($hash)) {
  531. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  532. SSCam_camstoprec($hash);
  533. } elsif ($opt eq "snap" && SSCam_IsModelCam($hash)) {
  534. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  535. SSCam_camsnap($hash);
  536. } elsif ($opt eq "snapGallery" && SSCam_IsModelCam($hash)) {
  537. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  538. my $ret = SSCam_getclhash($hash);
  539. return $ret if($ret);
  540. if(!AttrVal($name, "snapGalleryBoost",0)) {
  541. # Snaphash ist nicht vorhanden und wird neu abgerufen und ausgegeben
  542. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  543. # snap-Infos für Gallerie abrufen
  544. my ($sg,$slim,$ssize);
  545. $slim = $prop?AttrVal($name,"snapGalleryNumber",$prop):AttrVal($name,"snapGalleryNumber",$SSCam_slim); # Anzahl der abzurufenden Snapshots
  546. $ssize = (AttrVal($name,"snapGallerySize","Icon") eq "Icon")?1:2; # Image Size 1-Icon, 2-Full
  547. getsnapinfo("$name:$slim:$ssize");
  548. } else {
  549. # Snaphash ist vorhanden und wird zur Ausgabe aufbereitet (Polling ist aktiv)
  550. my $htmlCode = composegallery($name);
  551. for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) {
  552. if ($hash->{HELPER}{CL}{$k}->{COMP}) {
  553. # CL zusammengestellt (Auslösung durch Notify)
  554. asyncOutput($hash->{HELPER}{CL}{$k}, "$htmlCode");
  555. } else {
  556. # Output wurde über FHEMWEB ausgelöst
  557. return $htmlCode;
  558. }
  559. }
  560. delete($hash->{HELPER}{CL});
  561. }
  562. } elsif ($opt eq "createSnapGallery" && SSCam_IsModelCam($hash)) {
  563. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  564. my ($ret,$sgdev);
  565. return "When you want use \"$opt\", you have to set the attribute \"snapGalleryBoost\" first because the functionality depends on retrieving snapshots automatically."
  566. if(!AttrVal($name,"snapGalleryBoost",0));
  567. $sgdev = "SSCam.$name.snapgallery";
  568. $ret = CommandDefine($hash->{CL},"$sgdev weblink htmlCode {composegallery('$name','$sgdev')}");
  569. return $ret if($ret);
  570. my $wlname = "SSCam.$name.snapgallery";
  571. my $room = "SnapGallery";
  572. CommandAttr($hash->{CL},$wlname." room ".$room);
  573. return "<html>Snapgallery device \"$sgdev\" was created successfully. Please have a look to room <a href=\"/fhem?room=$room\">$room</a>.<br> You can now assign it to another room if you want. Don't rename this new device ! </html>";
  574. } elsif ($opt eq "enable" && SSCam_IsModelCam($hash)) {
  575. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  576. camenable($hash);
  577. } elsif ($opt eq "disable" && SSCam_IsModelCam($hash)) {
  578. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  579. camdisable($hash);
  580. } elsif ($opt eq "motdetsc" && SSCam_IsModelCam($hash)) {
  581. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  582. if (!$prop || $prop !~ /^(disable|camera|SVS)$/) { return " \"$opt\" needs one of those arguments: disable, camera, SVS !";}
  583. $hash->{HELPER}{MOTDETSC} = $prop;
  584. if ($prop1) {
  585. # check ob Zahl zwischen 1 und 99
  586. return "invalid value for sensitivity (SVS or camera) - use number between 1 - 99" if ($prop1 !~ /^([1-9]|[1-9][0-9])*$/);
  587. $hash->{HELPER}{MOTDETSC_PROP1} = $prop1;
  588. }
  589. if ($prop2) {
  590. # check ob Zahl zwischen 1 und 99
  591. return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop2 !~ /^([1-9]|[1-9][0-9])*$/);
  592. $hash->{HELPER}{MOTDETSC_PROP2} = $prop2;
  593. }
  594. if ($prop3) {
  595. # check ob Zahl zwischen 1 und 99
  596. return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop3 !~ /^([1-9]|[1-9][0-9])*$/);
  597. $hash->{HELPER}{MOTDETSC_PROP3} = $prop3;
  598. }
  599. SSCam_cammotdetsc($hash);
  600. } elsif ($opt eq "credentials") {
  601. return "Credentials are incomplete, use username password" if (!$prop || !$prop1);
  602. return "Password is too long. It is limited up to and including 20 characters." if (length $prop1 > 20);
  603. delete $hash->{HELPER}{SID} if($hash->{HELPER}{SID});
  604. ($success) = SSCam_setcredentials($hash,$prop,$prop1);
  605. $hash->{HELPER}{ACTIVE} = "off";
  606. if($success) {
  607. getcaminfoall($hash,0);
  608. return "Username and Password saved successfully";
  609. } else {
  610. return "Error while saving Username / Password - see logfile for details";
  611. }
  612. } elsif ($opt eq "expmode" && SSCam_IsModelCam($hash)) {
  613. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  614. unless ($prop) { return " \"$opt\" needs one of those arguments: auto, day, night !";}
  615. $hash->{HELPER}{EXPMODE} = $prop;
  616. SSCam_camexpmode($hash);
  617. } elsif ($opt eq "homeMode" && !SSCam_IsModelCam($hash)) {
  618. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  619. unless ($prop) { return " \"$opt\" needs one of those arguments: on, off !";}
  620. $hash->{HELPER}{HOMEMODE} = $prop;
  621. sethomemode($hash);
  622. } elsif ($opt eq "goPreset" && SSCam_IsModelCam($hash)) {
  623. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  624. if (!$prop) {return "Function \"goPreset\" needs a \"Presetname\" as an argument";}
  625. @prop = split(/;/, $prop);
  626. $prop = $prop[0];
  627. @prop = split(/,/, $prop);
  628. $prop = $prop[0];
  629. $hash->{HELPER}{GOPRESETNAME} = $prop;
  630. $hash->{HELPER}{PTZACTION} = "gopreset";
  631. doptzaction($hash);
  632. } elsif ($opt eq "optimizeParams" && SSCam_IsModelCam($hash)) {
  633. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  634. my %cpcl = (ntp => 1, mirror => 2, flip => 4, rotate => 8);
  635. SSCam_extoptpar($hash,$prop,\%cpcl) if($prop);
  636. SSCam_extoptpar($hash,$prop1,\%cpcl) if($prop1);
  637. SSCam_extoptpar($hash,$prop2,\%cpcl) if($prop2);
  638. setoptpar($hash);
  639. } elsif ($opt eq "runPatrol" && SSCam_IsModelCam($hash)) {
  640. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  641. if (!$prop) {return "Function \"runPatrol\" needs a \"Patrolname\" as an argument";}
  642. @prop = split(/;/, $prop);
  643. $prop = $prop[0];
  644. @prop = split(/,/, $prop);
  645. $prop = $prop[0];
  646. $hash->{HELPER}{GOPATROLNAME} = $prop;
  647. $hash->{HELPER}{PTZACTION} = "runpatrol";
  648. doptzaction($hash);
  649. } elsif ($opt eq "goAbsPTZ" && SSCam_IsModelCam($hash)) {
  650. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  651. if ($prop eq "up" || $prop eq "down" || $prop eq "left" || $prop eq "right") {
  652. if ($prop eq "up") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 480;}
  653. if ($prop eq "down") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 0;}
  654. if ($prop eq "left") {$hash->{HELPER}{GOPTZPOSX} = 0; $hash->{HELPER}{GOPTZPOSY} = 240;}
  655. if ($prop eq "right") {$hash->{HELPER}{GOPTZPOSX} = 640; $hash->{HELPER}{GOPTZPOSY} = 240;}
  656. $hash->{HELPER}{PTZACTION} = "goabsptz";
  657. doptzaction($hash);
  658. return undef;
  659. } else {
  660. if ($prop !~ /\d+/ || $prop1 !~ /\d+/ || abs($prop) > 640 || abs($prop1) > 480) {
  661. return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead";
  662. }
  663. $hash->{HELPER}{GOPTZPOSX} = abs($prop);
  664. $hash->{HELPER}{GOPTZPOSY} = abs($prop1);
  665. $hash->{HELPER}{PTZACTION} = "goabsptz";
  666. doptzaction($hash);
  667. return undef;
  668. }
  669. return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead";
  670. } elsif ($opt eq "move" && SSCam_IsModelCam($hash)) {
  671. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  672. return "PTZ version of Synology API isn't set. Use \"get $name scanVirgin\" first." if(!$hash->{HELPER}{APIPTZMAXVER});
  673. if($hash->{HELPER}{APIPTZMAXVER} <= 4) {
  674. if (!defined($prop) || ($prop !~ /^up$|^down$|^left$|^right$|^dir_\d$/)) {return "Function \"move\" needs an argument like up, down, left, right or dir_X (X = 0 to CapPTZDirections-1)";}
  675. $hash->{HELPER}{GOMOVEDIR} = $prop;
  676. } elsif ($hash->{HELPER}{APIPTZMAXVER} >= 5) {
  677. if (!defined($prop) || ($prop !~ /^right$|^upright$|^up$|^upleft$|^left$|^downleft$|^down$|^downright$/)) {return "Function \"move\" needs an argument like right, upright, up, upleft, left, downleft, down, downright ";}
  678. my %dirs = (
  679. right => 0,
  680. upright => 4,
  681. up => 8,
  682. upleft => 12,
  683. left => 16,
  684. downleft => 20,
  685. down => 24,
  686. downright => 28,
  687. );
  688. $hash->{HELPER}{GOMOVEDIR} = $dirs{$prop};
  689. }
  690. $hash->{HELPER}{GOMOVETIME} = defined($prop1) ? $prop1 : 1;
  691. $hash->{HELPER}{PTZACTION} = "movestart";
  692. doptzaction($hash);
  693. } elsif ($opt eq "runView" && SSCam_IsModelCam($hash)) {
  694. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  695. if ($prop eq "live_open") {
  696. if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};}
  697. $hash->{HELPER}{OPENWINDOW} = 1;
  698. $hash->{HELPER}{WLTYPE} = "link";
  699. $hash->{HELPER}{ALIAS} = "LiveView";
  700. $hash->{HELPER}{RUNVIEW} = "live_open";
  701. } elsif ($prop eq "live_link") {
  702. $hash->{HELPER}{OPENWINDOW} = 0;
  703. $hash->{HELPER}{WLTYPE} = "link";
  704. $hash->{HELPER}{ALIAS} = "LiveView";
  705. $hash->{HELPER}{RUNVIEW} = "live_link";
  706. } elsif ($prop eq "lastrec_open") {
  707. if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};}
  708. $hash->{HELPER}{OPENWINDOW} = 1;
  709. $hash->{HELPER}{WLTYPE} = "link";
  710. $hash->{HELPER}{ALIAS} = "LastRecording";
  711. $hash->{HELPER}{RUNVIEW} = "lastrec_open";
  712. } elsif ($prop eq "lastrec_fw") {
  713. $hash->{HELPER}{OPENWINDOW} = 0;
  714. $hash->{HELPER}{WLTYPE} = "iframe";
  715. $hash->{HELPER}{ALIAS} = " ";
  716. $hash->{HELPER}{RUNVIEW} = "lastrec";
  717. } elsif ($prop eq "live_fw") {
  718. $hash->{HELPER}{OPENWINDOW} = 0;
  719. $hash->{HELPER}{WLTYPE} = "image";
  720. $hash->{HELPER}{ALIAS} = " ";
  721. $hash->{HELPER}{RUNVIEW} = "live_fw";
  722. } elsif ($prop eq "lastsnap_fw") {
  723. $hash->{HELPER}{OPENWINDOW} = 0;
  724. $hash->{HELPER}{WLTYPE} = "base64img";
  725. $hash->{HELPER}{ALIAS} = " ";
  726. $hash->{HELPER}{RUNVIEW} = "lastsnap_fw";
  727. } else {
  728. return "$prop isn't a valid option of runview, use one of live_fw, live_link, live_open, lastrec_fw, lastrec_open, lastsnap_fw";
  729. }
  730. SSCam_runliveview($hash);
  731. } elsif ($opt eq "extevent" && !SSCam_IsModelCam($hash)) {
  732. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  733. $hash->{HELPER}{EVENTID} = $prop;
  734. SSCam_extevent($hash);
  735. } elsif ($opt eq "stopView" && SSCam_IsModelCam($hash)) {
  736. SSCam_stopliveview($hash);
  737. } else {
  738. return "$setlist";
  739. }
  740. return;
  741. }
  742. ################################################################
  743. sub SSCam_Get($@) {
  744. my ($hash, @a) = @_;
  745. return "\"get X\" needs at least an argument" if ( @a < 2 );
  746. my $name = shift @a;
  747. my $opt = shift @a;
  748. my $arg = shift @a;
  749. my $arg1 = shift @a;
  750. my $arg2 = shift @a;
  751. my $ret = "";
  752. my $getlist;
  753. if(SSCam_IsModelCam($hash)) {
  754. # selist für Cams
  755. $getlist = "Unknown argument $opt, choose one of ".
  756. "caminfoall:noArg ".
  757. "caminfo:noArg ".
  758. ((AttrVal($name,"snapGalleryNumber",undef) || AttrVal($name,"snapGalleryBoost",0))
  759. ?"snapGallery:noArg ":"snapGallery:$SSCAM_snum ").
  760. "snapinfo:noArg ".
  761. "svsinfo:noArg ".
  762. "snapfileinfo:noArg ".
  763. "eventlist:noArg ".
  764. "stmUrlPath:noArg ".
  765. "storedCredentials:noArg ".
  766. "scanVirgin:noArg "
  767. ;
  768. } else {
  769. # setlist für SVS Devices
  770. $getlist = "Unknown argument $opt, choose one of ".
  771. "caminfoall:noArg ".
  772. ($hash->{HELPER}{APIHMMAXVER}?"homeModeState:noArg ": "").
  773. "svsinfo:noArg ".
  774. "listLog ".
  775. "storedCredentials:noArg ".
  776. "scanVirgin:noArg "
  777. ;
  778. }
  779. return if(IsDisabled($name));
  780. if ($opt eq "caminfo") {
  781. # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine
  782. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  783. getcaminfo($hash);
  784. } elsif ($opt eq "caminfoall") {
  785. # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine
  786. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  787. getcaminfoall($hash,1);
  788. } elsif ($opt eq "homeModeState" && !SSCam_IsModelCam($hash)) {
  789. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  790. gethomemodestate($hash);
  791. } elsif ($opt eq "listLog" && !SSCam_IsModelCam($hash)) {
  792. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  793. # übergebenen CL-Hash (FHEMWEB) in Helper eintragen
  794. SSCam_getclhash($hash,1);
  795. SSCam_extlogargs($hash,$arg) if($arg);
  796. SSCam_extlogargs($hash,$arg1) if($arg1);
  797. SSCam_extlogargs($hash,$arg2) if($arg2);
  798. getsvslog($hash);
  799. } elsif ($opt eq "svsinfo") {
  800. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  801. getsvsinfo($hash);
  802. } elsif ($opt eq "storedCredentials") {
  803. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  804. # Credentials abrufen
  805. my ($success, $username, $password) = SSCam_getcredentials($hash,0);
  806. unless ($success) {return "Credentials couldn't be retrieved successfully - see logfile"};
  807. return "Stored Credentials for $name - Username: $username, Password: $password";
  808. } elsif ($opt eq "snapGallery" && SSCam_IsModelCam($hash)) {
  809. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  810. my $txt = SSCam_getclhash($hash);
  811. return $txt if($txt);
  812. if(!AttrVal($name, "snapGalleryBoost",0)) {
  813. # Snaphash ist nicht vorhanden und wird abgerufen
  814. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  815. # snap-Infos für Gallerie abrufen
  816. my ($sg,$slim,$ssize);
  817. $slim = $arg?AttrVal($name,"snapGalleryNumber",$arg):AttrVal($name,"snapGalleryNumber",$SSCam_slim); # Anzahl der abzurufenden Snapshots
  818. $ssize = (AttrVal($name,"snapGallerySize","Icon") eq "Icon")?1:2; # Image Size 1-Icon, 2-Full
  819. getsnapinfo("$name:$slim:$ssize");
  820. } else {
  821. # Snaphash ist vorhanden und wird zur Ausgabe aufbereitet
  822. my $htmlCode = composegallery($name);
  823. for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) {
  824. if ($hash->{HELPER}{CL}{$k}->{COMP}) {
  825. # CL zusammengestellt (Auslösung durch Notify)
  826. asyncOutput($hash->{HELPER}{CL}{$k}, "$htmlCode");
  827. } else {
  828. # Output wurde über FHEMWEB ausgelöst
  829. return $htmlCode;
  830. }
  831. }
  832. delete($hash->{HELPER}{CL});
  833. }
  834. } elsif ($opt eq "snapinfo" && SSCam_IsModelCam($hash)) {
  835. # Schnappschußgalerie abrufen (snapGalleryBoost) oder nur Info des letzten Snaps
  836. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  837. my ($slim,$ssize) = SSCam_snaplimsize($hash);
  838. getsnapinfo("$name:$slim:$ssize");
  839. } elsif ($opt eq "snapfileinfo" && SSCam_IsModelCam($hash)) {
  840. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  841. if (!ReadingsVal("$name", "LastSnapId", undef)) {return "Reading LastSnapId is empty - please take a snapshot before !"}
  842. getsnapfilename($hash);
  843. } elsif ($opt eq "eventlist" && SSCam_IsModelCam($hash)) {
  844. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  845. SSCam_geteventlist ($hash);
  846. } elsif ($opt eq "stmUrlPath" && SSCam_IsModelCam($hash)) {
  847. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  848. getStmUrlPath ($hash);
  849. } elsif ($opt eq "scanVirgin") {
  850. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  851. sessionoff($hash);
  852. delete $hash->{HELPER}{APIPARSET};
  853. delete $hash->{CAMID};
  854. # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine
  855. getcaminfoall($hash,1);
  856. } else {
  857. return "$getlist";
  858. }
  859. return $ret; # not generate trigger out of command
  860. }
  861. ######################################################################################
  862. # Kamera Liveview Anzeige in FHEMWEB
  863. ######################################################################################
  864. # wird von FW aufgerufen. $FW_wname = aufrufende Webinstanz, $d = aufrufendes
  865. # Device (z.B. CamCP1)
  866. sub SSCam_FWview ($$$$) {
  867. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn in FHEMWEB
  868. my $hash = $defs{$d};
  869. my $name = $hash->{NAME};
  870. my $link = $hash->{HELPER}{LINK};
  871. my $wltype = $hash->{HELPER}{WLTYPE};
  872. my $ret;
  873. my $alias;
  874. return if(!$hash->{HELPER}{LINK} || ReadingsVal("$name", "state", "") =~ /^dis.*/ || IsDisabled($name));
  875. my $attr = AttrVal($d, "htmlattr", " ");
  876. Log3($name, 4, "$name - SSCam_FWview called - FW_wname: $FW_wname, device: $d, room: $room, attributes: $attr");
  877. if($wltype eq "image") {
  878. $ret = "<img src=$link $attr><br>".weblink_FwDetail($d);
  879. } elsif($wltype eq "iframe") {
  880. $ret = "<iframe src=$link $attr>Iframes disabled</iframe>".weblink_FwDetail($d);
  881. } elsif($wltype eq "link") {
  882. $alias = $hash->{HELPER}{ALIAS};
  883. $ret = "<a href=$link $attr>$alias</a><br>";
  884. } elsif($wltype eq "base64img") {
  885. $alias = $hash->{HELPER}{ALIAS};
  886. $ret = "<img $attr alt='$alias' src='data:image/jpeg;base64,$link'><br>";
  887. }
  888. # FW_directNotify("FILTER=room=$room", "#FHEMWEB:$FW_wname", "location.reload('true')", "") if($d eq $name);
  889. return $ret;
  890. }
  891. ######################################################################################
  892. # initiale Startroutinen nach Restart FHEM
  893. ######################################################################################
  894. sub SSCam_initonboot ($) {
  895. my ($hash) = @_;
  896. my $name = $hash->{NAME};
  897. RemoveInternalTimer($hash, "SSCam_initonboot");
  898. if ($init_done == 1) {
  899. RemoveInternalTimer($hash); # alle Timer löschen
  900. delete($defs{$name}{READINGS}{LiveStreamUrl}) if($defs{$name}{READINGS}{LiveStreamUrl}); # LiveStream URL zurücksetzen
  901. # check ob alle Recordings = "Stop" nach Reboot -> sonst stoppen
  902. if (ReadingsVal($hash->{NAME}, "Record", "Stop") eq "Start") {
  903. Log3($name, 2, "$name - Recording of $hash->{CAMNAME} seems to be still active after FHEM restart - try to stop it now");
  904. SSCam_camstoprec($hash);
  905. }
  906. # Konfiguration der Synology Surveillance Station abrufen
  907. if (!$hash->{CREDENTIALS}) {
  908. Log3($name, 2, "$name - Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"");
  909. } else {
  910. # allg. SVS-Eigenschaften abrufen
  911. getsvsinfo($hash);
  912. if(SSCam_IsModelCam($hash)) {
  913. # Kameraspezifische Infos holen
  914. getcaminfo($hash);
  915. SSCam_getcapabilities($hash);
  916. # Preset/Patrollisten in Hash einlesen zur PTZ-Steuerung
  917. SSCam_getptzlistpreset($hash);
  918. SSCam_getptzlistpatrol($hash);
  919. # Schnappschußgalerie abrufen (snapGalleryBoost) oder nur Info des letzten Snaps
  920. my ($slim,$ssize) = SSCam_snaplimsize($hash);
  921. RemoveInternalTimer("getsnapinfo");
  922. InternalTimer(gettimeofday()+0.9, "getsnapinfo", "$name:$slim:$ssize", 0);
  923. }
  924. }
  925. # Subroutine Watchdog-Timer starten (sollen Cam-Infos regelmäßig abgerufen werden ?), verzögerter zufälliger Start 0-30s
  926. RemoveInternalTimer($hash, "SSCam_wdpollcaminfo");
  927. InternalTimer(gettimeofday()+int(rand(30)), "SSCam_wdpollcaminfo", $hash, 0);
  928. } else {
  929. InternalTimer(gettimeofday()+1, "SSCam_initonboot", $hash, 0);
  930. }
  931. return;
  932. }
  933. ######################################################################################
  934. # Username / Paßwort speichern
  935. ######################################################################################
  936. sub SSCam_setcredentials ($@) {
  937. my ($hash, @credentials) = @_;
  938. my $name = $hash->{NAME};
  939. my $success;
  940. my $credstr;
  941. my $index;
  942. my $retcode;
  943. my (@key,$len,$i);
  944. $credstr = encode_base64(join(':', @credentials));
  945. # Beginn Scramble-Routine
  946. @key = qw(1 3 4 5 6 3 2 1 9);
  947. $len = scalar @key;
  948. $i = 0;
  949. $credstr = join "",
  950. map { $i = ($i + 1) % $len;
  951. chr((ord($_) + $key[$i]) % 256) } split //, $credstr;
  952. # End Scramble-Routine
  953. $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  954. $retcode = setKeyValue($index, $credstr);
  955. if ($retcode) {
  956. Log3($name, 2, "$name - Error while saving the Credentials - $retcode");
  957. $success = 0;
  958. } else {
  959. SSCam_getcredentials($hash,1); # Credentials nach Speicherung lesen und in RAM laden ($boot=1)
  960. $success = 1;
  961. }
  962. return ($success);
  963. }
  964. ######################################################################################
  965. # Username / Paßwort abrufen
  966. ######################################################################################
  967. sub SSCam_getcredentials ($$) {
  968. my ($hash,$boot) = @_;
  969. my $name = $hash->{NAME};
  970. my $success;
  971. my $username;
  972. my $passwd;
  973. my $index;
  974. my ($retcode, $credstr);
  975. my (@key,$len,$i);
  976. if ($boot eq 1) {
  977. # mit $boot=1 Credentials von Platte lesen und als scrambled-String in RAM legen
  978. $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  979. ($retcode, $credstr) = getKeyValue($index);
  980. if ($retcode) {
  981. Log3($name, 2, "$name - Unable to read password from file: $retcode");
  982. $success = 0;
  983. }
  984. if ($credstr) {
  985. # beim Boot scrambled Credentials in den RAM laden
  986. $hash->{HELPER}{CREDENTIALS} = $credstr;
  987. # "Credentials" wird als Statusbit ausgewertet. Wenn nicht gesetzt -> Warnmeldung und keine weitere Verarbeitung
  988. $hash->{CREDENTIALS} = "Set";
  989. $success = 1;
  990. }
  991. } else {
  992. # boot = 0 -> Credentials aus RAM lesen, decoden und zurückgeben
  993. $credstr = $hash->{HELPER}{CREDENTIALS};
  994. # Beginn Descramble-Routine
  995. @key = qw(1 3 4 5 6 3 2 1 9);
  996. $len = scalar @key;
  997. $i = 0;
  998. $credstr = join "",
  999. map { $i = ($i + 1) % $len;
  1000. chr((ord($_) - $key[$i] + 256) % 256) }
  1001. split //, $credstr;
  1002. # Ende Descramble-Routine
  1003. ($username, $passwd) = split(":",decode_base64($credstr));
  1004. my $logpw = AttrVal($name, "showPassInLog", "0") == 1 ? $passwd : "********";
  1005. Log3($name, 4, "$name - Credentials read from RAM: $username $logpw");
  1006. $success = (defined($passwd)) ? 1 : 0;
  1007. }
  1008. return ($success, $username, $passwd);
  1009. }
  1010. ######################################################################################
  1011. # Polling Überwachung
  1012. ######################################################################################
  1013. sub SSCam_wdpollcaminfo ($) {
  1014. # Überwacht die Wert von Attribut "pollcaminfoall" und Reading "PollState"
  1015. # wenn Attribut "pollcaminfoall" > 10 und "PollState"=Inactive -> start Polling
  1016. my ($hash) = @_;
  1017. my $name = $hash->{NAME};
  1018. my $camname = $hash->{CAMNAME};
  1019. my $watchdogtimer = 90;
  1020. if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10 and ReadingsVal("$name", "PollState", "Active") eq "Inactive" and !IsDisabled($name)) {
  1021. readingsSingleUpdate($hash,"PollState","Active",1); # Polling ist jetzt aktiv
  1022. readingsSingleUpdate($hash,"state","polling",1) if(!SSCam_IsModelCam($hash)); # Polling-state bei einem SVS-Device setzten
  1023. Log3($name, 3, "$name - Polling of $camname is activated - Pollinginterval: ".$attr{$name}{pollcaminfoall}."s");
  1024. $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall}; # in $hash eintragen für späteren Vergleich (Changes von pollcaminfoall)
  1025. getcaminfoall($hash,0);
  1026. }
  1027. if (defined($hash->{HELPER}{OLDVALPOLL}) and defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) {
  1028. if ($hash->{HELPER}{OLDVALPOLL} != $attr{$name}{pollcaminfoall}) {
  1029. Log3($name, 3, "$name - Polling of $camname was changed to new Pollinginterval: ".$attr{$name}{pollcaminfoall}."s");
  1030. $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall};
  1031. }
  1032. }
  1033. if (defined($attr{$name}{pollnologging})) {
  1034. if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} ne $attr{$name}{pollnologging}) {
  1035. if ($attr{$name}{pollnologging} == "1") {
  1036. Log3($name, 3, "$name - Polling-Log of $camname is deactivated");
  1037. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging}; # in $hash eintragen für späteren Vergleich (Changes von pollnologging)
  1038. } else {
  1039. Log3($name, 3, "$name - Polling-Log of $camname is activated");
  1040. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging}; # in $hash eintragen für späteren Vergleich (Changes von pollnologging)
  1041. }
  1042. }
  1043. } else {
  1044. # alter Wert von "pollnologging" war 1 -> Logging war deaktiviert
  1045. if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} == "1") {
  1046. Log3($name, 3, "$name - Polling-Log of $camname is activated");
  1047. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0";
  1048. }
  1049. }
  1050. RemoveInternalTimer($hash, "SSCam_wdpollcaminfo");
  1051. InternalTimer(gettimeofday()+$watchdogtimer, "SSCam_wdpollcaminfo", $hash, 0);
  1052. return undef;
  1053. }
  1054. ############################################################################################################
  1055. # OpMode-Startroutinen #
  1056. # $hash->{HELPER}{ACTIVE} = Funktionstoken #
  1057. # $hash->{HELPER}{ACTIVE} = "on" -> eine Routine läuft, Start anderer Routine erst wenn "off". #
  1058. # $hash->{HELPER}{ACTIVE} = "off" -> keine andere Routine läuft, sofortiger Start möglich #
  1059. ############################################################################################################
  1060. ###############################################################################
  1061. # Kamera Aufnahme starten
  1062. ###############################################################################
  1063. sub SSCam_camstartrec ($) {
  1064. my ($hash) = @_;
  1065. my $camname = $hash->{CAMNAME};
  1066. my $name = $hash->{NAME};
  1067. my $errorcode;
  1068. my $error;
  1069. RemoveInternalTimer($hash, "SSCam_camstartrec");
  1070. return if(IsDisabled($name));
  1071. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1072. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1073. $errorcode = "402";
  1074. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1075. $errorcode = "502";
  1076. }
  1077. # Fehlertext zum Errorcode ermitteln
  1078. $error = SSCam_experror($hash,$errorcode);
  1079. # Setreading
  1080. readingsBeginUpdate($hash);
  1081. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1082. readingsBulkUpdate($hash,"Error",$error);
  1083. readingsEndUpdate($hash, 1);
  1084. Log3($name, 2, "$name - ERROR - Start Recording of Camera $camname can't be executed - $error");
  1085. return;
  1086. }
  1087. if (ReadingsVal("$name", "Record", undef) eq "Start" and !AttrVal($name, "recextend", undef)) {
  1088. Log3($name, 3, "$name - another recording is already running - new start-command will be ignored");
  1089. return;
  1090. }
  1091. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1092. # Aufnahme starten
  1093. $hash->{OPMODE} = "Start";
  1094. $hash->{HELPER}{ACTIVE} = "on";
  1095. $hash->{HELPER}{LOGINRETRIES} = 0;
  1096. if ($attr{$name}{debugactivetoken}) {
  1097. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1098. }
  1099. SSCam_getapisites($hash);
  1100. } else {
  1101. InternalTimer(gettimeofday()+0.3, "SSCam_camstartrec", $hash);
  1102. }
  1103. }
  1104. ###############################################################################
  1105. # Kamera Aufnahme stoppen
  1106. ###############################################################################
  1107. sub SSCam_camstoprec ($) {
  1108. my ($hash) = @_;
  1109. my $camname = $hash->{CAMNAME};
  1110. my $name = $hash->{NAME};
  1111. my $errorcode;
  1112. my $error;
  1113. RemoveInternalTimer($hash, "SSCam_camstoprec");
  1114. return if(IsDisabled($name));
  1115. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1116. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1117. $errorcode = "402";
  1118. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1119. $errorcode = "502";
  1120. }
  1121. # Fehlertext zum Errorcode ermitteln
  1122. $error = SSCam_experror($hash,$errorcode);
  1123. # Setreading
  1124. readingsBeginUpdate($hash);
  1125. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1126. readingsBulkUpdate($hash,"Error",$error);
  1127. readingsEndUpdate($hash, 1);
  1128. Log3($name, 2, "$name - ERROR - Stop Recording of Camera $camname can't be executed - $error");
  1129. return;
  1130. }
  1131. if (ReadingsVal("$name", "Record", undef) eq "Stop") {
  1132. Log3($name, 3, "$name - recording is already stopped - new stop-command will be ignored");
  1133. return;
  1134. }
  1135. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1136. $hash->{OPMODE} = "Stop";
  1137. $hash->{HELPER}{ACTIVE} = "on";
  1138. $hash->{HELPER}{LOGINRETRIES} = 0;
  1139. if ($attr{$name}{debugactivetoken}) {
  1140. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1141. }
  1142. SSCam_getapisites($hash);
  1143. } else {
  1144. InternalTimer(gettimeofday()+0.3, "SSCam_camstoprec", $hash, 0);
  1145. }
  1146. }
  1147. ###############################################################################
  1148. # Kamera Auto / Day / Nightmode setzen
  1149. ###############################################################################
  1150. sub SSCam_camexpmode($) {
  1151. my ($hash) = @_;
  1152. my $camname = $hash->{CAMNAME};
  1153. my $name = $hash->{NAME};
  1154. my $errorcode;
  1155. my $error;
  1156. RemoveInternalTimer($hash, "SSCam_camexpmode");
  1157. return if(IsDisabled($name));
  1158. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1159. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1160. $errorcode = "402";
  1161. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1162. $errorcode = "502";
  1163. }
  1164. # Fehlertext zum Errorcode ermitteln
  1165. $error = SSCam_experror($hash,$errorcode);
  1166. # Setreading
  1167. readingsBeginUpdate($hash);
  1168. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1169. readingsBulkUpdate($hash,"Error",$error);
  1170. readingsEndUpdate($hash, 1);
  1171. Log3($name, 2, "$name - ERROR - Setting exposure mode of Camera $camname can't be executed - $error");
  1172. return;
  1173. }
  1174. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1175. $hash->{OPMODE} = "ExpMode";
  1176. $hash->{HELPER}{ACTIVE} = "on";
  1177. $hash->{HELPER}{LOGINRETRIES} = 0;
  1178. if ($attr{$name}{debugactivetoken}) {
  1179. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1180. }
  1181. SSCam_getapisites($hash);
  1182. } else {
  1183. InternalTimer(gettimeofday()+0.5, "SSCam_camexpmode", $hash, 0);
  1184. }
  1185. }
  1186. ###############################################################################
  1187. # Art der Bewegungserkennung setzen
  1188. ###############################################################################
  1189. sub SSCam_cammotdetsc($) {
  1190. my ($hash) = @_;
  1191. my $camname = $hash->{CAMNAME};
  1192. my $name = $hash->{NAME};
  1193. my $errorcode;
  1194. my $error;
  1195. RemoveInternalTimer($hash, "SSCam_cammotdetsc");
  1196. return if(IsDisabled($name));
  1197. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1198. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1199. $errorcode = "402";
  1200. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1201. $errorcode = "502";
  1202. }
  1203. # Fehlertext zum Errorcode ermitteln
  1204. $error = SSCam_experror($hash,$errorcode);
  1205. # Setreading
  1206. readingsBeginUpdate($hash);
  1207. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1208. readingsBulkUpdate($hash,"Error",$error);
  1209. readingsEndUpdate($hash, 1);
  1210. Log3($name, 2, "$name - ERROR - Setting of motion detection source of Camera $camname can't be executed - $error");
  1211. return;
  1212. }
  1213. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1214. $hash->{OPMODE} = "MotDetSc";
  1215. $hash->{HELPER}{ACTIVE} = "on";
  1216. $hash->{HELPER}{LOGINRETRIES} = 0;
  1217. if ($attr{$name}{debugactivetoken}) {
  1218. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1219. }
  1220. SSCam_getapisites($hash);
  1221. } else {
  1222. InternalTimer(gettimeofday()+0.5, "SSCam_cammotdetsc", $hash, 0);
  1223. }
  1224. }
  1225. ###############################################################################
  1226. # Kamera Schappschuß aufnehmen
  1227. ###############################################################################
  1228. sub SSCam_camsnap($) {
  1229. my ($hash) = @_;
  1230. my $camname = $hash->{CAMNAME};
  1231. my $name = $hash->{NAME};
  1232. my $errorcode;
  1233. my $error;
  1234. RemoveInternalTimer($hash, "SSCam_camsnap");
  1235. return if(IsDisabled($name));
  1236. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1237. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1238. $errorcode = "402";
  1239. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1240. $errorcode = "502";
  1241. }
  1242. # Fehlertext zum Errorcode ermitteln
  1243. $error = SSCam_experror($hash,$errorcode);
  1244. # Setreading
  1245. readingsBeginUpdate($hash);
  1246. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1247. readingsBulkUpdate($hash,"Error",$error);
  1248. readingsEndUpdate($hash, 1);
  1249. Log3($name, 2, "$name - ERROR - Snapshot of Camera $camname can't be executed - $error");
  1250. return;
  1251. }
  1252. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1253. # einen Schnappschuß aufnehmen
  1254. $hash->{OPMODE} = "Snap";
  1255. $hash->{HELPER}{ACTIVE} = "on";
  1256. $hash->{HELPER}{LOGINRETRIES} = 0;
  1257. if ($attr{$name}{debugactivetoken}) {
  1258. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1259. }
  1260. SSCam_getapisites($hash);
  1261. } else {
  1262. InternalTimer(gettimeofday()+0.3, "SSCam_camsnap", $hash, 0);
  1263. }
  1264. }
  1265. ###############################################################################
  1266. # Kamera Liveview starten
  1267. ###############################################################################
  1268. sub SSCam_runliveview($) {
  1269. my ($hash) = @_;
  1270. my $camname = $hash->{CAMNAME};
  1271. my $name = $hash->{NAME};
  1272. my $errorcode;
  1273. my $error;
  1274. RemoveInternalTimer($hash, "SSCam_runliveview");
  1275. return if(IsDisabled($name));
  1276. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1277. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1278. $errorcode = "402";
  1279. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1280. $errorcode = "502";
  1281. }
  1282. # Fehlertext zum Errorcode ermitteln
  1283. $error = &SSCam_experror($hash,$errorcode);
  1284. # Setreading
  1285. readingsBeginUpdate($hash);
  1286. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1287. readingsBulkUpdate($hash,"Error",$error);
  1288. readingsEndUpdate($hash, 1);
  1289. Log3($name, 2, "$name - ERROR - Liveview of Camera $camname can't be started - $error");
  1290. return;
  1291. }
  1292. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1293. # Liveview starten
  1294. $hash->{OPMODE} = "runliveview";
  1295. $hash->{HELPER}{ACTIVE} = "on";
  1296. $hash->{HELPER}{LOGINRETRIES} = 0;
  1297. # erzwingen die Camid zu ermitteln und bei login-Fehler neue SID zu holen
  1298. delete $hash->{CAMID};
  1299. if ($attr{$name}{debugactivetoken}) {
  1300. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1301. }
  1302. readingsSingleUpdate($hash,"state","startview",1);
  1303. SSCam_getapisites($hash);
  1304. } else {
  1305. InternalTimer(gettimeofday()+0.5, "SSCam_runliveview", $hash, 0);
  1306. }
  1307. }
  1308. ###############################################################################
  1309. # Kamera Liveview stoppen
  1310. ###############################################################################
  1311. sub SSCam_stopliveview ($) {
  1312. my ($hash) = @_;
  1313. my $camname = $hash->{CAMNAME};
  1314. my $name = $hash->{NAME};
  1315. my $errorcode;
  1316. my $error;
  1317. RemoveInternalTimer($hash, "SSCam_stopliveview");
  1318. return if(IsDisabled($name));
  1319. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1320. # Liveview stoppen
  1321. $hash->{OPMODE} = "stopliveview";
  1322. $hash->{HELPER}{ACTIVE} = "on";
  1323. $hash->{HELPER}{LOGINRETRIES} = 0;
  1324. if ($attr{$name}{debugactivetoken}) {
  1325. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1326. }
  1327. # Link aus Helper-hash löschen
  1328. delete $hash->{HELPER}{LINK};
  1329. # Reading LiveStreamUrl löschen
  1330. delete($defs{$name}{READINGS}{LiveStreamUrl}) if ($defs{$name}{READINGS}{LiveStreamUrl});
  1331. # Longpoll refresh
  1332. readingsSingleUpdate($hash,"state","stopview",1);
  1333. # Aufnahmestatus im state abbilden
  1334. my $st;
  1335. (ReadingsVal("$name", "Record", "") eq "Start")?$st="on":$st="off";
  1336. readingsSingleUpdate($hash,"state", $st, 1);
  1337. $hash->{HELPER}{ACTIVE} = "off";
  1338. if ($attr{$name}{debugactivetoken}) {
  1339. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1340. }
  1341. } else {
  1342. InternalTimer(gettimeofday()+0.5, "SSCam_stopliveview", $hash, 0);
  1343. }
  1344. }
  1345. ###############################################################################
  1346. # external Event 1-10 auslösen
  1347. ###############################################################################
  1348. sub SSCam_extevent ($) {
  1349. my ($hash) = @_;
  1350. my $name = $hash->{NAME};
  1351. RemoveInternalTimer($hash, "SSCam_extevent");
  1352. return if(IsDisabled($name));
  1353. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1354. $hash->{OPMODE} = "extevent";
  1355. $hash->{HELPER}{ACTIVE} = "on";
  1356. $hash->{HELPER}{LOGINRETRIES} = 0;
  1357. if ($attr{$name}{debugactivetoken}) {
  1358. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1359. }
  1360. SSCam_getapisites($hash);
  1361. } else {
  1362. InternalTimer(gettimeofday()+0.5, "SSCam_extevent", $hash, 0);
  1363. }
  1364. }
  1365. ###############################################################################
  1366. # PTZ-Kamera auf Position fahren
  1367. ###############################################################################
  1368. sub doptzaction ($) {
  1369. my ($hash) = @_;
  1370. my $camname = $hash->{CAMNAME};
  1371. my $name = $hash->{NAME};
  1372. my $errorcode;
  1373. my $error;
  1374. RemoveInternalTimer($hash, "doptzaction");
  1375. return if(IsDisabled($name));
  1376. if (ReadingsVal("$name", "DeviceType", "Camera") ne "PTZ") {
  1377. Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible for cameras of DeviceType \"PTZ\" - please compare with device Readings");
  1378. return;
  1379. }
  1380. if ($hash->{HELPER}{PTZACTION} eq "goabsptz" && !ReadingsVal("$name", "CapPTZAbs", "false")) {
  1381. Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports absolute PTZ action - please compare with device Reading \"CapPTZAbs\"");
  1382. return;
  1383. }
  1384. if ( $hash->{HELPER}{PTZACTION} eq "movestart" && ReadingsVal("$name", "CapPTZDirections", "0") < 1) {
  1385. Log3($name, 2, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports \"Tilt\" and \"Pan\" operations - please compare with device Reading \"CapPTZDirections\"");
  1386. return;
  1387. }
  1388. if ($hash->{HELPER}{PTZACTION} eq "gopreset") {
  1389. if (!defined($hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}})) {
  1390. $errorcode = "600";
  1391. # Fehlertext zum Errorcode ermitteln
  1392. $error = SSCam_experror($hash,$errorcode);
  1393. # Setreading
  1394. readingsBeginUpdate($hash);
  1395. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1396. readingsBulkUpdate($hash,"Error",$error);
  1397. readingsEndUpdate($hash, 1);
  1398. Log3($name, 2, "$name - ERROR - goPreset to position \"$hash->{HELPER}{GOPRESETNAME}\" of Camera $camname can't be executed - $error");
  1399. return;
  1400. }
  1401. }
  1402. if ($hash->{HELPER}{PTZACTION} eq "runpatrol") {
  1403. if (!defined($hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}})) {
  1404. $errorcode = "600";
  1405. # Fehlertext zum Errorcode ermitteln
  1406. $error = SSCam_experror($hash,$errorcode);
  1407. # Setreading
  1408. readingsBeginUpdate($hash);
  1409. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1410. readingsBulkUpdate($hash,"Error",$error);
  1411. readingsEndUpdate($hash, 1);
  1412. Log3($name, 2, "$name - ERROR - runPatrol to patrol \"$hash->{HELPER}{GOPATROLNAME}\" of Camera $camname can't be executed - $error");
  1413. return;
  1414. }
  1415. }
  1416. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1417. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1418. $errorcode = "402";
  1419. } elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1420. $errorcode = "502";
  1421. }
  1422. # Fehlertext zum Errorcode ermitteln
  1423. $error = SSCam_experror($hash,$errorcode);
  1424. # Setreading
  1425. readingsBeginUpdate($hash);
  1426. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1427. readingsBulkUpdate($hash,"Error",$error);
  1428. readingsEndUpdate($hash, 1);
  1429. Log3($name, 2, "$name - ERROR - $hash->{HELPER}{PTZACTION} of Camera $camname can't be executed - $error");
  1430. return;
  1431. }
  1432. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1433. if ($hash->{HELPER}{PTZACTION} eq "gopreset") {
  1434. Log3($name, 4, "$name - Move Camera $camname to position \"$hash->{HELPER}{GOPRESETNAME}\" with ID \"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\" now");
  1435. } elsif ($hash->{HELPER}{PTZACTION} eq "runpatrol") {
  1436. Log3($name, 4, "$name - Start patrol \"$hash->{HELPER}{GOPATROLNAME}\" with ID \"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\" of Camera $camname now");
  1437. } elsif ($hash->{HELPER}{PTZACTION} eq "goabsptz") {
  1438. Log3($name, 4, "$name - Start move Camera $camname to position posX=\"$hash->{HELPER}{GOPTZPOSX}\" and posY=\"$hash->{HELPER}{GOPTZPOSY}\" now");
  1439. } elsif ($hash->{HELPER}{PTZACTION} eq "movestart") {
  1440. Log3($name, 4, "$name - Start move Camera $camname to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s");
  1441. }
  1442. if ($attr{$name}{debugactivetoken}) {
  1443. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1444. }
  1445. $hash->{OPMODE} = $hash->{HELPER}{PTZACTION};
  1446. $hash->{HELPER}{ACTIVE} = "on";
  1447. $hash->{HELPER}{LOGINRETRIES} = 0;
  1448. SSCam_getapisites($hash);
  1449. } else {
  1450. InternalTimer(gettimeofday()+0.5, "doptzaction", $hash, 0);
  1451. }
  1452. }
  1453. ###############################################################################
  1454. # stoppen continoues move
  1455. ###############################################################################
  1456. sub movestop ($) {
  1457. my ($hash) = @_;
  1458. my $camname = $hash->{CAMNAME};
  1459. my $name = $hash->{NAME};
  1460. RemoveInternalTimer($hash, "movestop");
  1461. return if(IsDisabled($name));
  1462. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1463. $hash->{OPMODE} = "movestop";
  1464. $hash->{HELPER}{ACTIVE} = "on";
  1465. $hash->{HELPER}{LOGINRETRIES} = 0;
  1466. if ($attr{$name}{debugactivetoken}) {
  1467. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");;
  1468. }
  1469. SSCam_getapisites($hash);
  1470. } else {
  1471. InternalTimer(gettimeofday()+0.3, "movestop", $hash, 0);
  1472. }
  1473. }
  1474. ###############################################################################
  1475. # Kamera aktivieren
  1476. ###############################################################################
  1477. sub camenable ($) {
  1478. my ($hash) = @_;
  1479. my $camname = $hash->{CAMNAME};
  1480. my $name = $hash->{NAME};
  1481. RemoveInternalTimer($hash, "camenable");
  1482. return if(IsDisabled($name));
  1483. # if (ReadingsVal("$name", "Availability", "disabled") eq "enabled") {return;} # Kamera ist bereits enabled
  1484. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1485. # eine Kamera aktivieren
  1486. Log3($name, 4, "$name - Enable Camera $camname");
  1487. $hash->{OPMODE} = "Enable";
  1488. $hash->{HELPER}{ACTIVE} = "on";
  1489. $hash->{HELPER}{LOGINRETRIES} = 0;
  1490. if ($attr{$name}{debugactivetoken}) {
  1491. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1492. }
  1493. SSCam_getapisites($hash);
  1494. } else {
  1495. InternalTimer(gettimeofday()+0.5, "camenable", $hash, 0);
  1496. }
  1497. }
  1498. ###############################################################################
  1499. # Kamera deaktivieren
  1500. ###############################################################################
  1501. sub camdisable ($) {
  1502. my ($hash) = @_;
  1503. my $camname = $hash->{CAMNAME};
  1504. my $name = $hash->{NAME};
  1505. RemoveInternalTimer($hash, "camdisable");
  1506. return if(IsDisabled($name));
  1507. # if (ReadingsVal("$name", "Availability", "enabled") eq "disabled") {return;} # Kamera ist bereits disabled
  1508. if ($hash->{HELPER}{ACTIVE} eq "off" and ReadingsVal("$name", "Record", "Start") ne "Start") {
  1509. # eine Kamera deaktivieren
  1510. Log3($name, 4, "$name - Disable Camera $camname");
  1511. $hash->{OPMODE} = "Disable";
  1512. $hash->{HELPER}{ACTIVE} = "on";
  1513. $hash->{HELPER}{LOGINRETRIES} = 0;
  1514. if ($attr{$name}{debugactivetoken}) {
  1515. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1516. }
  1517. SSCam_getapisites($hash);
  1518. } else {
  1519. InternalTimer(gettimeofday()+0.5, "camdisable", $hash, 0);
  1520. }
  1521. }
  1522. ###############################################################################
  1523. # Kamera alle Informationen abrufen (Get) bzw. Einstieg Polling
  1524. ###############################################################################
  1525. sub getcaminfoall ($$) {
  1526. my ($hash,$mode) = @_;
  1527. my $camname = $hash->{CAMNAME};
  1528. my $name = $hash->{NAME};
  1529. my ($now,$new);
  1530. RemoveInternalTimer($hash, "getcaminfoall");
  1531. return if(IsDisabled($name));
  1532. RemoveInternalTimer($hash, "getsvsinfo");
  1533. InternalTimer(gettimeofday()+1, "getsvsinfo", $hash, 0);
  1534. if(SSCam_IsModelCam($hash)) {
  1535. # Model ist CAM
  1536. RemoveInternalTimer($hash, "SSCam_geteventlist");
  1537. InternalTimer(gettimeofday()+0.5, "SSCam_geteventlist", $hash, 0);
  1538. RemoveInternalTimer($hash, "getcaminfo");
  1539. InternalTimer(gettimeofday()+0.9, "getcaminfo", $hash, 0);
  1540. # Schnappschußgalerie abrufen (snapGalleryBoost) oder nur Info des letzten Snaps
  1541. my ($slim,$ssize) = SSCam_snaplimsize($hash);
  1542. RemoveInternalTimer("getsnapinfo");
  1543. InternalTimer(gettimeofday()+1.5, "getsnapinfo", "$name:$slim:$ssize", 0);
  1544. RemoveInternalTimer($hash, "SSCam_getmotionenum");
  1545. InternalTimer(gettimeofday()+0.6, "SSCam_getmotionenum", $hash, 0);
  1546. RemoveInternalTimer($hash, "SSCam_getcapabilities");
  1547. InternalTimer(gettimeofday()+1.3, "SSCam_getcapabilities", $hash, 0);
  1548. RemoveInternalTimer($hash, "SSCam_getptzlistpreset");
  1549. InternalTimer(gettimeofday()+1.6, "SSCam_getptzlistpreset", $hash, 0);
  1550. RemoveInternalTimer($hash, "SSCam_getptzlistpatrol");
  1551. InternalTimer(gettimeofday()+1.9, "SSCam_getptzlistpatrol", $hash, 0);
  1552. RemoveInternalTimer($hash, "getStmUrlPath");
  1553. InternalTimer(gettimeofday()+2.1, "getStmUrlPath", $hash, 0);
  1554. } else {
  1555. # Model ist SVS
  1556. RemoveInternalTimer($hash, "gethomemodestate");
  1557. InternalTimer(gettimeofday()+0.7, "gethomemodestate", $hash, 0);
  1558. RemoveInternalTimer($hash, "getsvslog");
  1559. InternalTimer(gettimeofday()+0.8, "getsvslog", $hash, 0);
  1560. }
  1561. # wenn gesetzt = manuelle Abfrage
  1562. return if ($mode);
  1563. if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) {
  1564. # Pollen wenn pollcaminfo > 10, sonst kein Polling
  1565. $new = gettimeofday()+$attr{$name}{pollcaminfoall};
  1566. InternalTimer($new, "getcaminfoall", $hash, 0);
  1567. $now = FmtTime(gettimeofday());
  1568. $new = FmtTime(gettimeofday()+$attr{$name}{pollcaminfoall});
  1569. readingsSingleUpdate($hash,"state","polling",1) if(!SSCam_IsModelCam($hash)); # state für SVS-Device setzen
  1570. readingsSingleUpdate($hash,"PollState","Active - next time: $new",1);
  1571. if (!$attr{$name}{pollnologging}) {
  1572. Log3($name, 3, "$name - Polling now: $now , next Polling: $new");
  1573. }
  1574. } else {
  1575. # Beenden Polling aller Caminfos
  1576. readingsSingleUpdate($hash,"PollState","Inactive",1);
  1577. readingsSingleUpdate($hash,"state","initialized",1) if(!SSCam_IsModelCam($hash)); # state für SVS-Device setzen
  1578. Log3($name, 3, "$name - Polling of $camname is deactivated");
  1579. }
  1580. return;
  1581. }
  1582. ###########################################################################
  1583. # Infos zu Snaps abfragen (z.B. weil nicht über SSCam ausgelöst)
  1584. ###########################################################################
  1585. sub getsnapinfo ($) {
  1586. my ($str) = @_;
  1587. my ($name,$slim,$ssize) = split(":",$str);
  1588. my $hash = $defs{$name};
  1589. my $camname = $hash->{CAMNAME};
  1590. RemoveInternalTimer("getsnapinfo");
  1591. return if(IsDisabled($name));
  1592. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1593. $hash->{OPMODE} = "getsnapinfo";
  1594. $hash->{OPMODE} = "getsnapgallery" if(exists($hash->{HELPER}{GETSNAPGALLERY}));
  1595. $hash->{HELPER}{ACTIVE} = "on";
  1596. $hash->{HELPER}{LOGINRETRIES} = 0;
  1597. $hash->{HELPER}{SNAPLIMIT} = $slim; # 0-alle Snapshots werden abgerufen und ausgewertet, sonst $slim
  1598. $hash->{HELPER}{SNAPIMGSIZE} = $ssize; # 0-Do not append image, 1-Icon size, 2-Full size
  1599. $hash->{HELPER}{KEYWORD} = $camname;
  1600. if ($attr{$name}{debugactivetoken}) {
  1601. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1602. }
  1603. SSCam_getapisites($hash);
  1604. } else {
  1605. InternalTimer(gettimeofday()+1.7, "getsnapinfo", "$name:$slim:$ssize", 0);
  1606. }
  1607. }
  1608. ###############################################################################
  1609. # Filename zu Schappschuß ermitteln
  1610. ###############################################################################
  1611. sub getsnapfilename ($) {
  1612. my ($hash) = @_;
  1613. my $name = $hash->{NAME};
  1614. RemoveInternalTimer($hash, "getsnapfilename");
  1615. return if(IsDisabled($name));
  1616. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1617. $hash->{OPMODE} = "getsnapfilename";
  1618. $hash->{HELPER}{ACTIVE} = "on";
  1619. $hash->{HELPER}{LOGINRETRIES} = 0;
  1620. if ($attr{$name}{debugactivetoken}) {
  1621. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1622. }
  1623. SSCam_getapisites($hash);
  1624. } else {
  1625. InternalTimer(gettimeofday()+0.5, "getsnapfilename", $hash, 0);
  1626. }
  1627. }
  1628. ###########################################################################
  1629. # allgemeine Infos über Synology Surveillance Station
  1630. ###########################################################################
  1631. sub getsvsinfo ($) {
  1632. my ($hash) = @_;
  1633. my $camname = $hash->{CAMNAME};
  1634. my $name = $hash->{NAME};
  1635. RemoveInternalTimer($hash, "getsvsinfo");
  1636. return if(IsDisabled($name));
  1637. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1638. $hash->{OPMODE} = "getsvsinfo";
  1639. $hash->{HELPER}{ACTIVE} = "on";
  1640. $hash->{HELPER}{LOGINRETRIES} = 0;
  1641. if ($attr{$name}{debugactivetoken}) {
  1642. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1643. }
  1644. SSCam_getapisites($hash);
  1645. } else {
  1646. InternalTimer(gettimeofday()+1, "getsvsinfo", $hash, 0);
  1647. }
  1648. }
  1649. ###########################################################################
  1650. # HomeMode setzen
  1651. ###########################################################################
  1652. sub sethomemode ($) {
  1653. my ($hash) = @_;
  1654. my $camname = $hash->{CAMNAME};
  1655. my $name = $hash->{NAME};
  1656. RemoveInternalTimer($hash, "sethomemode");
  1657. return if(IsDisabled($name) || !defined($hash->{HELPER}{APIHMMAXVER}));
  1658. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1659. $hash->{OPMODE} = "sethomemode";
  1660. $hash->{HELPER}{ACTIVE} = "on";
  1661. $hash->{HELPER}{LOGINRETRIES} = 0;
  1662. if ($attr{$name}{debugactivetoken}) {
  1663. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1664. }
  1665. SSCam_getapisites($hash);
  1666. } else {
  1667. InternalTimer(gettimeofday()+0.6, "sethomemode", $hash, 0);
  1668. }
  1669. }
  1670. ###########################################################################
  1671. # Optimierparameter setzen
  1672. ###########################################################################
  1673. sub setoptpar ($) {
  1674. my ($hash) = @_;
  1675. my $camname = $hash->{CAMNAME};
  1676. my $name = $hash->{NAME};
  1677. RemoveInternalTimer($hash, "setoptpar");
  1678. return if(IsDisabled($name));
  1679. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1680. $hash->{OPMODE} = "setoptpar";
  1681. $hash->{HELPER}{ACTIVE} = "on";
  1682. $hash->{HELPER}{LOGINRETRIES} = 0;
  1683. if ($attr{$name}{debugactivetoken}) {
  1684. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1685. }
  1686. SSCam_getapisites($hash);
  1687. } else {
  1688. InternalTimer(gettimeofday()+0.6, "setoptpar", $hash, 0);
  1689. }
  1690. }
  1691. ###########################################################################
  1692. # HomeMode Status abfragen
  1693. ###########################################################################
  1694. sub gethomemodestate ($) {
  1695. my ($hash) = @_;
  1696. my $camname = $hash->{CAMNAME};
  1697. my $name = $hash->{NAME};
  1698. RemoveInternalTimer($hash, "gethomemodestate");
  1699. return if(IsDisabled($name) || !defined($hash->{HELPER}{APIHMMAXVER}));
  1700. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1701. $hash->{OPMODE} = "gethomemodestate";
  1702. $hash->{HELPER}{ACTIVE} = "on";
  1703. $hash->{HELPER}{LOGINRETRIES} = 0;
  1704. if ($attr{$name}{debugactivetoken}) {
  1705. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1706. }
  1707. SSCam_getapisites($hash);
  1708. } else {
  1709. InternalTimer(gettimeofday()+0.7, "gethomemodestate", $hash, 0);
  1710. }
  1711. }
  1712. ###########################################################################
  1713. # SVS Log abrufen
  1714. ###########################################################################
  1715. sub getsvslog ($) {
  1716. my ($hash) = @_;
  1717. my $camname = $hash->{CAMNAME};
  1718. my $name = $hash->{NAME};
  1719. RemoveInternalTimer($hash, "getsvslog");
  1720. return if(IsDisabled($name));
  1721. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1722. $hash->{OPMODE} = "getsvslog";
  1723. $hash->{HELPER}{ACTIVE} = "on";
  1724. $hash->{HELPER}{LOGINRETRIES} = 0;
  1725. if ($attr{$name}{debugactivetoken}) {
  1726. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1727. }
  1728. SSCam_getapisites($hash);
  1729. } else {
  1730. InternalTimer(gettimeofday()+0.9, "getsvslog", $hash, 0);
  1731. }
  1732. }
  1733. ###########################################################################
  1734. # Session SSCam_logout
  1735. ###########################################################################
  1736. sub sessionoff ($) {
  1737. my ($hash) = @_;
  1738. my $camname = $hash->{CAMNAME};
  1739. my $name = $hash->{NAME};
  1740. RemoveInternalTimer($hash, "sessionoff");
  1741. return if(IsDisabled($name));
  1742. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1743. $hash->{OPMODE} = "logout";
  1744. $hash->{HELPER}{ACTIVE} = "on";
  1745. if ($attr{$name}{debugactivetoken}) {
  1746. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1747. }
  1748. SSCam_logout($hash);
  1749. } else {
  1750. InternalTimer(gettimeofday()+1.1, "sessionoff", $hash, 0);
  1751. }
  1752. }
  1753. ###########################################################################
  1754. # Kamera allgemeine Informationen abrufen (Get), sub von getcaminfoall
  1755. ###########################################################################
  1756. sub getcaminfo ($) {
  1757. my ($hash) = @_;
  1758. my $camname = $hash->{CAMNAME};
  1759. my $name = $hash->{NAME};
  1760. RemoveInternalTimer($hash, "getcaminfo");
  1761. return if(IsDisabled($name));
  1762. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1763. $hash->{OPMODE} = "Getcaminfo";
  1764. $hash->{HELPER}{ACTIVE} = "on";
  1765. $hash->{HELPER}{LOGINRETRIES} = 0;
  1766. if ($attr{$name}{debugactivetoken}) {
  1767. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1768. }
  1769. SSCam_getapisites($hash);
  1770. } else {
  1771. InternalTimer(gettimeofday()+2, "getcaminfo", $hash, 0);
  1772. }
  1773. }
  1774. ################################################################################
  1775. # Kamera Stream Urls abrufen (Get), Aufruf aus getcaminfoall
  1776. ################################################################################
  1777. sub getStmUrlPath ($) {
  1778. my ($hash) = @_;
  1779. my $camname = $hash->{CAMNAME};
  1780. my $name = $hash->{NAME};
  1781. RemoveInternalTimer($hash, "getStmUrlPath");
  1782. return if(IsDisabled($name));
  1783. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1784. # Stream-Urls abrufen
  1785. $hash->{OPMODE} = "getStmUrlPath";
  1786. $hash->{HELPER}{ACTIVE} = "on";
  1787. $hash->{HELPER}{LOGINRETRIES} = 0;
  1788. if ($attr{$name}{debugactivetoken}) {
  1789. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1790. }
  1791. SSCam_getapisites($hash);
  1792. } else {
  1793. InternalTimer(gettimeofday()+2, "getStmUrlPath", $hash, 0);
  1794. }
  1795. }
  1796. ###########################################################################
  1797. # query SVS-Event information , sub von getcaminfoall
  1798. ###########################################################################
  1799. sub SSCam_geteventlist ($) {
  1800. my ($hash) = @_;
  1801. my $camname = $hash->{CAMNAME};
  1802. my $name = $hash->{NAME};
  1803. RemoveInternalTimer($hash, "SSCam_geteventlist");
  1804. return if(IsDisabled($name));
  1805. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1806. $hash->{OPMODE} = "geteventlist";
  1807. $hash->{HELPER}{ACTIVE} = "on";
  1808. $hash->{HELPER}{LOGINRETRIES} = 0;
  1809. if ($attr{$name}{debugactivetoken}) {
  1810. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1811. }
  1812. SSCam_getapisites($hash);
  1813. } else {
  1814. InternalTimer(gettimeofday()+2, "SSCam_geteventlist", $hash, 0);
  1815. }
  1816. }
  1817. ###########################################################################
  1818. # Enumerate motion detection parameters, sub von getcaminfoall
  1819. ###########################################################################
  1820. sub SSCam_getmotionenum ($) {
  1821. my ($hash) = @_;
  1822. my $camname = $hash->{CAMNAME};
  1823. my $name = $hash->{NAME};
  1824. RemoveInternalTimer($hash, "SSCam_getmotionenum");
  1825. return if(IsDisabled($name));
  1826. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1827. $hash->{OPMODE} = "getmotionenum";
  1828. $hash->{HELPER}{ACTIVE} = "on";
  1829. $hash->{HELPER}{LOGINRETRIES} = 0;
  1830. if ($attr{$name}{debugactivetoken}) {
  1831. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1832. }
  1833. SSCam_getapisites($hash);
  1834. } else {
  1835. InternalTimer(gettimeofday()+2, "SSCam_getmotionenum", $hash, 0);
  1836. }
  1837. }
  1838. ##########################################################################
  1839. # Capabilities von Kamera abrufen (Get), sub von getcaminfoall
  1840. ##########################################################################
  1841. sub SSCam_getcapabilities ($) {
  1842. my ($hash) = @_;
  1843. my $camname = $hash->{CAMNAME};
  1844. my $name = $hash->{NAME};
  1845. RemoveInternalTimer($hash, "SSCam_getcapabilities");
  1846. return if(IsDisabled($name));
  1847. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1848. $hash->{OPMODE} = "Getcapabilities";
  1849. $hash->{HELPER}{ACTIVE} = "on";
  1850. $hash->{HELPER}{LOGINRETRIES} = 0;
  1851. if ($attr{$name}{debugactivetoken}) {
  1852. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1853. }
  1854. SSCam_getapisites($hash);
  1855. } else {
  1856. InternalTimer(gettimeofday()+2, "SSCam_getcapabilities", $hash, 0);
  1857. }
  1858. }
  1859. ##########################################################################
  1860. # PTZ Presets abrufen (Get), sub von getcaminfoall
  1861. ##########################################################################
  1862. sub SSCam_getptzlistpreset ($) {
  1863. my ($hash) = @_;
  1864. my $camname = $hash->{CAMNAME};
  1865. my $name = $hash->{NAME};
  1866. RemoveInternalTimer($hash, "SSCam_getptzlistpreset");
  1867. return if(IsDisabled($name));
  1868. if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") {
  1869. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname is not a PTZ-Camera");
  1870. return;
  1871. }
  1872. if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") {
  1873. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname has no capability to tilt/pan");
  1874. return;
  1875. }
  1876. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1877. $hash->{OPMODE} = "Getptzlistpreset";
  1878. $hash->{HELPER}{ACTIVE} = "on";
  1879. $hash->{HELPER}{LOGINRETRIES} = 0;
  1880. if ($attr{$name}{debugactivetoken}) {
  1881. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1882. }
  1883. SSCam_getapisites($hash);
  1884. } else {
  1885. InternalTimer(gettimeofday()+2, "SSCam_getptzlistpreset", $hash, 0);
  1886. }
  1887. }
  1888. ##########################################################################
  1889. # PTZ Patrols abrufen (Get), sub von getcaminfoall
  1890. ##########################################################################
  1891. sub SSCam_getptzlistpatrol ($) {
  1892. my ($hash) = @_;
  1893. my $camname = $hash->{CAMNAME};
  1894. my $name = $hash->{NAME};
  1895. RemoveInternalTimer($hash, "SSCam_getptzlistpatrol");
  1896. return if(IsDisabled($name));
  1897. if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") {
  1898. Log3($name, 4, "$name - Retrieval of Patrols for $camname can't be executed - $camname is not a PTZ-Camera");
  1899. return;
  1900. }
  1901. if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") {
  1902. Log3($name, 4, "$name - Retrieval of Patrols for $camname can't be executed - $camname has no capability to tilt/pan");
  1903. return;
  1904. }
  1905. if ($hash->{HELPER}{ACTIVE} ne "on") {
  1906. $hash->{OPMODE} = "Getptzlistpatrol";
  1907. $hash->{HELPER}{ACTIVE} = "on";
  1908. $hash->{HELPER}{LOGINRETRIES} = 0;
  1909. if ($attr{$name}{debugactivetoken}) {
  1910. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1911. }
  1912. SSCam_getapisites($hash);
  1913. } else {
  1914. InternalTimer(gettimeofday()+2, "SSCam_getptzlistpatrol", $hash, 0);
  1915. }
  1916. }
  1917. #############################################################################################################################
  1918. ####### Begin Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) #######
  1919. #############################################################################################################################
  1920. sub SSCam_getapisites($) {
  1921. my ($hash) = @_;
  1922. my $serveraddr = $hash->{SERVERADDR};
  1923. my $serverport = $hash->{SERVERPORT};
  1924. my $name = $hash->{NAME};
  1925. my $apiinfo = $hash->{HELPER}{APIINFO}; # Info-Seite für alle API's, einzige statische Seite !
  1926. my $apiauth = $hash->{HELPER}{APIAUTH};
  1927. my $apiextrec = $hash->{HELPER}{APIEXTREC};
  1928. my $apiextevt = $hash->{HELPER}{APIEXTEVT};
  1929. my $apicam = $hash->{HELPER}{APICAM};
  1930. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  1931. my $apiptz = $hash->{HELPER}{APIPTZ};
  1932. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  1933. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  1934. my $apievent = $hash->{HELPER}{APIEVENT};
  1935. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  1936. my $apistm = $hash->{HELPER}{APISTM};
  1937. my $apihm = $hash->{HELPER}{APIHM};
  1938. my $apilog = $hash->{HELPER}{APILOG};
  1939. my $url;
  1940. my $param;
  1941. # API-Pfade und MaxVersions ermitteln
  1942. Log3($name, 4, "$name - ####################################################");
  1943. Log3($name, 4, "$name - ### start cam operation $hash->{OPMODE} ");
  1944. Log3($name, 4, "$name - ####################################################");
  1945. Log3($name, 4, "$name - --- Begin Function SSCam_getapisites nonblocking ---");
  1946. if ($hash->{HELPER}{APIPARSET}) {
  1947. # API-Hashwerte sind bereits gesetzt -> Abruf überspringen
  1948. Log3($name, 4, "$name - API hashvalues already set - ignore get apisites");
  1949. return SSCam_checksid($hash);
  1950. }
  1951. my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  1952. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  1953. # URL zur Abfrage der Eigenschaften der API's
  1954. $url = "http://$serveraddr:$serverport/webapi/query.cgi?api=$apiinfo&method=Query&version=1&query=$apiauth,$apiextrec,$apicam,$apitakesnap,$apiptz,$apisvsinfo,$apicamevent,$apievent,$apivideostm,$apiextevt,$apistm,$apihm,$apilog";
  1955. Log3($name, 4, "$name - Call-Out now: $url");
  1956. $param = {
  1957. url => $url,
  1958. timeout => $httptimeout,
  1959. hash => $hash,
  1960. method => "GET",
  1961. header => "Accept: application/json",
  1962. callback => \&SSCam_getapisites_parse
  1963. };
  1964. HttpUtils_NonblockingGet ($param);
  1965. }
  1966. ####################################################################################
  1967. # Auswertung Abruf apisites
  1968. ####################################################################################
  1969. sub SSCam_getapisites_parse ($) {
  1970. my ($param, $err, $myjson) = @_;
  1971. my $hash = $param->{hash};
  1972. my $name = $hash->{NAME};
  1973. my $serveraddr = $hash->{SERVERADDR};
  1974. my $serverport = $hash->{SERVERPORT};
  1975. my $apiauth = $hash->{HELPER}{APIAUTH};
  1976. my $apiextrec = $hash->{HELPER}{APIEXTREC};
  1977. my $apiextevt = $hash->{HELPER}{APIEXTEVT};
  1978. my $apicam = $hash->{HELPER}{APICAM};
  1979. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  1980. my $apiptz = $hash->{HELPER}{APIPTZ};
  1981. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  1982. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  1983. my $apievent = $hash->{HELPER}{APIEVENT};
  1984. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  1985. my $apistm = $hash->{HELPER}{APISTM};
  1986. my $apihm = $hash->{HELPER}{APIHM};
  1987. my $apilog = $hash->{HELPER}{APILOG};
  1988. my ($apicammaxver,$apicampath);
  1989. if ($err ne "") {
  1990. # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  1991. Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err");
  1992. readingsSingleUpdate($hash, "Error", $err, 1);
  1993. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  1994. $hash->{HELPER}{ACTIVE} = "off";
  1995. if ($attr{$name}{debugactivetoken}) {
  1996. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1997. }
  1998. return;
  1999. } elsif ($myjson ne "") {
  2000. # Evaluiere ob Daten im JSON-Format empfangen wurden
  2001. ($hash, my $success) = &SSCam_evaljson($hash,$myjson,$param->{url});
  2002. unless ($success) {
  2003. Log3($name, 4, "$name - Data returned: $myjson");
  2004. $hash->{HELPER}{ACTIVE} = "off";
  2005. if ($attr{$name}{debugactivetoken}) {
  2006. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2007. }
  2008. return;
  2009. }
  2010. my $data = decode_json($myjson);
  2011. # Logausgabe decodierte JSON Daten
  2012. Log3($name, 5, "$name - JSON returned: ". Dumper $data);
  2013. $success = $data->{'success'};
  2014. if ($success) {
  2015. my $logstr;
  2016. # Pfad und Maxversion von "SYNO.API.Auth" ermitteln
  2017. my $apiauthpath = $data->{'data'}->{$apiauth}->{'path'};
  2018. $apiauthpath =~ tr/_//d if (defined($apiauthpath));
  2019. my $apiauthmaxver = $data->{'data'}->{$apiauth}->{'maxVersion'};
  2020. $logstr = defined($apiauthpath) ? "Path of $apiauth selected: $apiauthpath" : "Path of $apiauth undefined - Surveillance Station may be stopped";
  2021. Log3($name, 4, "$name - $logstr");
  2022. $logstr = defined($apiauthmaxver) ? "MaxVersion of $apiauth selected: $apiauthmaxver" : "MaxVersion of $apiauth undefined - Surveillance Station may be stopped";
  2023. Log3($name, 4, "$name - $logstr");
  2024. # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalRecording" ermitteln
  2025. my $apiextrecpath = $data->{'data'}->{$apiextrec}->{'path'};
  2026. $apiextrecpath =~ tr/_//d if (defined($apiextrecpath));
  2027. my $apiextrecmaxver = $data->{'data'}->{$apiextrec}->{'maxVersion'};
  2028. $logstr = defined($apiextrecpath) ? "Path of $apiextrec selected: $apiextrecpath" : "Path of $apiextrec undefined - Surveillance Station may be stopped";
  2029. Log3($name, 4, "$name - $logstr");
  2030. $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apiextrec selected: $apiextrecmaxver" : "MaxVersion of $apiextrec undefined - Surveillance Station may be stopped";
  2031. Log3($name, 4, "$name - $logstr");
  2032. # Pfad und Maxversion von "SYNO.SurveillanceStation.Camera" ermitteln
  2033. $apicampath = $data->{'data'}->{$apicam}->{'path'};
  2034. $apicampath =~ tr/_//d if (defined($apicampath));
  2035. $apicammaxver = $data->{'data'}->{$apicam}->{'maxVersion'};
  2036. $logstr = defined($apicampath) ? "Path of $apicam selected: $apicampath" : "Path of $apicam undefined - Surveillance Station may be stopped";
  2037. Log3($name, 4, "$name - $logstr");
  2038. $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apicam: $apicammaxver" : "MaxVersion of $apicam undefined - Surveillance Station may be stopped";
  2039. Log3($name, 4, "$name - $logstr");
  2040. # Pfad und Maxversion von "SYNO.SurveillanceStation.SnapShot" ermitteln
  2041. my $apitakesnappath = $data->{'data'}->{$apitakesnap}->{'path'};
  2042. $apitakesnappath =~ tr/_//d if (defined($apitakesnappath));
  2043. my $apitakesnapmaxver = $data->{'data'}->{$apitakesnap}->{'maxVersion'};
  2044. $logstr = defined($apitakesnappath) ? "Path of $apitakesnap selected: $apitakesnappath" : "Path of $apitakesnap undefined - Surveillance Station may be stopped";
  2045. Log3($name, 4, "$name - $logstr");
  2046. $logstr = defined($apitakesnapmaxver) ? "MaxVersion of $apitakesnap: $apitakesnapmaxver" : "MaxVersion of $apitakesnap undefined - Surveillance Station may be stopped";
  2047. Log3($name, 4, "$name - $logstr");
  2048. # Pfad und Maxversion von "SYNO.SurveillanceStation.PTZ" ermitteln
  2049. my $apiptzpath = $data->{'data'}->{$apiptz}->{'path'};
  2050. $apiptzpath =~ tr/_//d if (defined($apiptzpath));
  2051. my $apiptzmaxver = $data->{'data'}->{$apiptz}->{'maxVersion'};
  2052. $logstr = defined($apiptzpath) ? "Path of $apiptz selected: $apiptzpath" : "Path of $apiptz undefined - Surveillance Station may be stopped";
  2053. Log3($name, 4, "$name - $logstr");
  2054. $logstr = defined($apiptzmaxver) ? "MaxVersion of $apiptz: $apiptzmaxver" : "MaxVersion of $apiptz undefined - Surveillance Station may be stopped";
  2055. Log3($name, 4, "$name - $logstr");
  2056. # Pfad und Maxversion von "SYNO.SurveillanceStation.Info" ermitteln
  2057. my $apisvsinfopath = $data->{'data'}->{$apisvsinfo}->{'path'};
  2058. $apisvsinfopath =~ tr/_//d if (defined($apisvsinfopath));
  2059. my $apisvsinfomaxver = $data->{'data'}->{$apisvsinfo}->{'maxVersion'};
  2060. $logstr = defined($apisvsinfopath) ? "Path of $apisvsinfo selected: $apisvsinfopath" : "Path of $apisvsinfo undefined - Surveillance Station may be stopped";
  2061. Log3($name, 4, "$name - $logstr");
  2062. $logstr = defined($apisvsinfomaxver) ? "MaxVersion of $apisvsinfo: $apisvsinfomaxver" : "MaxVersion of $apisvsinfo undefined - Surveillance Station may be stopped";
  2063. Log3($name, 4, "$name - $logstr");
  2064. # Pfad und Maxversion von "SYNO.Surveillance.Camera.Event" ermitteln
  2065. my $apicameventpath = $data->{'data'}->{$apicamevent}->{'path'};
  2066. $apicameventpath =~ tr/_//d if (defined($apicameventpath));
  2067. my $apicameventmaxver = $data->{'data'}->{$apicamevent}->{'maxVersion'};
  2068. $logstr = defined($apicameventpath) ? "Path of $apicamevent selected: $apicameventpath" : "Path of $apicamevent undefined - Surveillance Station may be stopped";
  2069. Log3($name, 4, "$name - $logstr");
  2070. $logstr = defined($apicameventmaxver) ? "MaxVersion of $apicamevent: $apicameventmaxver" : "MaxVersion of $apicamevent undefined - Surveillance Station may be stopped";
  2071. Log3($name, 4, "$name - $logstr");
  2072. # Pfad und Maxversion von "SYNO.Surveillance.Event" ermitteln
  2073. my $apieventpath = $data->{'data'}->{$apievent}->{'path'};
  2074. $apieventpath =~ tr/_//d if (defined($apieventpath));
  2075. my $apieventmaxver = $data->{'data'}->{$apievent}->{'maxVersion'};
  2076. $logstr = defined($apieventpath) ? "Path of $apievent selected: $apieventpath" : "Path of $apievent undefined - Surveillance Station may be stopped";
  2077. Log3($name, 4, "$name - $logstr");
  2078. $logstr = defined($apieventmaxver) ? "MaxVersion of $apievent: $apieventmaxver" : "MaxVersion of $apievent undefined - Surveillance Station may be stopped";
  2079. Log3($name, 4, "$name - $logstr");
  2080. # Pfad und Maxversion von "SYNO.Surveillance.VideoStream" ermitteln
  2081. my $apivideostmpath = $data->{'data'}->{$apivideostm}->{'path'};
  2082. $apivideostmpath =~ tr/_//d if (defined($apivideostmpath));
  2083. my $apivideostmmaxver = $data->{'data'}->{$apivideostm}->{'maxVersion'};
  2084. $logstr = defined($apivideostmpath) ? "Path of $apivideostm selected: $apivideostmpath" : "Path of $apivideostm undefined - Surveillance Station may be stopped";
  2085. Log3($name, 4, "$name - $logstr");
  2086. $logstr = defined($apivideostmmaxver) ? "MaxVersion of $apivideostm: $apivideostmmaxver" : "MaxVersion of $apivideostm undefined - Surveillance Station may be stopped";
  2087. Log3($name, 4, "$name - $logstr");
  2088. # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalEvent" ermitteln
  2089. my $apiextevtpath = $data->{'data'}->{$apiextevt}->{'path'};
  2090. $apiextevtpath =~ tr/_//d if (defined($apiextevtpath));
  2091. my $apiextevtmaxver = $data->{'data'}->{$apiextevt}->{'maxVersion'};
  2092. $logstr = defined($apiextevtpath) ? "Path of $apiextevt selected: $apiextevtpath" : "Path of $apiextevt undefined - Surveillance Station may be stopped";
  2093. Log3($name, 4, "$name - $logstr");
  2094. $logstr = defined($apiextevtmaxver) ? "MaxVersion of $apiextevt selected: $apiextevtmaxver" : "MaxVersion of $apiextevt undefined - Surveillance Station may be stopped";
  2095. Log3($name, 4, "$name - $logstr");
  2096. # Pfad und Maxversion von "SYNO.SurveillanceStation.Streaming" ermitteln
  2097. my $apistmpath = $data->{'data'}->{$apistm}->{'path'};
  2098. $apistmpath =~ tr/_//d if (defined($apistmpath));
  2099. my $apistmmaxver = $data->{'data'}->{$apistm}->{'maxVersion'};
  2100. $logstr = defined($apistmpath) ? "Path of $apistm selected: $apistmpath" : "Path of $apistm undefined - Surveillance Station may be stopped";
  2101. Log3($name, 4, "$name - $logstr");
  2102. $logstr = defined($apistmmaxver) ? "MaxVersion of $apistm selected: $apistmmaxver" : "MaxVersion of $apistm undefined - Surveillance Station may be stopped";
  2103. Log3($name, 4, "$name - $logstr");
  2104. # Pfad und Maxversion von "SYNO.SurveillanceStation.HomeMode" ermitteln
  2105. my $apihmpath = $data->{'data'}->{$apihm}->{'path'};
  2106. $apihmpath =~ tr/_//d if (defined($apihmpath));
  2107. my $apihmmaxver = $data->{'data'}->{$apihm}->{'maxVersion'};
  2108. $logstr = defined($apihmpath) ? "Path of $apihm selected: $apihmpath" : "Path of $apihm undefined - Surveillance Station may be stopped";
  2109. Log3($name, 4, "$name - $logstr");
  2110. $logstr = defined($apihmmaxver) ? "MaxVersion of $apihm selected: $apihmmaxver" : "MaxVersion of $apihm undefined - Surveillance Station may be stopped";
  2111. Log3($name, 4, "$name - $logstr");
  2112. # Pfad und Maxversion von "SYNO.SurveillanceStation.Log" ermitteln
  2113. my $apilogpath = $data->{'data'}->{$apilog}->{'path'};
  2114. $apilogpath =~ tr/_//d if (defined($apilogpath));
  2115. my $apilogmaxver = $data->{'data'}->{$apilog}->{'maxVersion'};
  2116. $logstr = defined($apilogpath) ? "Path of $apilog selected: $apilogpath" : "Path of $apilog undefined - Surveillance Station may be stopped";
  2117. Log3($name, 4, "$name - $logstr");
  2118. $logstr = defined($apilogmaxver) ? "MaxVersion of $apilog selected: $apilogmaxver" : "MaxVersion of $apilog undefined - Surveillance Station may be stopped";
  2119. Log3($name, 4, "$name - $logstr");
  2120. # aktuelle oder simulierte SVS-Version für Fallentscheidung setzen
  2121. no warnings 'uninitialized';
  2122. my $major = $hash->{HELPER}{SVSVERSION}{MAJOR};
  2123. my $minor = $hash->{HELPER}{SVSVERSION}{MINOR};
  2124. my $small = $hash->{HELPER}{SVSVERSION}{SMALL};
  2125. my $build = $hash->{HELPER}{SVSVERSION}{BUILD};
  2126. my $actvs = $major.$minor.$small.$build;
  2127. Log3($name, 4, "$name - installed SVS version is: $actvs");
  2128. use warnings;
  2129. if(AttrVal($name,"simu_SVSversion",0)) {
  2130. my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", ""));
  2131. $actvs = $vl[0];
  2132. $actvs .= $vl[1];
  2133. $actvs .= ($vl[2] =~ /\d/)?$vl[2]."xxxx":$vl[2];
  2134. $actvs .= "-simu";
  2135. }
  2136. # Downgrades für nicht kompatible API-Versionen
  2137. # hier nur nutzen wenn API zentral downgraded werden soll
  2138. # In den neueren API-Upgrades werden nur einzelne Funktionen auf eine höhere API-Version gezogen
  2139. # -> diese Steuerung erfolgt in den einzelnen Funktionsaufrufen in SSCam_camop
  2140. Log3($name, 4, "$name - ------- Begin of adaption section -------");
  2141. #$apiptzmaxver = 4;
  2142. #Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  2143. #$apicammaxver = 8;
  2144. #Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  2145. Log3($name, 4, "$name - ------- End of adaption section -------");
  2146. # Simulation anderer SVS-Versionen
  2147. Log3($name, 4, "$name - ------- Begin of simulation section -------");
  2148. if (AttrVal($name, "simu_SVSversion", undef)) {
  2149. Log3($name, 4, "$name - SVS version $actvs will be simulated");
  2150. if ($actvs =~ /^71/) {
  2151. $apicammaxver = 8;
  2152. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  2153. $apiauthmaxver = 4;
  2154. Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver");
  2155. $apiextrecmaxver = 2;
  2156. Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver");
  2157. $apiptzmaxver = 4;
  2158. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  2159. } elsif ($actvs =~ /^72/) {
  2160. $apicammaxver = 8;
  2161. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  2162. $apiauthmaxver = 6;
  2163. Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver");
  2164. $apiextrecmaxver = 3;
  2165. Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver");
  2166. $apiptzmaxver = 5;
  2167. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  2168. } elsif ($actvs =~ /^800/) {
  2169. $apicammaxver = 9;
  2170. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  2171. $apiauthmaxver = 6;
  2172. Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver");
  2173. $apiextrecmaxver = 3;
  2174. Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver");
  2175. $apiptzmaxver = 5;
  2176. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  2177. }
  2178. } else {
  2179. Log3($name, 4, "$name - no simulations done !");
  2180. }
  2181. Log3($name, 4, "$name - ------- End of simulation section -------");
  2182. # ermittelte Werte in $hash einfügen
  2183. $hash->{HELPER}{APIAUTHPATH} = $apiauthpath;
  2184. $hash->{HELPER}{APIAUTHMAXVER} = $apiauthmaxver;
  2185. $hash->{HELPER}{APIEXTRECPATH} = $apiextrecpath;
  2186. $hash->{HELPER}{APIEXTRECMAXVER} = $apiextrecmaxver;
  2187. $hash->{HELPER}{APICAMPATH} = $apicampath;
  2188. $hash->{HELPER}{APICAMMAXVER} = $apicammaxver;
  2189. $hash->{HELPER}{APITAKESNAPPATH} = $apitakesnappath;
  2190. $hash->{HELPER}{APITAKESNAPMAXVER} = $apitakesnapmaxver;
  2191. $hash->{HELPER}{APIPTZPATH} = $apiptzpath;
  2192. $hash->{HELPER}{APIPTZMAXVER} = $apiptzmaxver;
  2193. $hash->{HELPER}{APISVSINFOPATH} = $apisvsinfopath;
  2194. $hash->{HELPER}{APISVSINFOMAXVER} = $apisvsinfomaxver;
  2195. $hash->{HELPER}{APICAMEVENTPATH} = $apicameventpath;
  2196. $hash->{HELPER}{APICAMEVENTMAXVER} = $apicameventmaxver;
  2197. $hash->{HELPER}{APIEVENTPATH} = $apieventpath;
  2198. $hash->{HELPER}{APIEVENTMAXVER} = $apieventmaxver;
  2199. $hash->{HELPER}{APIVIDEOSTMPATH} = $apivideostmpath;
  2200. $hash->{HELPER}{APIVIDEOSTMMAXVER} = $apivideostmmaxver;
  2201. $hash->{HELPER}{APIEXTEVTPATH} = $apiextevtpath;
  2202. $hash->{HELPER}{APIEXTEVTMAXVER} = $apiextevtmaxver;
  2203. $hash->{HELPER}{APISTMPATH} = $apistmpath;
  2204. $hash->{HELPER}{APISTMMAXVER} = $apistmmaxver;
  2205. $hash->{HELPER}{APIHMPATH} = $apihmpath;
  2206. $hash->{HELPER}{APIHMMAXVER} = $apihmmaxver;
  2207. $hash->{HELPER}{APILOGPATH} = $apilogpath;
  2208. $hash->{HELPER}{APILOGMAXVER} = $apilogmaxver;
  2209. readingsBeginUpdate($hash);
  2210. readingsBulkUpdate($hash,"Errorcode","none");
  2211. readingsBulkUpdate($hash,"Error","none");
  2212. readingsEndUpdate($hash,1);
  2213. # API Hash values sind gesetzt
  2214. $hash->{HELPER}{APIPARSET} = 1;
  2215. } else {
  2216. my $error = "couldn't call API-Infosite";
  2217. readingsBeginUpdate($hash);
  2218. readingsBulkUpdate($hash,"Errorcode","none");
  2219. readingsBulkUpdate($hash,"Error",$error);
  2220. readingsEndUpdate($hash, 1);
  2221. Log3($name, 2, "$name - ERROR - the API-Query couldn't be executed successfully");
  2222. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  2223. $hash->{HELPER}{ACTIVE} = "off";
  2224. if ($attr{$name}{debugactivetoken}) {
  2225. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2226. }
  2227. return;
  2228. }
  2229. }
  2230. return SSCam_checksid($hash);
  2231. }
  2232. #############################################################################################
  2233. # Check ob Session ID gesetzt ist - ggf. login
  2234. #############################################################################################
  2235. sub SSCam_checksid ($) {
  2236. my ($hash) = @_;
  2237. my $name = $hash->{NAME};
  2238. my $subref;
  2239. if(SSCam_IsModelCam($hash)) {
  2240. # Folgefunktion wenn Cam-Device
  2241. $subref = "SSCam_getcamid";
  2242. } else {
  2243. # Folgefunktion wenn SVS-Device
  2244. $subref = "SSCam_camop";
  2245. }
  2246. # SID holen bzw. login
  2247. my $sid = $hash->{HELPER}{SID};
  2248. if(!$sid) {
  2249. Log3($name, 3, "$name - no session ID found - get new one");
  2250. SSCam_login($hash,$subref);
  2251. return;
  2252. }
  2253. if(SSCam_IsModelCam($hash)) {
  2254. # Normalverarbeitung für Cams
  2255. return SSCam_getcamid($hash);
  2256. } else {
  2257. # Sprung zu SSCam_camop wenn SVS Device
  2258. return SSCam_camop($hash);
  2259. }
  2260. }
  2261. #############################################################################################
  2262. # Abruf der installierten Cams
  2263. #############################################################################################
  2264. sub SSCam_getcamid ($) {
  2265. my ($hash) = @_;
  2266. my $name = $hash->{NAME};
  2267. my $serveraddr = $hash->{SERVERADDR};
  2268. my $serverport = $hash->{SERVERPORT};
  2269. my $apicam = $hash->{HELPER}{APICAM};
  2270. my $apicampath = $hash->{HELPER}{APICAMPATH};
  2271. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  2272. my $sid = $hash->{HELPER}{SID};
  2273. my $url;
  2274. # die Kamera-Id wird aus dem Kameranamen (Surveillance Station) ermittelt
  2275. Log3($name, 4, "$name - --- Begin Function SSCam_getcamid nonblocking ---");
  2276. if ($hash->{CAMID}) {
  2277. # Camid ist bereits ermittelt -> Abruf überspringen
  2278. Log3($name, 4, "$name - CAMID already set - ignore get camid");
  2279. return SSCam_camop($hash);
  2280. }
  2281. my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  2282. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  2283. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=List&basic=true&streamInfo=true&camStm=true&_sid=\"$sid\"";
  2284. if ($apicammaxver >= 9) {
  2285. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=\"List\"&basic=true&streamInfo=true&camStm=0&_sid=\"$sid\"";
  2286. }
  2287. Log3($name, 4, "$name - Call-Out now: $url");
  2288. my $param = {
  2289. url => $url,
  2290. timeout => $httptimeout,
  2291. hash => $hash,
  2292. method => "GET",
  2293. header => "Accept: application/json",
  2294. callback => \&SSCam_getcamid_parse
  2295. };
  2296. HttpUtils_NonblockingGet($param);
  2297. }
  2298. #############################################################################################
  2299. # Auswertung installierte Cams, Selektion Cam , Ausführung Operation
  2300. #############################################################################################
  2301. sub SSCam_getcamid_parse ($) {
  2302. my ($param, $err, $myjson) = @_;
  2303. my $hash = $param->{hash};
  2304. my $name = $hash->{NAME};
  2305. my $camname = $hash->{CAMNAME};
  2306. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  2307. my ($data,$success,$error,$errorcode,$camid);
  2308. my ($i,$n,$id);
  2309. my %allcams;
  2310. if ($err ne "") {
  2311. # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  2312. Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err");
  2313. readingsSingleUpdate($hash, "Error", $err, 1);
  2314. return SSCam_login($hash,'SSCam_getapisites');
  2315. } elsif ($myjson ne "") {
  2316. # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  2317. # evaluiere ob Daten im JSON-Format empfangen wurden, Achtung: sehr viele Daten mit verbose=5
  2318. ($hash, $success) = SSCam_evaljson($hash,$myjson,$param->{url});
  2319. unless ($success) {
  2320. Log3($name, 4, "$name - Data returned: ".$myjson);
  2321. $hash->{HELPER}{ACTIVE} = "off";
  2322. if ($attr{$name}{debugactivetoken}) {
  2323. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2324. }
  2325. return;
  2326. }
  2327. $data = decode_json($myjson);
  2328. # lesbare Ausgabe der decodierten JSON-Daten
  2329. Log3($name, 5, "$name - JSON returned: ". Dumper $data);
  2330. $success = $data->{'success'};
  2331. if ($success) {
  2332. # die Liste aller Kameras konnte ausgelesen werden
  2333. $i = 0;
  2334. # Namen aller installierten Kameras mit Id's in Assoziatives Array einlesen
  2335. %allcams = ();
  2336. while ($data->{'data'}->{'cameras'}->[$i]) {
  2337. if ($apicammaxver <= 8) {
  2338. $n = $data->{'data'}->{'cameras'}->[$i]->{'name'};
  2339. } else {
  2340. $n = $data->{'data'}->{'cameras'}->[$i]->{'newName'}; # Änderung ab SVS 8.0.0
  2341. }
  2342. $id = $data->{'data'}->{'cameras'}->[$i]->{'id'};
  2343. $allcams{"$n"} = "$id";
  2344. $i += 1;
  2345. }
  2346. # Ist der gesuchte Kameraname im Hash enhalten (in SVS eingerichtet ?)
  2347. if (exists($allcams{$camname})) {
  2348. $camid = $allcams{$camname};
  2349. # in hash eintragen
  2350. $hash->{CAMID} = $camid;
  2351. # Logausgabe
  2352. Log3($name, 4, "$name - Detection Camid successful - $camname ID: $camid");
  2353. } else {
  2354. # Kameraname nicht gefunden, id = ""
  2355. # Setreading
  2356. readingsBeginUpdate($hash);
  2357. readingsBulkUpdate($hash,"Errorcode","none");
  2358. readingsBulkUpdate($hash,"Error","Camera(ID) not found in Surveillance Station");
  2359. readingsEndUpdate($hash, 1);
  2360. # Logausgabe
  2361. Log3($name, 2, "$name - ERROR - Cameraname $camname wasn't found in Surveillance Station. Check Userrights, Cameraname and Spelling");
  2362. $hash->{HELPER}{ACTIVE} = "off";
  2363. if ($attr{$name}{debugactivetoken}) {
  2364. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2365. }
  2366. return;
  2367. }
  2368. } else {
  2369. # Errorcode aus JSON ermitteln
  2370. $errorcode = $data->{'error'}->{'code'};
  2371. # Fehlertext zum Errorcode ermitteln
  2372. $error = SSCam_experror($hash,$errorcode);
  2373. readingsBeginUpdate($hash);
  2374. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  2375. readingsBulkUpdate($hash,"Error",$error);
  2376. readingsEndUpdate($hash, 1);
  2377. if ($errorcode =~ /(105|401)/) {
  2378. # neue Login-Versuche
  2379. Log3($name, 2, "$name - ERROR - $errorcode - $error -> try new login");
  2380. return SSCam_login($hash,'SSCam_getapisites');
  2381. } else {
  2382. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  2383. $hash->{HELPER}{ACTIVE} = "off";
  2384. if ($attr{$name}{debugactivetoken}) {
  2385. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2386. }
  2387. Log3($name, 2, "$name - ERROR - ID of Camera $camname couldn't be selected. Errorcode: $errorcode - $error");
  2388. return;
  2389. }
  2390. }
  2391. }
  2392. return SSCam_camop($hash);
  2393. }
  2394. #############################################################################################
  2395. # Ausführung Operation
  2396. #############################################################################################
  2397. sub SSCam_camop ($) {
  2398. my ($hash) = @_;
  2399. my $name = $hash->{NAME};
  2400. my $serveraddr = $hash->{SERVERADDR};
  2401. my $serverport = $hash->{SERVERPORT};
  2402. my $apicam = $hash->{HELPER}{APICAM};
  2403. my $apicampath = $hash->{HELPER}{APICAMPATH};
  2404. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  2405. my $apiextrec = $hash->{HELPER}{APIEXTREC};
  2406. my $apiextrecpath = $hash->{HELPER}{APIEXTRECPATH};
  2407. my $apiextrecmaxver = $hash->{HELPER}{APIEXTRECMAXVER};
  2408. my $apiextevt = $hash->{HELPER}{APIEXTEVT};
  2409. my $apiextevtpath = $hash->{HELPER}{APIEXTEVTPATH};
  2410. my $apiextevtmaxver = $hash->{HELPER}{APIEXTEVTMAXVER};
  2411. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  2412. my $apitakesnappath = $hash->{HELPER}{APITAKESNAPPATH};
  2413. my $apitakesnapmaxver = $hash->{HELPER}{APITAKESNAPMAXVER};
  2414. my $apiptz = $hash->{HELPER}{APIPTZ};
  2415. my $apiptzpath = $hash->{HELPER}{APIPTZPATH};
  2416. my $apiptzmaxver = $hash->{HELPER}{APIPTZMAXVER};
  2417. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  2418. my $apisvsinfopath = $hash->{HELPER}{APISVSINFOPATH};
  2419. my $apisvsinfomaxver = $hash->{HELPER}{APISVSINFOMAXVER};
  2420. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  2421. my $apicameventpath = $hash->{HELPER}{APICAMEVENTPATH};
  2422. my $apicameventmaxver = $hash->{HELPER}{APICAMEVENTMAXVER};
  2423. my $apievent = $hash->{HELPER}{APIEVENT};
  2424. my $apieventpath = $hash->{HELPER}{APIEVENTPATH};
  2425. my $apieventmaxver = $hash->{HELPER}{APIEVENTMAXVER};
  2426. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  2427. my $apivideostmpath = $hash->{HELPER}{APIVIDEOSTMPATH};
  2428. my $apivideostmmaxver = $hash->{HELPER}{APIVIDEOSTMMAXVER};
  2429. my $apistm = $hash->{HELPER}{APISTM};
  2430. my $apistmpath = $hash->{HELPER}{APISTMPATH};
  2431. my $apistmmaxver = $hash->{HELPER}{APISTMMAXVER};
  2432. my $apihm = $hash->{HELPER}{APIHM};
  2433. my $apihmpath = $hash->{HELPER}{APIHMPATH};
  2434. my $apihmmaxver = $hash->{HELPER}{APIHMMAXVER};
  2435. my $apilog = $hash->{HELPER}{APILOG};
  2436. my $apilogpath = $hash->{HELPER}{APILOGPATH};
  2437. my $apilogmaxver = $hash->{HELPER}{APILOGMAXVER};
  2438. my $sid = $hash->{HELPER}{SID};
  2439. my $OpMode = $hash->{OPMODE};
  2440. my $camid = $hash->{CAMID};
  2441. my ($livestream,$winname,$attr,$room,$param);
  2442. my ($url,$snapid,$httptimeout,$expmode,$motdetsc);
  2443. Log3($name, 4, "$name - --- Begin Function $OpMode nonblocking ---");
  2444. $httptimeout = AttrVal($name, "httptimeout", 4);
  2445. $httptimeout = $httptimeout+90 if($OpMode eq "setoptpar"); # setzen der Optimierungsparameter dauert lange !
  2446. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  2447. if ($OpMode eq "Start") {
  2448. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=start&_sid=\"$sid\"";
  2449. if($apiextrecmaxver >= 3) {
  2450. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=start&_sid=\"$sid\"";
  2451. }
  2452. } elsif ($OpMode eq "Stop") {
  2453. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=stop&_sid=\"$sid\"";
  2454. if($apiextrecmaxver >= 3) {
  2455. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=stop&_sid=\"$sid\"";
  2456. }
  2457. } elsif ($OpMode eq "Snap") {
  2458. # ein Schnappschuß wird ausgelöst
  2459. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&dsId=\"0\"&method=\"TakeSnapshot\"&version=\"$apitakesnapmaxver\"&camId=\"$camid\"&blSave=\"true\"&_sid=\"$sid\"";
  2460. readingsSingleUpdate($hash,"state", "snap", 1);
  2461. readingsSingleUpdate($hash, "LastSnapId", "", 0);
  2462. } elsif ($OpMode eq "getsnapinfo" || $OpMode eq "getsnapgallery") {
  2463. # Informationen über den letzten oder mehrere Schnappschüsse ermitteln
  2464. my $limit = $hash->{HELPER}{SNAPLIMIT};
  2465. my $imgsize = $hash->{HELPER}{SNAPIMGSIZE};
  2466. my $keyword = $hash->{HELPER}{KEYWORD};
  2467. Log3($name,4, "$name - Call getsnapinfo with params: Image numbers => $limit, Image size => $imgsize, Keyword => $keyword");
  2468. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&keyword=\"$keyword\"&imgSize=\"$imgsize\"&limit=\"$limit\"&_sid=\"$sid\"";
  2469. } elsif ($OpMode eq "getsnapfilename") {
  2470. # der Filename der aktuellen Schnappschuß-ID wird ermittelt
  2471. $snapid = ReadingsVal("$name", "LastSnapId", " ");
  2472. Log3($name, 4, "$name - Get filename of present Snap-ID $snapid");
  2473. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&imgSize=\"0\"&idList=\"$snapid\"&_sid=\"$sid\"";
  2474. }elsif ($OpMode eq "gopreset") {
  2475. # Preset wird angefahren
  2476. $apiptzmaxver = ($apiptzmaxver >= 5)?4:$apiptzmaxver;
  2477. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"GoPreset\"&position=\"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\"";
  2478. readingsSingleUpdate($hash,"state", "moving", 0);
  2479. } elsif ($OpMode eq "runpatrol") {
  2480. # eine Überwachungstour starten
  2481. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"RunPatrol\"&patrolId=\"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\"";
  2482. readingsSingleUpdate($hash,"state", "moving", 0);
  2483. } elsif ($OpMode eq "goabsptz") {
  2484. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"AbsPtz\"&cameraId=\"$camid\"&posX=\"$hash->{HELPER}{GOPTZPOSX}\"&posY=\"$hash->{HELPER}{GOPTZPOSY}\"&_sid=\"$sid\"";
  2485. readingsSingleUpdate($hash,"state", "moving", 0);
  2486. } elsif ($OpMode eq "movestart") {
  2487. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&speed=\"3\"&moveType=\"Start\"&_sid=\"$sid\"";
  2488. } elsif ($OpMode eq "movestop") {
  2489. Log3($name, 4, "$name - Stop Camera $hash->{CAMNAME} moving to direction \"$hash->{HELPER}{GOMOVEDIR}\" now");
  2490. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&moveType=\"Stop\"&_sid=\"$sid\"";
  2491. } elsif ($OpMode eq "Enable") {
  2492. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Enable&cameraIds=$camid&_sid=\"$sid\"";
  2493. if($apicammaxver >= 9) {
  2494. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=$apicammaxver&method=\"Enable\"&idList=\"$camid\"&_sid=\"$sid\"";
  2495. }
  2496. } elsif ($OpMode eq "Disable") {
  2497. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Disable&cameraIds=$camid&_sid=\"$sid\"";
  2498. if($apicammaxver >= 9) {
  2499. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=$apicammaxver&method=\"Disable\"&idList=\"$camid\"&_sid=\"$sid\"";
  2500. }
  2501. } elsif ($OpMode eq "sethomemode") {
  2502. my $sw = $hash->{HELPER}{HOMEMODE}; # HomeMode on,off
  2503. $sw = ($sw eq "on")?"true":"false";
  2504. $url = "http://$serveraddr:$serverport/webapi/$apihmpath?on=$sw&api=$apihm&method=Switch&version=$apihmmaxver&_sid=\"$sid\"";
  2505. } elsif ($OpMode eq "gethomemodestate") {
  2506. $url = "http://$serveraddr:$serverport/webapi/$apihmpath?api=$apihm&method=GetInfo&version=$apihmmaxver&_sid=\"$sid\"";
  2507. } elsif ($OpMode eq "getsvslog") {
  2508. my $sev = $hash->{HELPER}{LISTLOGSEVERITY}?$hash->{HELPER}{LISTLOGSEVERITY}:"";
  2509. my $lim = $hash->{HELPER}{LISTLOGLIMIT}?$hash->{HELPER}{LISTLOGLIMIT}:0;
  2510. my $mco = $hash->{HELPER}{LISTLOGMATCH}?$hash->{HELPER}{LISTLOGMATCH}:"";
  2511. $mco = SSCam_IsModelCam($hash)?$hash->{CAMNAME}:$mco;
  2512. $lim = 1 if(!$hash->{HELPER}{CL}{1}); # Datenabruf im Hintergrund
  2513. $sev = (lc($sev) =~ /error/)?3:(lc($sev) =~ /warning/)?2:(lc($sev) =~ /info/)?1:"";
  2514. no warnings 'uninitialized';
  2515. Log3($name,4, "$name - get logList with params: severity => $hash->{HELPER}{LISTLOGSEVERITY}, limit => $lim, matchcode => $hash->{HELPER}{LISTLOGMATCH}");
  2516. use warnings;
  2517. $url = "http://$serveraddr:$serverport/webapi/$apilogpath?api=$apilog&version=\"2\"&method=\"List\"&time2String=\"no\"&level=\"$sev\"&limit=\"$lim\"&keyword=\"$mco\"&_sid=\"$sid\"";
  2518. delete($hash->{HELPER}{LISTLOGSEVERITY});
  2519. delete($hash->{HELPER}{LISTLOGLIMIT});
  2520. delete($hash->{HELPER}{LISTLOGMATCH});
  2521. } elsif ($OpMode eq "getsvsinfo") {
  2522. $url = "http://$serveraddr:$serverport/webapi/$apisvsinfopath?api=\"$apisvsinfo\"&version=\"$apisvsinfomaxver\"&method=\"GetInfo\"&_sid=\"$sid\"";
  2523. } elsif ($OpMode eq "setoptpar") {
  2524. my $mirr = $hash->{HELPER}{MIRROR}?$hash->{HELPER}{MIRROR}:ReadingsVal("$name","CamVideoMirror","");
  2525. my $flip = $hash->{HELPER}{FLIP}?$hash->{HELPER}{FLIP}:ReadingsVal("$name","CamVideoFlip","");
  2526. my $rot = $hash->{HELPER}{ROTATE}?$hash->{HELPER}{ROTATE}:ReadingsVal("$name","CamVideoRotate","");
  2527. my $ntp = $hash->{HELPER}{NTPSERV}?$hash->{HELPER}{NTPSERV}:ReadingsVal("$name","CamNTPServer","");
  2528. my $clst = $hash->{HELPER}{CHKLIST}?$hash->{HELPER}{CHKLIST}:"";
  2529. $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver;
  2530. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&vdoMirror=$mirr&vdoRotation=$rot&vdoFlip=$flip&timeServer=\"$ntp\"&camParamChkList=$clst&cameraIds=\"$camid\"&_sid=\"$sid\"";
  2531. } elsif ($OpMode eq "Getcaminfo") {
  2532. $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver;
  2533. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetInfo\"&cameraIds=\"$camid\"&deviceOutCap=\"true\"&streamInfo=\"true\"&ptz=\"true\"&basic=\"true\"&camAppInfo=\"true\"&optimize=\"true\"&fisheye=\"true\"&eventDetection=\"true\"&_sid=\"$sid\"";
  2534. } elsif ($OpMode eq "getStmUrlPath") {
  2535. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetStmUrlPath\"&cameraIds=\"$camid\"&_sid=\"$sid\"";
  2536. if($apicammaxver >= 9) {
  2537. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&method=\"GetLiveViewPath\"&version=$apicammaxver&idList=\"$camid\"&_sid=\"$sid\"";
  2538. }
  2539. } elsif ($OpMode eq "geteventlist") {
  2540. # Abruf der Events einer Kamera
  2541. $url = "http://$serveraddr:$serverport/webapi/$apieventpath?api=\"$apievent\"&version=\"$apieventmaxver\"&method=\"List\"&cameraIds=\"$camid\"&locked=\"0\"&blIncludeSnapshot=\"false\"&reason=\"\"&limit=\"2\"&includeAllCam=\"false\"&_sid=\"$sid\"";
  2542. } elsif ($OpMode eq "Getptzlistpreset") {
  2543. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPreset&cameraId=$camid&_sid=\"$sid\"";
  2544. } elsif ($OpMode eq "Getcapabilities") {
  2545. # Capabilities einer Cam werden abgerufen
  2546. $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver;
  2547. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=\"GetCapabilityByCamId\"&cameraId=$camid&_sid=\"$sid\"";
  2548. } elsif ($OpMode eq "Getptzlistpatrol") {
  2549. # PTZ-ListPatrol werden abgerufen
  2550. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPatrol&cameraId=$camid&_sid=\"$sid\"";
  2551. } elsif ($OpMode eq "ExpMode") {
  2552. if ($hash->{HELPER}{EXPMODE} eq "auto") {
  2553. $expmode = "0";
  2554. }
  2555. elsif ($hash->{HELPER}{EXPMODE} eq "day") {
  2556. $expmode = "1";
  2557. }
  2558. elsif ($hash->{HELPER}{EXPMODE} eq "night") {
  2559. $expmode = "2";
  2560. }
  2561. $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver;
  2562. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&cameraIds=\"$camid\"&expMode=\"$expmode\"&camParamChkList=32&_sid=\"$sid\"";
  2563. } elsif ($OpMode eq "MotDetSc") {
  2564. # Hash für Optionswerte sichern für Logausgabe in Befehlsauswertung
  2565. my %motdetoptions = ();
  2566. if ($hash->{HELPER}{MOTDETSC} eq "disable") {
  2567. $motdetsc = "-1";
  2568. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\"";
  2569. } elsif ($hash->{HELPER}{MOTDETSC} eq "camera") {
  2570. $motdetsc = "0";
  2571. $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'});
  2572. $motdetoptions{OBJECTSIZE} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'});
  2573. $motdetoptions{PERCENTAGE} = $hash->{'HELPER'}{'MOTDETSC_PROP3'} if ($hash->{'HELPER'}{'MOTDETSC_PROP3'});
  2574. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&_sid=\"$sid\"";
  2575. if ($hash->{HELPER}{MOTDETSC_PROP1} || $hash->{HELPER}{MOTDETSC_PROP2} || $hash->{HELPER}{MOTDETSC_PROP13}) {
  2576. # umschalten und neue Werte setzen
  2577. $url .= "&keep=false";
  2578. } else {
  2579. # nur Umschaltung, alte Werte beibehalten
  2580. $url .= "&keep=true";
  2581. }
  2582. if ($hash->{HELPER}{MOTDETSC_PROP1}) {
  2583. # der Wert für Bewegungserkennung Kamera -> Empfindlichkeit ist gesetzt
  2584. my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1};
  2585. $url .= "&sensitivity=\"$sensitivity\"";
  2586. }
  2587. if ($hash->{HELPER}{MOTDETSC_PROP2}) {
  2588. # der Wert für Bewegungserkennung Kamera -> Objektgröße ist gesetzt
  2589. my $objectsize = delete $hash->{HELPER}{MOTDETSC_PROP2};
  2590. $url .= "&objectSize=\"$objectsize\"";
  2591. }
  2592. if ($hash->{HELPER}{MOTDETSC_PROP3}) {
  2593. # der Wert für Bewegungserkennung Kamera -> Prozentsatz für Auslösung ist gesetzt
  2594. my $percentage = delete $hash->{HELPER}{MOTDETSC_PROP3};
  2595. $url .= "&percentage=\"$percentage\"";
  2596. }
  2597. } elsif ($hash->{HELPER}{MOTDETSC} eq "SVS") {
  2598. $motdetsc = "1";
  2599. $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'});
  2600. $motdetoptions{THRESHOLD} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'});
  2601. # nur Umschaltung, alte Werte beibehalten
  2602. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\"";
  2603. if ($hash->{HELPER}{MOTDETSC_PROP1}) {
  2604. # der Wert für Bewegungserkennung SVS -> Empfindlichkeit ist gesetzt
  2605. my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1};
  2606. $url .= "&sensitivity=\"$sensitivity\"";
  2607. }
  2608. if ($hash->{HELPER}{MOTDETSC_PROP2}) {
  2609. # der Wert für Bewegungserkennung SVS -> Schwellwert ist gesetzt
  2610. my $threshold = delete $hash->{HELPER}{MOTDETSC_PROP2};
  2611. $url .= "&threshold=\"$threshold\"";
  2612. }
  2613. }
  2614. # Optionswerte in Hash sichern für Logausgabe in Befehlsauswertung
  2615. $hash->{HELPER}{MOTDETOPTIONS} = \%motdetoptions;
  2616. } elsif ($OpMode eq "getmotionenum") {
  2617. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MotionEnum\"&camId=\"$camid\"&_sid=\"$sid\"";
  2618. } elsif ($OpMode eq "extevent") {
  2619. Log3($name, 4, "$name - trigger external event \"$hash->{HELPER}{EVENTID}\"");
  2620. $url = "http://$serveraddr:$serverport/webapi/$apiextevtpath?api=$apiextevt&version=$apiextevtmaxver&method=Trigger&eventId=$hash->{HELPER}{EVENTID}&eventName=$hash->{HELPER}{EVENTID}&_sid=\"$sid\"";
  2621. } elsif ($OpMode eq "runliveview" && $hash->{HELPER}{RUNVIEW} !~ /snap/) {
  2622. if ($hash->{HELPER}{RUNVIEW} =~ m/live/) {
  2623. # externe URL
  2624. $livestream = !AttrVal($name, "livestreamprefix", undef) ? "http://$serveraddr:$serverport" : AttrVal($name, "livestreamprefix", undef);
  2625. $livestream .= "/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\"";
  2626. # interne URL
  2627. $url = "http://$serveraddr:$serverport/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\"";
  2628. readingsSingleUpdate($hash,"LiveStreamUrl", $livestream, 1) if(AttrVal($name, "showStmInfoFull", undef));
  2629. } else {
  2630. # Abspielen der letzten Aufnahme (EventId)
  2631. $url = "http://$serveraddr:$serverport/webapi/$apistmpath?api=$apistm&version=$apistmmaxver&method=EventStream&eventId=$hash->{HELPER}{CAMLASTRECID}&timestamp=1&_sid=$sid";
  2632. }
  2633. # Liveview-Link in Hash speichern -> Anzeige über SSCam_FWview, in Reading setzen für Linkversand
  2634. $hash->{HELPER}{LINK} = $url;
  2635. Log3($name, 4, "$name - Set Streaming-URL: $url");
  2636. # livestream sofort in neuem Browsertab öffnen
  2637. if ($hash->{HELPER}{OPENWINDOW}) {
  2638. $winname = $name."_view";
  2639. $attr = AttrVal($name, "htmlattr", "");
  2640. # öffnen streamwindow für die Instanz die "VIEWOPENROOM" oder Attr "room" aktuell geöffnet hat
  2641. if ($hash->{HELPER}{VIEWOPENROOM}) {
  2642. $room = $hash->{HELPER}{VIEWOPENROOM};
  2643. map {FW_directNotify("FILTER=room=$room", "#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*");
  2644. } else {
  2645. map {FW_directNotify("#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*");
  2646. }
  2647. }
  2648. # Aufnahmestatus in state abbilden mit Longpoll refresh
  2649. my $st;
  2650. (ReadingsVal("$name", "Record", "") eq "Start")?$st="on":$st="off";
  2651. readingsSingleUpdate($hash,"state", $st, 1);
  2652. $hash->{HELPER}{ACTIVE} = "off";
  2653. if ($attr{$name}{debugactivetoken}) {
  2654. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2655. }
  2656. return;
  2657. } elsif ($OpMode eq "runliveview" && $hash->{HELPER}{RUNVIEW} =~ /snap/) {
  2658. # den letzten Schnappschuß live anzeigen
  2659. my $limit = 1; # nur 1 Snap laden, für lastsnap_fw
  2660. my $imgsize = 2; # full size image, für lastsnap_fw
  2661. my $keyword = $hash->{CAMNAME}; # nur Snaps von $camname selektieren, für lastsnap_fw
  2662. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&keyword=\"$keyword\"&imgSize=\"$imgsize\"&limit=\"$limit\"&_sid=\"$sid\"";
  2663. }
  2664. Log3($name, 4, "$name - Call-Out now: $url");
  2665. $param = {
  2666. url => $url,
  2667. timeout => $httptimeout,
  2668. hash => $hash,
  2669. method => "GET",
  2670. header => "Accept: application/json",
  2671. callback => \&SSCam_camop_parse
  2672. };
  2673. HttpUtils_NonblockingGet ($param);
  2674. }
  2675. ###################################################################################
  2676. # Check ob Kameraoperation erfolgreich wie in "OpMOde" definiert
  2677. ###################################################################################
  2678. sub SSCam_camop_parse ($) {
  2679. my ($param, $err, $myjson) = @_;
  2680. my $hash = $param->{hash};
  2681. my $name = $hash->{NAME};
  2682. my $camname = $hash->{CAMNAME};
  2683. my $OpMode = $hash->{OPMODE};
  2684. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  2685. my ($rectime,$data,$success);
  2686. my ($error,$errorcode);
  2687. my ($snapid,$camLiveMode,$update_time);
  2688. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
  2689. my ($deviceType,$camStatus);
  2690. my ($patrolcnt,$patrolid,$patrolname,@patrolkeys,$patrollist);
  2691. my ($recStatus,$exposuremode,$exposurecontrol);
  2692. my ($userPriv,$verbose,$motdetsc);
  2693. my ($sensitivity_camCap,$sensitivity_value,$sensitivity_ssCap);
  2694. my ($threshold_camCap,$threshold_value,$threshold_ssCap);
  2695. my ($percentage_camCap,$percentage_value,$percentage_ssCap);
  2696. my ($objectSize_camCap,$objectSize_value,$objectSize_ssCap);
  2697. # Einstellung für Logausgabe Pollinginfos
  2698. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3
  2699. if (AttrVal($name, "pollnologging", 0) == 1) {
  2700. $verbose = 4;
  2701. } else {
  2702. $verbose = 3;
  2703. }
  2704. if ($err ne "") {
  2705. # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  2706. Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err");
  2707. readingsSingleUpdate($hash, "Error", $err, 1);
  2708. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  2709. $hash->{HELPER}{ACTIVE} = "off";
  2710. if ($attr{$name}{debugactivetoken}) {
  2711. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2712. }
  2713. return;
  2714. } elsif ($myjson ne "") {
  2715. # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  2716. # Evaluiere ob Daten im JSON-Format empfangen wurden
  2717. ($hash, $success) = &SSCam_evaljson($hash,$myjson,$param->{url});
  2718. unless ($success) {
  2719. Log3($name, 4, "$name - Data returned: ".$myjson);
  2720. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  2721. $hash->{HELPER}{ACTIVE} = "off";
  2722. if ($attr{$name}{debugactivetoken}) {
  2723. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  2724. }
  2725. return;
  2726. }
  2727. $data = decode_json($myjson);
  2728. # Logausgabe decodierte JSON Daten
  2729. Log3($name, 5, "$name - JSON returned: ". Dumper $data);
  2730. $success = $data->{'success'};
  2731. if ($success) {
  2732. # Kameraoperation entsprechend "OpMode" war erfolgreich
  2733. if ($OpMode eq "Start") {
  2734. # Die Aufnahmezeit setzen
  2735. # wird "set <name> on [rectime]" verwendet -> dann [rectime] nutzen,
  2736. # sonst Attribut "rectime" wenn es gesetzt ist, falls nicht -> "RECTIME_DEF"
  2737. if (defined($hash->{HELPER}{RECTIME_TEMP})) {
  2738. $rectime = delete $hash->{HELPER}{RECTIME_TEMP};
  2739. } else {
  2740. if (defined($attr{$name}{rectime}) && AttrVal($name,"rectime", undef) == 0) {
  2741. $rectime = 0;
  2742. } else {
  2743. $rectime = AttrVal($name, "rectime", undef) ? AttrVal($name, "rectime", undef) : $hash->{HELPER}{RECTIME_DEF};
  2744. }
  2745. }
  2746. if ($rectime == "0") {
  2747. Log3($name, 3, "$name - Camera $camname endless Recording started - stop it by stop-command !");
  2748. } else {
  2749. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2750. # Aufnahme läuft schon und wird verlängert
  2751. Log3($name, 3, "$name - running recording renewed to $rectime s");
  2752. } else {
  2753. Log3($name, 3, "$name - Camera $camname Recording with Recordtime $rectime s started");
  2754. }
  2755. }
  2756. readingsBeginUpdate($hash);
  2757. readingsBulkUpdate($hash,"Record","Start");
  2758. readingsBulkUpdate($hash,"state","on");
  2759. readingsBulkUpdate($hash,"Errorcode","none");
  2760. readingsBulkUpdate($hash,"Error","none");
  2761. readingsEndUpdate($hash, 1);
  2762. if ($rectime != 0) {
  2763. # Stop der Aufnahme nach Ablauf $rectime, wenn rectime = 0 -> endlose Aufnahme
  2764. RemoveInternalTimer($hash, "SSCam_camstoprec");
  2765. InternalTimer(gettimeofday()+$rectime, "SSCam_camstoprec", $hash);
  2766. }
  2767. } elsif ($OpMode eq "Stop") {
  2768. readingsBeginUpdate($hash);
  2769. readingsBulkUpdate($hash,"Record","Stop");
  2770. readingsBulkUpdate($hash,"state","off");
  2771. readingsBulkUpdate($hash,"Errorcode","none");
  2772. readingsBulkUpdate($hash,"Error","none");
  2773. readingsEndUpdate($hash, 1);
  2774. # Logausgabe
  2775. Log3($name, 3, "$name - Camera $camname Recording stopped");
  2776. # Aktualisierung Eventlist der letzten Aufnahme
  2777. SSCam_geteventlist($hash);
  2778. } elsif ($OpMode eq "ExpMode") {
  2779. readingsBeginUpdate($hash);
  2780. readingsBulkUpdate($hash,"Errorcode","none");
  2781. readingsBulkUpdate($hash,"Error","none");
  2782. readingsEndUpdate($hash, 1);
  2783. # Logausgabe
  2784. Log3($name, 3, "$name - Camera $camname exposure mode was set to \"$hash->{HELPER}{EXPMODE}\"");
  2785. } elsif ($OpMode eq "sethomemode") {
  2786. readingsBeginUpdate($hash);
  2787. readingsBulkUpdate($hash,"Errorcode","none");
  2788. readingsBulkUpdate($hash,"Error","none");
  2789. readingsEndUpdate($hash, 1);
  2790. Log3($name, 3, "$name - HomeMode was set to \"$hash->{HELPER}{HOMEMODE}\" ");
  2791. # Token freigeben vor nächstem Kommando
  2792. $hash->{HELPER}{ACTIVE} = "off";
  2793. # neuen HomeModeState abrufen
  2794. gethomemodestate($hash);
  2795. } elsif ($OpMode eq "gethomemodestate") {
  2796. my $hmst = $data->{'data'}{'on'};
  2797. my $hmststr = ($hmst == 1)?"on":"off";
  2798. readingsBeginUpdate($hash);
  2799. readingsBulkUpdate($hash,"HomeModeState",$hmststr);
  2800. readingsBulkUpdate($hash,"Errorcode","none");
  2801. readingsBulkUpdate($hash,"Error","none");
  2802. readingsEndUpdate($hash, 1);
  2803. } elsif ($OpMode eq "getsvslog") {
  2804. my $lec = $data->{'data'}{'total'}; # abgerufene Anzahl von Log-Einträgen
  2805. my $log = '<html>';
  2806. my $log0 = "";
  2807. my $i = 0;
  2808. while ($data->{'data'}->{'log'}->[$i]) {
  2809. my $id = $data->{'data'}->{'log'}->[$i]{'id'};
  2810. my $un = $data->{'data'}->{'log'}->[$i]{'user_name'};
  2811. my $desc = $data->{'data'}->{'log'}->[$i]{'desc'};
  2812. my $level = $data->{'data'}->{'log'}->[$i]{'type'};
  2813. $level = ($level == 3)?"Error":($level == 2)?"Warning":"Information";
  2814. my $time = $data->{'data'}->{'log'}->[$i]{'time'};
  2815. $time = FmtDateTime($time);
  2816. $log0 = $time." - ".$level." - ".$desc if($i == 0);
  2817. $log .= "$time - $level - $desc<br>";
  2818. $i++;
  2819. }
  2820. $log = "<html><b>Surveillance Station Server \"$hash->{SERVERADDR}\" Log</b> ( $i/$lec entries are displayed )<br><br>$log</html>";
  2821. # asyncOutput kann normalerweise etwa 100k uebertragen (siehe fhem.pl/addToWritebuffer() fuer Details)
  2822. # bzw. https://forum.fhem.de/index.php/topic,77310.0.html
  2823. # $log = "Too much log data were selected. Please reduce amount of data by specifying all or one of 'severity', 'limit', 'match'" if (length($log) >= 102400);
  2824. readingsBeginUpdate($hash);
  2825. readingsBulkUpdate($hash,"LastLogEntry",$log0) if(!$hash->{HELPER}{CL}{1}); # Datenabruf im Hintergrund;
  2826. readingsBulkUpdate($hash,"Errorcode","none");
  2827. readingsBulkUpdate($hash,"Error","none");
  2828. readingsEndUpdate($hash, 1);
  2829. # Ausgabe Popup der Log-Daten (nach readingsEndUpdate positionieren sonst "Connection lost, trying reconnect every 5 seconds" wenn > 102400 Zeichen)
  2830. asyncOutput($hash->{HELPER}{CL}{1},"$log");
  2831. delete($hash->{HELPER}{CL});
  2832. } elsif ($OpMode eq "setoptpar") {
  2833. my $rid = $data->{'data'}{'id'}; # Cam ID return wenn i.O.
  2834. my $ropt = $rid == $hash->{CAMID}?"none":"error in operation";
  2835. delete($hash->{HELPER}{NTPSERV});
  2836. delete($hash->{HELPER}{MIRROR});
  2837. delete($hash->{HELPER}{FLIP});
  2838. delete($hash->{HELPER}{ROTATE});
  2839. delete($hash->{HELPER}{CHKLIST});
  2840. readingsBeginUpdate($hash);
  2841. readingsBulkUpdate($hash,"Errorcode","none");
  2842. readingsBulkUpdate($hash,"Error",$ropt);
  2843. readingsEndUpdate($hash, 1);
  2844. # Token freigeben vor Abruf caminfo
  2845. $hash->{HELPER}{ACTIVE} = "off";
  2846. RemoveInternalTimer($hash, "getcaminfo");
  2847. InternalTimer(gettimeofday()+0.5, "getcaminfo", $hash, 0);
  2848. } elsif ($OpMode eq "MotDetSc") {
  2849. readingsBeginUpdate($hash);
  2850. readingsBulkUpdate($hash,"Errorcode","none");
  2851. readingsBulkUpdate($hash,"Error","none");
  2852. readingsEndUpdate($hash, 1);
  2853. # Logausgabe
  2854. my $sensitivity;
  2855. if ($hash->{HELPER}{MOTDETSC} eq "SVS" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) {
  2856. # Optionen für "SVS" sind gesetzt
  2857. $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-";
  2858. my $threshold = ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) ? ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) : "-";
  2859. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, threshold: $threshold");
  2860. } elsif ($hash->{HELPER}{MOTDETSC} eq "camera" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) {
  2861. # Optionen für "camera" sind gesetzt
  2862. $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-";
  2863. my $objectSize = ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) : "-";
  2864. my $percentage = ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) : "-";
  2865. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, objectSize: $objectSize, percentage: $percentage");
  2866. } else {
  2867. # keine Optionen Bewegungserkennung wurden gesetzt
  2868. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" ");
  2869. }
  2870. } elsif ($OpMode eq "Snap") {
  2871. # ein Schnapschuß wurde aufgenommen
  2872. # falls Aufnahme noch läuft -> state = on setzen
  2873. my $st;
  2874. (ReadingsVal("$name", "Record", "") eq "Start")?$st="on":$st="off";
  2875. readingsSingleUpdate($hash,"state", $st, 0);
  2876. $snapid = $data->{data}{'id'};
  2877. readingsBeginUpdate($hash);
  2878. readingsBulkUpdate($hash,"Errorcode","none");
  2879. readingsBulkUpdate($hash,"Error","none");
  2880. readingsEndUpdate($hash, 1);
  2881. # Logausgabe
  2882. Log3($name, 3, "$name - Snapshot of Camera $camname has been done successfully");
  2883. # Token freigeben vor nächstem Kommando
  2884. $hash->{HELPER}{ACTIVE} = "off";
  2885. # Schnappschußgalerie abrufen (snapGalleryBoost) oder nur Info des letzten Snaps
  2886. my ($slim,$ssize) = SSCam_snaplimsize($hash);
  2887. RemoveInternalTimer("getsnapinfo");
  2888. InternalTimer(gettimeofday()+0.6, "getsnapinfo", "$name:$slim:$ssize", 0);
  2889. } elsif ($OpMode eq "getsnapinfo" || $OpMode eq "getsnapgallery" || $OpMode eq "runliveview") {
  2890. # Informationen zu einem oder mehreren Schnapschüssen wurde abgerufen bzw. Lifeanzeige Schappschuß
  2891. my $lsid = exists($data->{data}{data}[0]{id})?$data->{data}{data}[0]{id}:"n.a.";
  2892. my $lfname = exists($data->{data}{data}[0]{fileName})?$data->{data}{data}[0]{fileName}:"n.a.";
  2893. my $lstime;
  2894. if(exists($data->{data}{data}[0]{createdTm})) {
  2895. $lstime = $data->{data}{data}[0]{createdTm};
  2896. my @t = split(" ", FmtDateTime($lstime));
  2897. my @d = split("-", $t[0]);
  2898. $lstime = "$d[2].$d[1].$d[0] / $t[1]";
  2899. } else {
  2900. $lstime = "n.a.";
  2901. }
  2902. Log3($name,4, "$name - Snap [0]: ID => $lsid, File => $lfname, Created => $lstime");
  2903. readingsBeginUpdate($hash);
  2904. readingsBulkUpdate($hash,"Errorcode","none");
  2905. readingsBulkUpdate($hash,"Error","none");
  2906. readingsBulkUpdate($hash,"LastSnapId",$lsid);
  2907. readingsBulkUpdate($hash,"LastSnapFilename", $lfname);
  2908. readingsBulkUpdate($hash,"LastSnapTime", $lstime);
  2909. readingsEndUpdate($hash, 1);
  2910. # Schnapschuss soll als liveView angezeigt werden (mindestens 1 Bild vorhanden)
  2911. Log3($name, 3, "$name - There is no snapshot of camera $camname to display ! Take one snapshot before.")
  2912. if(exists($hash->{HELPER}{RUNVIEW}) && $hash->{HELPER}{RUNVIEW} =~ /snap/ && !exists($data->{'data'}{'data'}[0]{imageData}));
  2913. if (exists($hash->{HELPER}{RUNVIEW}) && $hash->{HELPER}{RUNVIEW} =~ /snap/ && exists($data->{'data'}{'data'}[0]{imageData})) {
  2914. delete $hash->{HELPER}{RUNVIEW};
  2915. # Aufnahmestatus in state abbilden
  2916. my $st;
  2917. (ReadingsVal("$name", "Record", "") eq "Start")?$st="on":$st="off";
  2918. readingsSingleUpdate($hash,"state", $st, 1);
  2919. $hash->{HELPER}{LINK} = $data->{data}{data}[0]{imageData};
  2920. # Longpoll refresh
  2921. DoTrigger($name,"startview");
  2922. }
  2923. if($OpMode eq "getsnapgallery") {
  2924. # es soll eine Schnappschußgallerie bereitgestellt (Attr snapGalleryBoost=1) bzw. gleich angezeigt werden (Attr snapGalleryBoost=0)
  2925. my $i = 0;
  2926. my $sn = 0;
  2927. my %allsnaps = (); # Schnappschuss Hash wird leer erstellt
  2928. $hash->{HELPER}{TOTALCNT} = $data->{data}{total}; # total Anzahl Schnappschüsse
  2929. while ($data->{'data'}{'data'}[$i]) {
  2930. if($data->{'data'}{'data'}[$i]{'camName'} ne $camname) {
  2931. $i += 1;
  2932. next;
  2933. }
  2934. $snapid = $data->{data}{data}[$i]{id};
  2935. my $createdTm = $data->{data}{data}[$i]{createdTm};
  2936. my $fileName = $data->{data}{data}[$i]{fileName};
  2937. my $imageData = $data->{data}{data}[$i]{imageData}; # Image data of snapshot in base64 format
  2938. $allsnaps{$sn}{snapid} = $snapid;
  2939. my @t = split(" ", FmtDateTime($createdTm));
  2940. my @d = split("-", $t[0]);
  2941. $createdTm = "$d[2].$d[1].$d[0] / $t[1]";
  2942. $allsnaps{$sn}{createdTm} = $createdTm;
  2943. $allsnaps{$sn}{fileName} = $fileName;
  2944. $allsnaps{$sn}{imageData} = $imageData;
  2945. Log3($name,4, "$name - Snap '$sn' added to gallery hash: ID => $allsnaps{$sn}{snapid}, File => $allsnaps{$sn}{fileName}, Created => $allsnaps{$sn}{createdTm}");
  2946. $sn += 1;
  2947. $i += 1;
  2948. }
  2949. # Hash der Schnapschüsse erstellen
  2950. $hash->{HELPER}{".SNAPHASH"} = \%allsnaps;
  2951. # Direktausgabe Snaphash wenn nicht gepollt wird
  2952. if(!AttrVal($name, "snapGalleryBoost",0)) {
  2953. my $htmlCode = composegallery($name);
  2954. for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) {
  2955. asyncOutput($hash->{HELPER}{CL}{$k},"$htmlCode");
  2956. }
  2957. delete($hash->{HELPER}{".SNAPHASH"}); # Snaphash löschen wenn nicht gepollt wird
  2958. delete($hash->{HELPER}{CL});
  2959. }
  2960. delete($hash->{HELPER}{GETSNAPGALLERY}); # Steuerbit getsnapgallery statt getsnapinfo
  2961. }
  2962. Log3($name, $verbose, "$name - Snapinfos of camera $camname retrieved");
  2963. } elsif ($OpMode eq "getsnapfilename") {
  2964. # den Filenamen eines Schnapschusses ermitteln
  2965. $snapid = ReadingsVal("$name", "LastSnapId", " ");
  2966. readingsBeginUpdate($hash);
  2967. readingsBulkUpdate($hash,"Errorcode","none");
  2968. readingsBulkUpdate($hash,"Error","none");
  2969. readingsBulkUpdate($hash,"LastSnapFilename", $data->{'data'}{'data'}[0]{'fileName'});
  2970. readingsEndUpdate($hash, 1);
  2971. # Logausgabe
  2972. Log3($name, 4, "$name - Filename of Snap-ID $snapid is \"$data->{'data'}{'data'}[0]{'fileName'}\"") if($data->{'data'}{'data'}[0]{'fileName'});
  2973. } elsif ($OpMode eq "gopreset") {
  2974. # eine Presetposition wurde angefahren
  2975. # falls Aufnahme noch läuft -> state = on setzen
  2976. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2977. readingsSingleUpdate($hash,"state", "on", 0);
  2978. } else {
  2979. readingsSingleUpdate($hash,"state", "off", 0);
  2980. }
  2981. readingsBeginUpdate($hash);
  2982. readingsBulkUpdate($hash,"Errorcode","none");
  2983. readingsBulkUpdate($hash,"Error","none");
  2984. readingsEndUpdate($hash, 1);
  2985. # Logausgabe
  2986. Log3($name, 3, "$name - Camera $camname has been moved to position \"$hash->{HELPER}{GOPRESETNAME}\"");
  2987. } elsif ($OpMode eq "runpatrol") {
  2988. # eine Tour wurde gestartet
  2989. # falls Aufnahme noch läuft -> state = on setzen
  2990. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2991. readingsSingleUpdate($hash,"state", "on", 0);
  2992. } else {
  2993. readingsSingleUpdate($hash,"state", "off", 0);
  2994. }
  2995. readingsBeginUpdate($hash);
  2996. readingsBulkUpdate($hash,"Errorcode","none");
  2997. readingsBulkUpdate($hash,"Error","none");
  2998. readingsEndUpdate($hash, 1);
  2999. # Logausgabe
  3000. Log3($name, 3, "$name - Patrol \"$hash->{HELPER}{GOPATROLNAME}\" of camera $camname has been started successfully");
  3001. } elsif ($OpMode eq "goabsptz") {
  3002. # eine absolute PTZ-Position wurde angefahren
  3003. # falls Aufnahme noch läuft -> state = on setzen
  3004. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  3005. readingsSingleUpdate($hash,"state", "on", 0);
  3006. } else {
  3007. readingsSingleUpdate($hash,"state", "off", 0);
  3008. }
  3009. readingsBeginUpdate($hash);
  3010. readingsBulkUpdate($hash,"Errorcode","none");
  3011. readingsBulkUpdate($hash,"Error","none");
  3012. readingsEndUpdate($hash, 1);
  3013. # Logausgabe
  3014. Log3($name, 3, "$name - Camera $camname has been moved to absolute position \"posX=$hash->{HELPER}{GOPTZPOSX}\" and \"posY=$hash->{HELPER}{GOPTZPOSY}\"");
  3015. } elsif ($OpMode eq "movestart") {
  3016. # ein "Move" in eine bestimmte Richtung wird durchgeführt
  3017. readingsBeginUpdate($hash);
  3018. readingsBulkUpdate($hash,"state","moving");
  3019. readingsBulkUpdate($hash,"Errorcode","none");
  3020. readingsBulkUpdate($hash,"Error","none");
  3021. readingsEndUpdate($hash, 1);
  3022. # Logausgabe
  3023. Log3($name, 3, "$name - Camera $camname started move to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s");
  3024. RemoveInternalTimer($hash, "movestop");
  3025. InternalTimer(gettimeofday()+($hash->{HELPER}{GOMOVETIME}), "movestop", $hash);
  3026. } elsif ($OpMode eq "movestop") {
  3027. # ein "Move" in eine bestimmte Richtung wurde durchgeführt
  3028. # falls Aufnahme noch läuft -> state = on setzen
  3029. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  3030. readingsSingleUpdate($hash,"state", "on", 0);
  3031. } else {
  3032. readingsSingleUpdate($hash,"state", "off", 0);
  3033. }
  3034. readingsBeginUpdate($hash);
  3035. readingsBulkUpdate($hash,"Errorcode","none");
  3036. readingsBulkUpdate($hash,"Error","none");
  3037. readingsEndUpdate($hash, 1);
  3038. # Logausgabe
  3039. Log3($name, 3, "$name - Camera $camname stopped move to direction \"$hash->{HELPER}{GOMOVEDIR}\"");
  3040. } elsif ($OpMode eq "Enable") {
  3041. # Kamera wurde aktiviert, sonst kann nichts laufen -> "off"
  3042. readingsBeginUpdate($hash);
  3043. readingsBulkUpdate($hash,"Availability","enabled");
  3044. readingsBulkUpdate($hash,"state","off");
  3045. readingsBulkUpdate($hash,"Errorcode","none");
  3046. readingsBulkUpdate($hash,"Error","none");
  3047. readingsEndUpdate($hash, 1);
  3048. # Logausgabe
  3049. Log3($name, 3, "$name - Camera $camname has been enabled successfully");
  3050. } elsif ($OpMode eq "Disable") {
  3051. # Kamera wurde deaktiviert
  3052. readingsBeginUpdate($hash);
  3053. readingsBulkUpdate($hash,"Availability","disabled");
  3054. readingsBulkUpdate($hash,"state","disabled");
  3055. readingsBulkUpdate($hash,"Errorcode","none");
  3056. readingsBulkUpdate($hash,"Error","none");
  3057. readingsEndUpdate($hash, 1);
  3058. # Logausgabe
  3059. Log3($name, 3, "$name - Camera $camname has been disabled successfully");
  3060. } elsif ($OpMode eq "getsvsinfo") {
  3061. # Parse SVS-Infos
  3062. $userPriv = $data->{'data'}{'userPriv'};
  3063. if (defined($userPriv)) {
  3064. if ($userPriv eq "0") {
  3065. $userPriv = "No Access";
  3066. } elsif ($userPriv eq "1") {
  3067. $userPriv = "Admin";
  3068. } elsif ($userPriv eq "2") {
  3069. $userPriv = "Manager";
  3070. } elsif ($userPriv eq "4") {
  3071. $userPriv = "Viewer";
  3072. }
  3073. }
  3074. # "my" nicht am Anfang deklarieren, sonst wird Hash %version wieder geleert !
  3075. my %version = (
  3076. MAJOR => $data->{'data'}{'version'}{'major'},
  3077. MINOR => $data->{'data'}{'version'}{'minor'},
  3078. SMALL => $data->{'data'}{'version'}{'small'},
  3079. BUILD => $data->{'data'}{'version'}{'build'}
  3080. );
  3081. # Werte in $hash zur späteren Auswertung einfügen
  3082. $hash->{HELPER}{SVSVERSION} = \%version;
  3083. my $major = $version{"MAJOR"};
  3084. my $minor = $version{"MINOR"};
  3085. my $small = $version{"SMALL"};
  3086. my $build = $version{"BUILD"};
  3087. # simulieren einer anderen SVS-Version
  3088. if (AttrVal($name, "simu_SVSversion", undef)) {
  3089. Log3($name, 4, "$name - another SVS-version ".AttrVal($name, "simu_SVSversion", undef)." will be simulated");
  3090. #delete $version{"SMALL"} if ($version{"SMALL"});
  3091. my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", ""));
  3092. $major = $vl[0];
  3093. $minor = $vl[1];
  3094. $small = ($vl[2] =~ /\d/)?$vl[2]:undef;
  3095. $build = "xxxx-simu";
  3096. }
  3097. if (!exists($data->{'data'}{'customizedPortHttp'})) {
  3098. delete $defs{$name}{READINGS}{SVScustomPortHttp};
  3099. }
  3100. if (!exists($data->{'data'}{'customizedPortHttps'})) {
  3101. delete $defs{$name}{READINGS}{SVScustomPortHttps};
  3102. }
  3103. # Setreading
  3104. readingsBeginUpdate($hash);
  3105. readingsBulkUpdate($hash,"SVScustomPortHttp",$data->{'data'}{'customizedPortHttp'});
  3106. readingsBulkUpdate($hash,"SVScustomPortHttps",$data->{'data'}{'customizedPortHttps'});
  3107. readingsBulkUpdate($hash,"SVSlicenseNumber",$data->{'data'}{'liscenseNumber'});
  3108. readingsBulkUpdate($hash,"SVSuserPriv",$userPriv);
  3109. if(defined($small)) {
  3110. readingsBulkUpdate($hash,"SVSversion",$major.".".$minor.".".$small."-".$build);
  3111. } else {
  3112. readingsBulkUpdate($hash,"SVSversion",$major.".".$minor."-".$build);
  3113. }
  3114. readingsBulkUpdate($hash,"Errorcode","none");
  3115. readingsBulkUpdate($hash,"Error","none");
  3116. readingsEndUpdate($hash, 1);
  3117. Log3($name, $verbose, "$name - Informations related to Surveillance Station retrieved");
  3118. } elsif ($OpMode eq "getStmUrlPath") {
  3119. # Parse SVS-Infos
  3120. my($camforcemcast,$mjpegHttp,$multicst,$mxpegHttp,$unicastOverHttp,$unicastPath);
  3121. if($apicammaxver < 9) {
  3122. $camforcemcast = $data->{'data'}{'pathInfos'}[0]{'forceEnableMulticast'};
  3123. $mjpegHttp = $data->{'data'}{'pathInfos'}[0]{'mjpegHttpPath'};
  3124. $multicst = $data->{'data'}{'pathInfos'}[0]{'multicstPath'};
  3125. $mxpegHttp = $data->{'data'}{'pathInfos'}[0]{'mxpegHttpPath'};
  3126. $unicastOverHttp = $data->{'data'}{'pathInfos'}[0]{'unicastOverHttpPath'};
  3127. $unicastPath = $data->{'data'}{'pathInfos'}[0]{'unicastPath'};
  3128. }
  3129. if($apicammaxver >= 9) {
  3130. $mjpegHttp = $data->{'data'}[0]{'mjpegHttpPath'};
  3131. $multicst = $data->{'data'}[0]{'multicstPath'};
  3132. $mxpegHttp = $data->{'data'}[0]{'mxpegHttpPath'};
  3133. $unicastOverHttp = $data->{'data'}[0]{'rtspOverHttpPath'};
  3134. $unicastPath = $data->{'data'}[0]{'rtspPath'};
  3135. }
  3136. # Rewrite Url's falls livestreamprefix ist gesetzt
  3137. if (AttrVal($name, "livestreamprefix", undef)) {
  3138. my @mjh = split(/\//, $mjpegHttp, 4);
  3139. $mjpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mjh[3];
  3140. my @mxh = split(/\//, $mxpegHttp, 4);
  3141. $mxpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mxh[3];
  3142. if($unicastPath) {
  3143. my @ucp = split(/[@\|:]/, $unicastPath);
  3144. my @lspf = split(/[\/\/\|:]/, AttrVal($name, "livestreamprefix", undef));
  3145. $unicastPath = $ucp[0].":".$ucp[1].":".$ucp[2]."@".$lspf[3].":".$ucp[4];
  3146. }
  3147. }
  3148. # StmKey extrahieren
  3149. my @sk = split(/&StmKey=/, $mjpegHttp);
  3150. my $stmkey = $sk[1];
  3151. $stmkey =~ tr/"//d;
  3152. # Quotes in StmKey entfernen falls noQuotesForSID gesezt
  3153. $mjpegHttp =~ tr/"//d if(AttrVal($name, "noQuotesForSID",0));
  3154. # Readings löschen falls sie nicht angezeigt werden sollen (showStmInfoFull)
  3155. if (!AttrVal($name,"showStmInfoFull",0)) {
  3156. delete($defs{$name}{READINGS}{StmKeymjpegHttp});
  3157. delete($defs{$name}{READINGS}{StmKeyUnicst});
  3158. delete($defs{$name}{READINGS}{StmKeyUnicstOverHttp});
  3159. }
  3160. readingsBeginUpdate($hash);
  3161. readingsBulkUpdate($hash,"CamForceEnableMulticast",$camforcemcast) if($camforcemcast);
  3162. readingsBulkUpdate($hash,"StmKey",$stmkey);
  3163. readingsBulkUpdate($hash,"StmKeymjpegHttp",$mjpegHttp) if(AttrVal($name,"showStmInfoFull",0));
  3164. # readingsBulkUpdate($hash,"StmKeymxpegHttp",$mxpegHttp);
  3165. readingsBulkUpdate($hash,"StmKeyUnicstOverHttp",$unicastOverHttp) if(AttrVal($name,"showStmInfoFull",0) && $unicastOverHttp);
  3166. readingsBulkUpdate($hash,"StmKeyUnicst",$unicastPath) if(AttrVal($name,"showStmInfoFull",0) && $unicastPath);
  3167. readingsBulkUpdate($hash,"Errorcode","none");
  3168. readingsBulkUpdate($hash,"Error","none");
  3169. readingsEndUpdate($hash, 1);
  3170. # Logausgabe
  3171. Log3($name, $verbose, "$name - Stream-URLs of camera $camname retrieved");
  3172. } elsif ($OpMode eq "Getcaminfo") {
  3173. # Parse Caminfos
  3174. $camLiveMode = $data->{'data'}->{'cameras'}->[0]->{'camLiveMode'};
  3175. if ($camLiveMode eq "0") {$camLiveMode = "Liveview from DS";}elsif ($camLiveMode eq "1") {$camLiveMode = "Liveview from Camera";}
  3176. # $update_time = $data->{'data'}->{'cameras'}->[0]->{'update_time'};
  3177. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  3178. $update_time = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ;
  3179. $deviceType = $data->{'data'}->{'cameras'}->[0]->{'deviceType'};
  3180. if ($deviceType eq "1") {
  3181. $deviceType = "Camera";
  3182. } elsif ($deviceType eq "2") {
  3183. $deviceType = "Video_Server";
  3184. } elsif ($deviceType eq "4") {
  3185. $deviceType = "PTZ";
  3186. } elsif ($deviceType eq "8") {
  3187. $deviceType = "Fisheye";
  3188. }
  3189. $camStatus = $data->{'data'}->{'cameras'}->[0]->{'camStatus'};
  3190. if ($camStatus eq "1") {
  3191. $camStatus = "enabled";
  3192. # falls Aufnahme noch läuft -> STATE = on setzen
  3193. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  3194. readingsSingleUpdate($hash,"state", "on", 0);
  3195. } else {
  3196. readingsSingleUpdate($hash,"state", "off", 0);
  3197. }
  3198. } elsif ($camStatus eq "3") {
  3199. $camStatus = "disconnected";
  3200. readingsSingleUpdate($hash,"state", "disconnected", 0);
  3201. } elsif ($camStatus eq "7") {
  3202. $camStatus = "disabled";
  3203. readingsSingleUpdate($hash,"state", "disabled", 0);
  3204. } else {
  3205. $camStatus = "other";
  3206. }
  3207. $recStatus = $data->{'data'}->{'cameras'}->[0]->{'recStatus'};
  3208. if ($recStatus ne "0") {
  3209. $recStatus = "Start";
  3210. } else {
  3211. $recStatus = "Stop";
  3212. }
  3213. my $rotate = $data->{'data'}->{'cameras'}->[0]->{'video_rotation'};
  3214. $rotate = $rotate == 1?"true":"false";
  3215. $exposuremode = $data->{'data'}->{'cameras'}->[0]->{'exposure_mode'};
  3216. if ($exposuremode == 0) {
  3217. $exposuremode = "Auto";
  3218. }
  3219. elsif ($exposuremode == 1) {
  3220. $exposuremode = "Day";
  3221. }
  3222. elsif ($exposuremode == 2) {
  3223. $exposuremode = "Night";
  3224. }
  3225. elsif ($exposuremode == 3) {
  3226. $exposuremode = "Schedule";
  3227. }
  3228. elsif ($exposuremode == 4) {
  3229. $exposuremode = "Unknown";
  3230. }
  3231. $exposurecontrol = $data->{'data'}->{'cameras'}->[0]->{'exposure_control'};
  3232. if ($exposurecontrol == 0) {
  3233. $exposurecontrol = "Auto";
  3234. }
  3235. elsif ($exposurecontrol == 1) {
  3236. $exposurecontrol = "50HZ";
  3237. }
  3238. elsif ($exposurecontrol == 2) {
  3239. $exposurecontrol = "60HZ";
  3240. }
  3241. elsif ($exposurecontrol == 3) {
  3242. $exposurecontrol = "Hold";
  3243. }
  3244. elsif ($exposurecontrol == 4) {
  3245. $exposurecontrol = "Outdoor";
  3246. }
  3247. elsif ($exposurecontrol == 5) {
  3248. $exposurecontrol = "None";
  3249. }
  3250. elsif ($exposurecontrol == 6) {
  3251. $exposurecontrol = "Unknown";
  3252. }
  3253. # Setreading
  3254. readingsBeginUpdate($hash);
  3255. readingsBulkUpdate($hash,"CamLiveMode",$camLiveMode);
  3256. readingsBulkUpdate($hash,"CamExposureMode",$exposuremode);
  3257. readingsBulkUpdate($hash,"CamExposureControl",$exposurecontrol);
  3258. readingsBulkUpdate($hash,"CamModel",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camModel'});
  3259. readingsBulkUpdate($hash,"CamRecShare",$data->{'data'}->{'cameras'}->[0]->{'camRecShare'});
  3260. readingsBulkUpdate($hash,"CamRecVolume",$data->{'data'}->{'cameras'}->[0]->{'camRecVolume'});
  3261. readingsBulkUpdate($hash,"CamIP",$data->{'data'}->{'cameras'}->[0]->{'host'});
  3262. readingsBulkUpdate($hash,"CamNTPServer",$data->{'data'}->{'cameras'}->[0]->{'time_server'}) if($data->{'data'}->{'cameras'}->[0]->{'time_server'});
  3263. readingsBulkUpdate($hash,"CamVendor",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'});
  3264. readingsBulkUpdate($hash,"CamPreRecTime",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'});
  3265. readingsBulkUpdate($hash,"CamPort",$data->{'data'}->{'cameras'}->[0]->{'port'});
  3266. readingsBulkUpdate($hash,"CamPtSpeed",$data->{'data'}->{'cameras'}->[0]->{'ptSpeed'});
  3267. readingsBulkUpdate($hash,"CamblPresetSpeed",$data->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'});
  3268. readingsBulkUpdate($hash,"CamVideoMirror",$data->{'data'}->{'cameras'}->[0]->{'video_mirror'});
  3269. readingsBulkUpdate($hash,"CamVideoFlip",$data->{'data'}->{'cameras'}->[0]->{'video_flip'});
  3270. readingsBulkUpdate($hash,"CamVideoRotate",$rotate);
  3271. readingsBulkUpdate($hash,"Availability",$camStatus);
  3272. readingsBulkUpdate($hash,"DeviceType",$deviceType);
  3273. readingsBulkUpdate($hash,"LastUpdateTime",$update_time);
  3274. readingsBulkUpdate($hash,"Record",$recStatus);
  3275. readingsBulkUpdate($hash,"UsedSpaceMB",$data->{'data'}->{'cameras'}->[0]->{'volume_space'});
  3276. readingsBulkUpdate($hash,"VideoFolder",AttrVal($name, "videofolderMap", undef) ? AttrVal($name, "videofolderMap", undef) : $data->{'data'}->{'cameras'}->[0]->{'folder'});
  3277. readingsBulkUpdate($hash,"Errorcode","none");
  3278. readingsBulkUpdate($hash,"Error","none");
  3279. readingsEndUpdate($hash, 1);
  3280. # Logausgabe
  3281. Log3($name, $verbose, "$name - Informations of camera $camname retrieved");
  3282. } elsif ($OpMode eq "geteventlist") {
  3283. my $eventnum = $data->{'data'}{'total'};
  3284. my $lastrecord = $data->{'data'}{'events'}[0]{name};
  3285. $hash->{HELPER}{CAMLASTRECID} = $data->{'data'}{'events'}[0]{'eventId'};
  3286. my ($lastrecstarttime,$lastrecstoptime);
  3287. if ($eventnum > 0) {
  3288. $lastrecstarttime = $data->{'data'}{'events'}[0]{startTime};
  3289. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstarttime);
  3290. $lastrecstarttime = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ;
  3291. $lastrecstoptime = $data->{'data'}{'events'}[0]{stopTime};
  3292. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstoptime);
  3293. $lastrecstoptime = sprintf "%02d:%02d:%02d" , $hour , $min , $sec ;
  3294. }
  3295. # Setreading
  3296. readingsBeginUpdate($hash);
  3297. readingsBulkUpdate($hash,"CamEventNum",$eventnum);
  3298. readingsBulkUpdate($hash,"CamLastRec",$lastrecord);
  3299. if ($lastrecstarttime) {readingsBulkUpdate($hash,"CamLastRecTime",$lastrecstarttime." - ". $lastrecstoptime);}
  3300. readingsBulkUpdate($hash,"Errorcode","none");
  3301. readingsBulkUpdate($hash,"Error","none");
  3302. readingsEndUpdate($hash, 1);
  3303. # Logausgabe
  3304. Log3($name, $verbose, "$name - Query eventlist of camera $camname retrieved");
  3305. } elsif ($OpMode eq "getmotionenum") {
  3306. $motdetsc = $data->{'data'}{'MDParam'}{'source'};
  3307. $sensitivity_camCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'camCap'};
  3308. $sensitivity_value = $data->{'data'}{'MDParam'}{'sensitivity'}{'value'};
  3309. $sensitivity_ssCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'ssCap'};
  3310. $threshold_camCap = $data->{'data'}{'MDParam'}{'threshold'}{'camCap'};
  3311. $threshold_value = $data->{'data'}{'MDParam'}{'threshold'}{'value'};
  3312. $threshold_ssCap = $data->{'data'}{'MDParam'}{'threshold'}{'ssCap'};
  3313. $percentage_camCap = $data->{'data'}{'MDParam'}{'percentage'}{'camCap'};
  3314. $percentage_value = $data->{'data'}{'MDParam'}{'percentage'}{'value'};
  3315. $percentage_ssCap = $data->{'data'}{'MDParam'}{'percentage'}{'ssCap'};
  3316. $objectSize_camCap = $data->{'data'}{'MDParam'}{'objectSize'}{'camCap'};
  3317. $objectSize_value = $data->{'data'}{'MDParam'}{'objectSize'}{'value'};
  3318. $objectSize_ssCap = $data->{'data'}{'MDParam'}{'objectSize'}{'ssCap'};
  3319. if ($motdetsc == -1) {
  3320. $motdetsc = "disabled";
  3321. }
  3322. elsif ($motdetsc == 0) {
  3323. $motdetsc = "Camera";
  3324. if ($sensitivity_camCap) {
  3325. $motdetsc .= ", sensitivity: $sensitivity_value";
  3326. }
  3327. if ($threshold_camCap) {
  3328. $motdetsc .= ", threshold: $threshold_value";
  3329. }
  3330. if ($percentage_camCap) {
  3331. $motdetsc .= ", percentage: $percentage_value";
  3332. }
  3333. if ($objectSize_camCap) {
  3334. $motdetsc .= ", objectSize: $objectSize_value";
  3335. }
  3336. }
  3337. elsif ($motdetsc == 1) {
  3338. $motdetsc = "SVS";
  3339. if ($sensitivity_ssCap) {
  3340. $motdetsc .= ", sensitivity: $sensitivity_value";
  3341. }
  3342. if ($threshold_ssCap) {
  3343. $motdetsc .= ", threshold: $threshold_value";
  3344. }
  3345. if ($percentage_ssCap) {
  3346. $motdetsc .= ", percentage: $percentage_value";
  3347. }
  3348. if ($objectSize_ssCap) {
  3349. $motdetsc .= ", objectSize: $objectSize_value";
  3350. }
  3351. }
  3352. # Setreading
  3353. readingsBeginUpdate($hash);
  3354. readingsBulkUpdate($hash,"CamMotDetSc",$motdetsc);
  3355. readingsBulkUpdate($hash,"Errorcode","none");
  3356. readingsBulkUpdate($hash,"Error","none");
  3357. readingsEndUpdate($hash, 1);
  3358. # Logausgabe
  3359. Log3($name, $verbose, "$name - Enumerate motion detection parameters of camera $camname retrieved");
  3360. } elsif ($OpMode eq "Getcapabilities") {
  3361. # Parse Infos
  3362. my $ptzfocus = $data->{'data'}{'ptzFocus'};
  3363. if ($ptzfocus eq "0") {
  3364. $ptzfocus = "false";
  3365. }
  3366. elsif ($ptzfocus eq "1") {
  3367. $ptzfocus = "support step operation";
  3368. }
  3369. elsif ($ptzfocus eq "2") {
  3370. $ptzfocus = "support continuous operation";
  3371. }
  3372. my $ptztilt = $data->{'data'}{'ptzTilt'};
  3373. if ($ptztilt eq "0") {
  3374. $ptztilt = "false";
  3375. }
  3376. elsif ($ptztilt eq "1") {
  3377. $ptztilt = "support step operation";
  3378. }
  3379. elsif ($ptztilt eq "2") {
  3380. $ptztilt = "support continuous operation";
  3381. }
  3382. my $ptzzoom = $data->{'data'}{'ptzZoom'};
  3383. if ($ptzzoom eq "0") {
  3384. $ptzzoom = "false";
  3385. }
  3386. elsif ($ptzzoom eq "1") {
  3387. $ptzzoom = "support step operation";
  3388. }
  3389. elsif ($ptzzoom eq "2") {
  3390. $ptzzoom = "support continuous operation";
  3391. }
  3392. my $ptzpan = $data->{'data'}{'ptzPan'};
  3393. if ($ptzpan eq "0") {
  3394. $ptzpan = "false";
  3395. }
  3396. elsif ($ptzpan eq "1") {
  3397. $ptzpan = "support step operation";
  3398. }
  3399. elsif ($ptzpan eq "2") {
  3400. $ptzpan = "support continuous operation";
  3401. }
  3402. my $ptziris = $data->{'data'}{'ptzIris'};
  3403. if ($ptziris eq "0") {
  3404. $ptziris = "false";
  3405. }
  3406. elsif ($ptziris eq "1") {
  3407. $ptziris = "support step operation";
  3408. }
  3409. elsif ($ptziris eq "2") {
  3410. $ptziris = "support continuous operation";
  3411. }
  3412. # Setreading
  3413. readingsBeginUpdate($hash);
  3414. readingsBulkUpdate($hash,"CapPTZAutoFocus",$data->{'data'}{'ptzAutoFocus'});
  3415. readingsBulkUpdate($hash,"CapAudioOut",$data->{'data'}{'audioOut'});
  3416. readingsBulkUpdate($hash,"CapChangeSpeed",$data->{'data'}{'ptzSpeed'});
  3417. readingsBulkUpdate($hash,"CapPTZHome",$data->{'data'}{'ptzHome'});
  3418. readingsBulkUpdate($hash,"CapPTZAbs",$data->{'data'}{'ptzAbs'});
  3419. readingsBulkUpdate($hash,"CapPTZDirections",$data->{'data'}{'ptzDirection'});
  3420. readingsBulkUpdate($hash,"CapPTZFocus",$ptzfocus);
  3421. readingsBulkUpdate($hash,"CapPTZIris",$ptziris);
  3422. readingsBulkUpdate($hash,"CapPTZPan",$ptzpan);
  3423. readingsBulkUpdate($hash,"CapPTZTilt",$ptztilt);
  3424. readingsBulkUpdate($hash,"CapPTZZoom",$ptzzoom);
  3425. readingsBulkUpdate($hash,"Errorcode","none");
  3426. readingsBulkUpdate($hash,"Error","none");
  3427. readingsEndUpdate($hash, 1);
  3428. # Logausgabe
  3429. Log3($name, $verbose, "$name - Capabilities of camera $camname retrieved");
  3430. } elsif ($OpMode eq "Getptzlistpreset") {
  3431. # Parse PTZ-ListPresets
  3432. my $presetcnt = $data->{'data'}->{'total'};
  3433. my $cnt = 0;
  3434. # alle Presets der Kamera mit Id's in Assoziatives Array einlesen
  3435. # "my" nicht am Anfang deklarieren, sonst wird Hash %allpresets wieder geleert !
  3436. my %allpresets;
  3437. while ($cnt < $presetcnt) {
  3438. # my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'id'};
  3439. my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'position'};
  3440. my $presname = $data->{'data'}->{'presets'}->[$cnt]->{'name'};
  3441. $allpresets{$presname} = "$presid";
  3442. $cnt += 1;
  3443. }
  3444. # Presethash in $hash einfügen
  3445. $hash->{HELPER}{ALLPRESETS} = \%allpresets;
  3446. my @preskeys = sort(keys(%allpresets));
  3447. my $presetlist = join(",",@preskeys);
  3448. # Setreading
  3449. readingsBeginUpdate($hash);
  3450. readingsBulkUpdate($hash,"Presets",$presetlist);
  3451. readingsBulkUpdate($hash,"Errorcode","none");
  3452. readingsBulkUpdate($hash,"Error","none");
  3453. readingsEndUpdate($hash, 1);
  3454. # Logausgabe
  3455. Log3($name, $verbose, "$name - PTZ Presets of camera $camname retrieved");
  3456. } elsif ($OpMode eq "Getptzlistpatrol") {
  3457. # Parse PTZ-ListPatrols
  3458. $patrolcnt = $data->{'data'}->{'total'};
  3459. my $cnt = 0;
  3460. # alle Patrols der Kamera mit Id's in Assoziatives Array einlesen
  3461. # "my" nicht am Anfang deklarieren, sonst wird Hash %allpatrols wieder geleert !
  3462. my %allpatrols = ();
  3463. while ($cnt < $patrolcnt) {
  3464. $patrolid = $data->{'data'}->{'patrols'}->[$cnt]->{'id'};
  3465. $patrolname = $data->{'data'}->{'patrols'}->[$cnt]->{'name'};
  3466. $allpatrols{$patrolname} = $patrolid;
  3467. $cnt += 1;
  3468. }
  3469. # Presethash in $hash einfügen
  3470. $hash->{HELPER}{ALLPATROLS} = \%allpatrols;
  3471. @patrolkeys = sort(keys(%allpatrols));
  3472. $patrollist = join(",",@patrolkeys);
  3473. # print "ID von Tour1 ist : ". %allpatrols->{Tour1};
  3474. # print "aus Hash: ".$hash->{HELPER}{ALLPRESETS}{Tour1};
  3475. readingsBeginUpdate($hash);
  3476. readingsBulkUpdate($hash,"Patrols",$patrollist);
  3477. readingsBulkUpdate($hash,"Errorcode","none");
  3478. readingsBulkUpdate($hash,"Error","none");
  3479. readingsEndUpdate($hash, 1);
  3480. # Logausgabe
  3481. Log3($name, $verbose, "$name - PTZ Patrols of camera $camname retrieved");
  3482. }
  3483. } else {
  3484. # die API-Operation war fehlerhaft
  3485. # Errorcode aus JSON ermitteln
  3486. $errorcode = $data->{'error'}->{'code'};
  3487. # Fehlertext zum Errorcode ermitteln
  3488. $error = SSCam_experror($hash,$errorcode);
  3489. # Setreading
  3490. readingsBeginUpdate($hash);
  3491. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  3492. readingsBulkUpdate($hash,"Error",$error);
  3493. readingsEndUpdate($hash, 1);
  3494. if ($errorcode =~ /(105|401)/) {
  3495. Log3($name, 2, "$name - ERROR - $errorcode - $error in operation $OpMode -> try new login");
  3496. return SSCam_login($hash,'SSCam_getapisites');
  3497. }
  3498. # Logausgabe
  3499. Log3($name, 2, "$name - ERROR - Operation $OpMode of Camera $camname was not successful. Errorcode: $errorcode - $error");
  3500. }
  3501. }
  3502. # Token freigeben
  3503. $hash->{HELPER}{ACTIVE} = "off";
  3504. if ($attr{$name}{debugactivetoken}) {
  3505. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3506. }
  3507. return;
  3508. }
  3509. #############################################################################################################################
  3510. ######### Ende Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) #############
  3511. #############################################################################################################################
  3512. #############################################################################################################################
  3513. ######### Hilfsroutinen #############
  3514. #############################################################################################################################
  3515. ####################################################################################
  3516. # Login in SVS wenn kein oder ungültige Session-ID vorhanden ist
  3517. sub SSCam_login ($$) {
  3518. my ($hash,$fret) = @_;
  3519. my $name = $hash->{NAME};
  3520. my $serveraddr = $hash->{SERVERADDR};
  3521. my $serverport = $hash->{SERVERPORT};
  3522. my $apiauth = $hash->{HELPER}{APIAUTH};
  3523. my $apiauthpath = $hash->{HELPER}{APIAUTHPATH};
  3524. my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER};
  3525. my $lrt = AttrVal($name,"loginRetries",3);
  3526. my ($url,$param);
  3527. delete $hash->{HELPER}{SID} if($hash->{HELPER}{SID});
  3528. # Login und SID ermitteln
  3529. Log3($name, 4, "$name - --- Begin Function SSCam_login ---");
  3530. # Credentials abrufen
  3531. my ($success, $username, $password) = SSCam_getcredentials($hash,0);
  3532. unless ($success) {
  3533. Log3($name, 2, "$name - Credentials couldn't be retrieved successfully - make sure you've set it with \"set $name credentials <username> <password>\"");
  3534. $hash->{HELPER}{ACTIVE} = "off";
  3535. if ($attr{$name}{debugactivetoken}) {
  3536. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3537. }
  3538. return;
  3539. }
  3540. if($hash->{HELPER}{LOGINRETRIES} >= $lrt) {
  3541. # login wird abgebrochen, Freigabe Funktionstoken
  3542. $hash->{HELPER}{ACTIVE} = "off";
  3543. if ($attr{$name}{debugactivetoken}) {
  3544. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3545. }
  3546. Log3($name, 2, "$name - ERROR - Login or privilege of user $username unsuccessful");
  3547. return;
  3548. }
  3549. my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  3550. Log3($name, 5, "$name - HTTP-Call login will be done with httptimeout-Value: $httptimeout s");
  3551. my $urlwopw; # nur zur Anzeige bei verbose >= 4 und "showPassInLog" == 0
  3552. # sid in Quotes einschliessen oder nicht -> bei Problemen mit 402 - Permission denied
  3553. my $sid = AttrVal($name, "noQuotesForSID", "0") == 1 ? "sid" : "\"sid\"";
  3554. if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") {
  3555. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&session=SurveillanceStation&format=$sid";
  3556. $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&session=SurveillanceStation&format=$sid";
  3557. } else {
  3558. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&format=$sid";
  3559. $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&format=$sid";
  3560. }
  3561. AttrVal($name, "showPassInLog", "0") == 1 ? Log3($name, 4, "$name - Call-Out now: $url") : Log3($name, 4, "$name - Call-Out now: $urlwopw");
  3562. $hash->{HELPER}{LOGINRETRIES}++;
  3563. $param = {
  3564. url => $url,
  3565. timeout => $httptimeout,
  3566. hash => $hash,
  3567. user => $username,
  3568. funcret => $fret,
  3569. method => "GET",
  3570. header => "Accept: application/json",
  3571. callback => \&SSCam_login_return
  3572. };
  3573. HttpUtils_NonblockingGet ($param);
  3574. }
  3575. sub SSCam_login_return ($) {
  3576. my ($param, $err, $myjson) = @_;
  3577. my $hash = $param->{hash};
  3578. my $name = $hash->{NAME};
  3579. my $username = $param->{user};
  3580. my $fret = $param->{funcret};
  3581. my $subref = \&$fret;
  3582. my $success;
  3583. # Verarbeitung der asynchronen Rückkehrdaten aus sub "login_nonbl"
  3584. if ($err ne "") {
  3585. # ein Fehler bei der HTTP Abfrage ist aufgetreten
  3586. Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err");
  3587. readingsSingleUpdate($hash, "Error", $err, 1);
  3588. return SSCam_login($hash,$fret);
  3589. } elsif ($myjson ne "") {
  3590. # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  3591. # Evaluiere ob Daten im JSON-Format empfangen wurden
  3592. ($hash, $success) = SSCam_evaljson($hash,$myjson,$param->{url});
  3593. unless ($success) {
  3594. Log3($name, 4, "$name - no JSON-Data returned: ".$myjson);
  3595. $hash->{HELPER}{ACTIVE} = "off";
  3596. if ($attr{$name}{debugactivetoken}) {
  3597. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3598. }
  3599. return;
  3600. }
  3601. my $data = decode_json($myjson);
  3602. # Logausgabe decodierte JSON Daten
  3603. Log3($name, 5, "$name - JSON decoded: ". Dumper $data);
  3604. $success = $data->{'success'};
  3605. if ($success) {
  3606. # login war erfolgreich
  3607. my $sid = $data->{'data'}->{'sid'};
  3608. # Session ID in hash eintragen
  3609. $hash->{HELPER}{SID} = $sid;
  3610. # Setreading
  3611. readingsBeginUpdate($hash);
  3612. readingsBulkUpdate($hash,"Errorcode","none");
  3613. readingsBulkUpdate($hash,"Error","none");
  3614. readingsEndUpdate($hash, 1);
  3615. # Logausgabe
  3616. Log3($name, 4, "$name - Login of User $username successful - SID: $sid");
  3617. return &$subref($hash);
  3618. } else {
  3619. # Errorcode aus JSON ermitteln
  3620. my $errorcode = $data->{'error'}->{'code'};
  3621. # Fehlertext zum Errorcode ermitteln
  3622. my $error = SSCam_experrorauth($hash,$errorcode);
  3623. # Setreading
  3624. readingsBeginUpdate($hash);
  3625. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  3626. readingsBulkUpdate($hash,"Error",$error);
  3627. readingsEndUpdate($hash, 1);
  3628. # Logausgabe
  3629. Log3($name, 3, "$name - Login of User $username unsuccessful. Code: $errorcode - $error - try again");
  3630. return SSCam_login($hash,$fret);
  3631. }
  3632. }
  3633. return SSCam_login($hash,$fret);
  3634. }
  3635. ###################################################################################
  3636. # Funktion logout
  3637. sub SSCam_logout ($) {
  3638. my ($hash) = @_;
  3639. my $name = $hash->{NAME};
  3640. my $serveraddr = $hash->{SERVERADDR};
  3641. my $serverport = $hash->{SERVERPORT};
  3642. my $apiauth = $hash->{HELPER}{APIAUTH};
  3643. my $apiauthpath = $hash->{HELPER}{APIAUTHPATH};
  3644. my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER};
  3645. my $sid = $hash->{HELPER}{SID};
  3646. my $url;
  3647. my $param;
  3648. my $httptimeout;
  3649. Log3($name, 4, "$name - ####################################################");
  3650. Log3($name, 4, "$name - ### start cam operation $hash->{OPMODE} ");
  3651. Log3($name, 4, "$name - ####################################################");
  3652. Log3($name, 4, "$name - --- Begin Function SSCam_logout nonblocking ---");
  3653. $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  3654. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  3655. if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") {
  3656. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&session=SurveillanceStation&_sid=$sid";
  3657. } else {
  3658. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&_sid=$sid";
  3659. }
  3660. $param = {
  3661. url => $url,
  3662. timeout => $httptimeout,
  3663. hash => $hash,
  3664. method => "GET",
  3665. header => "Accept: application/json",
  3666. callback => \&SSCam_logout_return
  3667. };
  3668. HttpUtils_NonblockingGet ($param);
  3669. }
  3670. sub SSCam_logout_return ($) {
  3671. my ($param, $err, $myjson) = @_;
  3672. my $hash = $param->{hash};
  3673. my $name = $hash->{NAME};
  3674. my $sid = $hash->{HELPER}{SID};
  3675. my ($success, $username) = SSCam_getcredentials($hash,0);
  3676. my $OpMode = $hash->{OPMODE};
  3677. my $data;
  3678. my $error;
  3679. my $errorcode;
  3680. if($err ne "") {
  3681. # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  3682. Log3($name, 2, "$name - error while requesting ".$param->{url}." - $err");
  3683. readingsSingleUpdate($hash, "Error", $err, 1);
  3684. } elsif($myjson ne "") {
  3685. # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  3686. Log3($name, 4, "$name - URL-Call: ".$param->{url});
  3687. # Evaluiere ob Daten im JSON-Format empfangen wurden
  3688. ($hash, $success) = &SSCam_evaljson($hash,$myjson,$param->{url});
  3689. unless ($success) {
  3690. Log3($name, 4, "$name - Data returned: ".$myjson);
  3691. $hash->{HELPER}{ACTIVE} = "off";
  3692. if ($attr{$name}{debugactivetoken}) {
  3693. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3694. }
  3695. return;
  3696. }
  3697. $data = decode_json($myjson);
  3698. # Logausgabe decodierte JSON Daten
  3699. Log3($name, 4, "$name - JSON returned: ". Dumper $data);
  3700. $success = $data->{'success'};
  3701. if ($success) {
  3702. # die Logout-URL konnte erfolgreich aufgerufen werden
  3703. Log3($name, 4, "$name - Session of User $username has ended - SID: \"$sid\" has been deleted");
  3704. } else {
  3705. # Errorcode aus JSON ermitteln
  3706. $errorcode = $data->{'error'}->{'code'};
  3707. # Fehlertext zum Errorcode ermitteln
  3708. $error = &SSCam_experrorauth($hash,$errorcode);
  3709. Log3($name, 2, "$name - ERROR - Logout of User $username was not successful, however SID: \"$sid\" has been deleted. Errorcode: $errorcode - $error");
  3710. }
  3711. }
  3712. # Session-ID aus Helper-hash löschen
  3713. delete $hash->{HELPER}{SID};
  3714. # ausgeführte Funktion ist erledigt (auch wenn logout nicht erfolgreich), Freigabe Funktionstoken
  3715. $hash->{HELPER}{ACTIVE} = "off";
  3716. if ($attr{$name}{debugactivetoken}) {
  3717. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3718. }
  3719. return;
  3720. }
  3721. ###############################################################################
  3722. # Test ob JSON-String empfangen wurde
  3723. sub SSCam_evaljson {
  3724. my ($hash,$myjson,$url)= @_;
  3725. my $success = 1;
  3726. my $e;
  3727. eval {decode_json($myjson)} or do
  3728. {
  3729. $success = 0;
  3730. $e = $@;
  3731. # Setreading
  3732. readingsBeginUpdate($hash);
  3733. readingsBulkUpdate($hash,"Errorcode","none");
  3734. readingsBulkUpdate($hash,"Error","malformed JSON string received");
  3735. readingsEndUpdate($hash, 1);
  3736. };
  3737. return($hash,$success);
  3738. }
  3739. ###############################################################################
  3740. # Test ob MODEL=CAM (sonst ist es SVS)
  3741. sub SSCam_IsModelCam($){
  3742. my ($hash)= @_;
  3743. my $m = ($hash->{MODEL} eq "CAM")?1:0;
  3744. return($m);
  3745. }
  3746. ###############################################################################
  3747. # Schnappschußgalerie abrufen (snapGalleryBoost) oder nur Info des letzten Snaps
  3748. sub SSCam_snaplimsize ($) {
  3749. my ($hash)= @_;
  3750. my $name = $hash->{NAME};
  3751. my ($slim,$ssize);
  3752. if(!AttrVal($name,"snapGalleryBoost",0)) {
  3753. $slim = 1;
  3754. $ssize = 0;
  3755. } else {
  3756. $hash->{HELPER}{GETSNAPGALLERY} = 1;
  3757. $slim = AttrVal($name,"snapGalleryNumber",$SSCam_slim); # Anzahl der abzurufenden Snaps
  3758. my $sg = AttrVal($name,"snapGallerySize","Icon"); # Auflösung Image
  3759. $ssize = ($sg eq "Icon")?1:2;
  3760. }
  3761. return ($slim,$ssize);
  3762. }
  3763. ###############################################################################
  3764. # Helper für listLog-Argumente extrahieren
  3765. ###############################################################################
  3766. sub SSCam_extlogargs ($$) {
  3767. my ($hash,$a) = @_;
  3768. $hash->{HELPER}{LISTLOGSEVERITY} = (split("severity:",$a))[1] if(lc($a) =~ m/^severity:.*/);
  3769. $hash->{HELPER}{LISTLOGLIMIT} = (split("limit:",$a))[1] if(lc($a) =~ m/^limit:.*/);
  3770. $hash->{HELPER}{LISTLOGMATCH} = (split("match:",$a))[1] if(lc($a) =~ m/^match:.*/);
  3771. return;
  3772. }
  3773. ###############################################################################
  3774. # Helper für optimizeParams-Argumente extrahieren
  3775. ###############################################################################
  3776. sub SSCam_extoptpar ($$$) {
  3777. my ($hash,$a,$cpcl) = @_;
  3778. $hash->{HELPER}{MIRROR} = (split("mirror:",$a))[1] if(lc($a) =~ m/^mirror:.*/);
  3779. $hash->{HELPER}{FLIP} = (split("flip:",$a))[1] if(lc($a) =~ m/^flip:.*/);
  3780. $hash->{HELPER}{ROTATE} = (split("rotate:",$a))[1] if(lc($a) =~ m/^rotate:.*/);
  3781. $hash->{HELPER}{NTPSERV} = (split("ntp:",$a))[1] if(lc($a) =~ m/^ntp:.*/);
  3782. $hash->{HELPER}{CHKLIST} = ($hash->{HELPER}{NTPSERV}?$cpcl->{ntp}:0)+
  3783. ($hash->{HELPER}{MIRROR}?$cpcl->{mirror}:0)+
  3784. ($hash->{HELPER}{FLIP}?$cpcl->{flip}:0)+
  3785. ($hash->{HELPER}{ROTATE}?$cpcl->{rotate}:0);
  3786. return;
  3787. }
  3788. ###############################################################################
  3789. # Clienthash übernehmen oder zusammenstellen
  3790. # Identifikation ob über FHEMWEB ausgelöst oder nicht -> erstellen $hash->CL
  3791. sub SSCam_getclhash ($;$$) {
  3792. my ($hash,$nobgd)= @_;
  3793. my $name = $hash->{NAME};
  3794. my $ret;
  3795. if($nobgd) {
  3796. # nur übergebenen CL-Hash speichern,
  3797. # keine Hintergrundverarbeitung bzw. synthetische Erstellung CL-Hash
  3798. $hash->{HELPER}{CL}{1} = $hash->{CL};
  3799. return undef;
  3800. }
  3801. if (!defined($hash->{CL})) {
  3802. # Clienthash wurde nicht übergeben und wird erstellt (FHEMWEB Instanzen mit canAsyncOutput=1 analysiert)
  3803. my $outdev;
  3804. my @webdvs = devspec2array("TYPE=FHEMWEB:FILTER=canAsyncOutput=1:FILTER=STATE=Connected");
  3805. my $i = 1;
  3806. foreach (@webdvs) {
  3807. $outdev = $_;
  3808. next if(!$defs{$outdev});
  3809. $hash->{HELPER}{CL}{$i}->{NAME} = $defs{$outdev}{NAME};
  3810. $hash->{HELPER}{CL}{$i}->{NR} = $defs{$outdev}{NR};
  3811. $hash->{HELPER}{CL}{$i}->{COMP} = 1;
  3812. $i++;
  3813. }
  3814. } else {
  3815. # übergebenen CL-Hash in Helper eintragen
  3816. $hash->{HELPER}{CL}{1} = $hash->{CL};
  3817. }
  3818. # Clienthash auflösen zur Fehlersuche (aufrufende FHEMWEB Instanz
  3819. if (defined($hash->{HELPER}{CL}{1})) {
  3820. for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) {
  3821. Log3($name, 4, "$name - Clienthash number: $k");
  3822. while (my ($key,$val) = each(%{$hash->{HELPER}{CL}{$k}})) {
  3823. $val = $val?$val:" ";
  3824. Log3($name, 4, "$name - Clienthash: $key -> $val");
  3825. }
  3826. }
  3827. } else {
  3828. Log3($name, 2, "$name - Clienthash was neither delivered nor created !");
  3829. $ret = "Clienthash was neither delivered nor created. Can't use asynchronous output for function.";
  3830. }
  3831. return ($ret);
  3832. }
  3833. ###############################################################################
  3834. # Schnappschußgalerie zusammenstellen
  3835. sub composegallery ($;$$) {
  3836. my ($name,$wlname) = @_;
  3837. my $hash = $defs{$name};
  3838. my $camname = $hash->{CAMNAME};
  3839. my $allsnaps = $hash->{HELPER}{".SNAPHASH"}; # = \%allsnaps
  3840. my $sgc = AttrVal($name,"snapGalleryColumns",3); # Anzahl der Images in einer Tabellenzeile
  3841. my $lss = ReadingsVal($name, "LastSnapTime", " "); # Zeitpunkt neueste Aufnahme
  3842. my $lang = AttrVal("global","language","EN"); # Systemsprache
  3843. my $limit = $hash->{HELPER}{SNAPLIMIT}; # abgerufene Anzahl Snaps
  3844. my $totalcnt = $hash->{HELPER}{TOTALCNT}; # totale Anzahl Snaps
  3845. $limit = $totalcnt if ($limit > $totalcnt); # wenn weniger Snaps vorhanden sind als $limit -> Text in Anzeige korrigieren
  3846. my $lupt = ((ReadingsTimestamp($name,"LastSnapTime"," ") gt ReadingsTimestamp($name,"LastUpdateTime"," "))
  3847. ? ReadingsTimestamp($name,"LastSnapTime"," ")
  3848. : ReadingsTimestamp($name,"LastUpdateTime"," ")); # letzte Aktualisierung
  3849. $lupt =~ s/ / \/ /;
  3850. my $ha = AttrVal($name, "snapGalleryHtmlAttr", undef)?AttrVal($name, "snapGalleryHtmlAttr", undef):AttrVal($name, "htmlattr", 'width="500" height="325"');
  3851. # falls "composegallery" durch ein mit "createSnapGallery" angelegtes Device aufgerufen wird
  3852. my ($devWlink,$wlhash,$wlha,$wlalias);
  3853. if ($wlname) {
  3854. $wlalias = $attr{$wlname}{alias}?$attr{$wlname}{alias}:$wlname; # Linktext als Aliasname oder Devicename setzen
  3855. $devWlink = "<a href=\"/fhem?detail=$wlname\">$wlalias</a>";
  3856. $wlhash = $defs{$wlname};
  3857. $wlha = $attr{$wlname}{htmlattr};
  3858. $ha = (defined($wlha))?$wlha:$ha; # htmlattr vom weblink-Device übernehmen falls von wl-Device aufgerufen und gesetzt
  3859. } else {
  3860. $devWlink = " ";
  3861. }
  3862. # wenn Weblink genutzt wird und attr "snapGalleryBoost" nicht gesetzt ist -> Warnung in Gallerie ausgeben
  3863. my $sgbnote = " ";
  3864. if($wlname && !AttrVal($name,"snapGalleryBoost",0)) {
  3865. $sgbnote = "<b>CAUTION</b> - No snapshots can be retrieved. Please set the attribute \"snapGalleryBoost=1\" in device <a href=\"/fhem?detail=$name\">$name</a>" if ($lang eq "EN");
  3866. $sgbnote = "<b>ACHTUNG</b> - Es können keine Schnappschüsse abgerufen werden. Bitte setzen sie das Attribut \"snapGalleryBoost=1\" im Device <a href=\"/fhem?detail=$name\">$name</a>" if ($lang eq "DE");
  3867. }
  3868. my $header;
  3869. if ($lang eq "EN") {
  3870. $header = "Snapshots ($limit/$totalcnt) of camera <b>$camname</b> - newest Snapshot: $lss<br>";
  3871. $header .= " (Possibly another snapshots are available. Last recall: $lupt)<br>" if(AttrVal($name,"snapGalleryBoost",0));
  3872. } else {
  3873. $header = "Schnappschüsse ($limit/$totalcnt) von Kamera <b>$camname</b> - neueste Aufnahme: $lss <br>";
  3874. $header .= " (Eventuell sind neuere Aufnahmen verfügbar. Letzter Abruf: $lupt)<br>" if(AttrVal($name,"snapGalleryBoost",0));
  3875. }
  3876. $header .= $sgbnote;
  3877. my $gattr = (AttrVal($name,"snapGallerySize","Icon") eq "Full")?$ha:" ";
  3878. my @as = sort{$a <=>$b}keys%{$allsnaps};
  3879. # Ausgabetabelle erstellen
  3880. my ($htmlCode,$ct);
  3881. $htmlCode = "<html>";
  3882. $htmlCode .= sprintf("$devWlink<br> <div class=\"makeTable wide\"; style=\"text-align:center\"> $header <br>");
  3883. $htmlCode .= "<table class=\"block wide internals\">";
  3884. $htmlCode .= "<tbody>";
  3885. $htmlCode .= "<tr class=\"odd\">";
  3886. my $cell = 1;
  3887. foreach my $key (@as) {
  3888. $ct = $allsnaps->{$key}{createdTm};
  3889. my $html = sprintf("<td>$ct<br /> <img $gattr src=\"data:image/jpeg;base64,$allsnaps->{$key}{imageData}\" /> </td>" );
  3890. $cell++;
  3891. if ( $cell == $sgc+1 ) {
  3892. $htmlCode .= $html;
  3893. $htmlCode .= "</tr>";
  3894. $htmlCode .= "<tr class=\"odd\">";
  3895. $cell = 1;
  3896. } else {
  3897. $htmlCode .= $html;
  3898. }
  3899. }
  3900. if ( $cell == 2 ) {
  3901. $htmlCode .= "<td> </td>";
  3902. }
  3903. $htmlCode .= "</tr>";
  3904. $htmlCode .= "</tbody>";
  3905. $htmlCode .= "</table>";
  3906. $htmlCode .= "</div>";
  3907. $htmlCode .= "</html>";
  3908. return $htmlCode;
  3909. }
  3910. ##############################################################################
  3911. # Auflösung Errorcodes bei Login / Logout
  3912. sub SSCam_experrorauth {
  3913. # Übernahmewerte sind $hash, $errorcode
  3914. my ($hash,@errorcode) = @_;
  3915. my $device = $hash->{NAME};
  3916. my $errorcode = shift @errorcode;
  3917. my $error;
  3918. unless (exists($SSCam_errauthlist{"$errorcode"})) {$error = "Message of errorcode \"$errorcode\" not found. Please turn to Synology Web API-Guide."; return ($error);}
  3919. # Fehlertext aus Hash-Tabelle %errorauthlist ermitteln
  3920. $error = $SSCam_errauthlist{"$errorcode"};
  3921. return ($error);
  3922. }
  3923. ##############################################################################
  3924. # Auflösung Errorcodes SVS API
  3925. sub SSCam_experror {
  3926. # Übernahmewerte sind $hash, $errorcode
  3927. my ($hash,@errorcode) = @_;
  3928. my $device = $hash->{NAME};
  3929. my $errorcode = shift @errorcode;
  3930. my $error;
  3931. unless (exists($SSCam_errlist{"$errorcode"})) {$error = "Message of errorcode $errorcode not found. Please turn to Synology Web API-Guide."; return ($error);}
  3932. # Fehlertext aus Hash-Tabelle %errorlist ermitteln
  3933. $error = $SSCam_errlist{"$errorcode"};
  3934. return ($error);
  3935. }
  3936. 1;
  3937. =pod
  3938. =item summary operates surveillance cameras defined in Synology Surveillance Station
  3939. =item summary_DE steuert Kameras welche der Synology Surveillance Station
  3940. =begin html
  3941. <a name="SSCam"></a>
  3942. <h3>SSCam</h3>
  3943. <ul>
  3944. Using this Module you are able to operate cameras which are defined in Synology Surveillance Station (SVS) and execute
  3945. functions of the SVS. It is based on the SVS API and supports the SVS version 7 and above.<br>
  3946. At present the following functions are available: <br><br>
  3947. <ul>
  3948. <ul>
  3949. <li>Start a Recording</li>
  3950. <li>Stop a Recording (using command or automatically after the &lt;RecordTime&gt; period</li>
  3951. <li>Trigger a Snapshot </li>
  3952. <li>Deaktivate a Camera in Synology Surveillance Station</li>
  3953. <li>Activate a Camera in Synology Surveillance Station</li>
  3954. <li>Control of the exposure modes day, night and automatic </li>
  3955. <li>switchover the motion detection by camera, by SVS or to deactivate </li>
  3956. <li>control of motion detection parameters sensitivity, threshold, object size and percentage for release </li>
  3957. <li>Retrieval of Camera Properties (also by Polling) as well as informations about the installed SVS-package</li>
  3958. <li>Move to a predefined Preset-position (at PTZ-cameras) </li>
  3959. <li>Start a predefined Patrol (at PTZ-cameras) </li>
  3960. <li>Positioning of PTZ-cameras to absolute X/Y-coordinates </li>
  3961. <li>continuous moving of PTZ-camera lense </li>
  3962. <li>trigger of external events 1-10 (action rules in SVS) </li>
  3963. <li>start and stop of camera livestreams, show the last recording and snapshot embedded </li>
  3964. <li>fetch of livestream-Url's with key (login not needed in that case) </li>
  3965. <li>playback of last recording and playback the last snapshot </li>
  3966. <li>switch the Surveillance Station HomeMode on/off and retrieve the HomeModeState </li>
  3967. <li>show the stored credentials of a device </li>
  3968. <li>fetch the Surveillance Station Logs, exploit the newest entry as reading </li>
  3969. <li>create a gallery of the last 1-10 snapshots (as a Popup or permanent weblink-Device) </li><br>
  3970. </ul>
  3971. </ul>
  3972. The recordings and snapshots will be stored in Synology Surveillance Station (SVS) and are managed like the other (normal) recordings / snapshots defined by Surveillance Station rules.<br>
  3973. For example the recordings are stored for a defined time in Surveillance Station and will be deleted after that period.<br><br>
  3974. If you like to discuss or help to improve this module please use FHEM-Forum with link: <br>
  3975. <a href="http://forum.fhem.de/index.php/topic,45671.msg374390.html#msg374390">49_SSCam: Fragen, Hinweise, Neuigkeiten und mehr rund um dieses Modul</a>.<br><br>
  3976. <b> Prerequisites </b> <br><br>
  3977. This module uses the Perl-module JSON. <br>
  3978. On Debian-Linux based systems this module can be installed by: <br><br>
  3979. <code>sudo apt-get install libjson-perl</code> <br><br>
  3980. SSCam is completely using the nonblocking functions of HttpUtils respectively HttpUtils_NonblockingGet. <br>
  3981. In DSM respectively in Synology Surveillance Station an User has to be created. The login credentials are needed later when using a set-command to assign the login-data to a device. <br>
  3982. Further informations could be find among <a href="#SSCam_Credentials">Credentials</a>. <br><br>
  3983. Overview which Perl-modules SSCam is using: <br><br>
  3984. JSON <br>
  3985. Data::Dumper <br>
  3986. MIME::Base64 <br>
  3987. Time::HiRes <br>
  3988. HttpUtils (FHEM-module) <br><br>
  3989. <a name="SSCamdefine"></a>
  3990. <b>Define</b>
  3991. <ul>
  3992. <br>
  3993. There is a distinction between the definition of a camera-device and the definition of a Surveillance Station (SVS)
  3994. device. Dependend on the kind of the defined device the internal MODEL will be set to CAM or SVS and a proper
  3995. subset of the described set/get-commands are assigned to the device. <br>
  3996. The scope of application of set/get-commands is denoted to every particular command (valid for CAM, SVS, CAM/SVS).
  3997. <br><br>
  3998. A camera-device will be defined by: <br><br>
  3999. <code>define &lt;name&gt; SSCAM &lt;camera name in SVS&gt; &lt;ServerAddr&gt; [Port] </code> <br><br>
  4000. At first the devices have to be set up and has to be operable in Synology Surveillance Station 7.0 and above. <br><br>
  4001. A SVS-device to control functions of the Surveillance Station (SVS) will be defined by: <br><br>
  4002. <code>define &lt;name&gt; SSCAM SVS &lt;ServerAddr&gt; [Port] </code> <br><br>
  4003. In that case the term &lt;camera name in SVS&gt; become replaced by <b>SVS</b> only. <br><br>
  4004. The Modul SSCam ist based on functions of Synology Surveillance Station API. <br>
  4005. Currently the HTTP-protocol is supported to call Synology Disk Station. <br><br>
  4006. The parameters are in detail:
  4007. <br>
  4008. <br>
  4009. <table>
  4010. <colgroup> <col width=15%> <col width=85%> </colgroup>
  4011. <tr><td>name: </td><td>the name of the new device to use in FHEM</td></tr>
  4012. <tr><td>Cameraname: </td><td>camera name as defined in Synology Surveillance Station if camera-device, "SVS" if SVS-Device. Spaces are not allowed in camera name. </td></tr>
  4013. <tr><td>ServerAddr: </td><td>IP-address of Synology Surveillance Station Host. <b>Note:</b> avoid using hostnames because of DNS-Calls are not unblocking in FHEM </td></tr>
  4014. <tr><td>Port: </td><td>optional - the port of synology surveillance station, if not set the default of 5000 (HTTP only) is used</td></tr>
  4015. </table>
  4016. <br><br>
  4017. <b>Example:</b>
  4018. <pre>
  4019. <code>define CamCP SSCAM Carport 192.168.2.20 [5000]</code>
  4020. creates a new camera device CamCP
  4021. <code>define DS1 SSCAM SVS 192.168.2.20 [5000]</code>
  4022. creares a new SVS device DS1
  4023. </pre>
  4024. When a new Camera is defined, as a start the recordingtime of 15 seconds will be assigned to the device.<br>
  4025. Using the <a href="#SSCamattr">attribute</a> "rectime" you can adapt the recordingtime for every camera individually.<br>
  4026. The value of "0" for rectime will lead to an endless recording which has to be stopped by a "set &lt;name&gt; off" command.<br>
  4027. Due to a Log-Entry with a hint to that circumstance will be written. <br><br>
  4028. If the <a href="#SSCamattr">attribute</a> "rectime" would be deleted again, the default-value for recording-time (15s) become active.<br><br>
  4029. With <a href="#SSCamset">command</a> <b>"set &lt;name&gt; on [rectime]"</b> a temporary recordingtime is determinded which would overwrite the dafault-value of recordingtime <br>
  4030. and the attribute "rectime" (if it is set) uniquely. <br><br>
  4031. In that case the command <b>"set &lt;name&gt; on 0"</b> leads also to an endless recording as well.<br><br>
  4032. If you have specified a pre-recording time in SVS it will be considered too. <br><br><br>
  4033. <a name="SSCam_Credentials"></a>
  4034. <b>Credentials </b><br><br>
  4035. After a camera-device is defined, firstly it is needed to save the credentials. This will be done with command:
  4036. <pre>
  4037. set &lt;name&gt; credentials &lt;username&gt; &lt;password&gt;
  4038. </pre>
  4039. The password length has a maximum of 20 characters. <br>
  4040. The operator can, dependend on what functions are planned to execute, create an user in DSM respectively in Synology Surveillance Station as well. <br>
  4041. If the user is member of admin-group, he has access to all module functions. Without this membership the user can only execute functions with lower need of rights. <br>
  4042. The required minimum rights to execute functions are listed in a table further down. <br>
  4043. Alternatively to DSM-user a user created in SVS can be used. Also in that case a user of type "manager" has the right to execute all functions, <br>
  4044. whereat the access to particular cameras can be restricted by the privilege profile (please see help function in SVS for details). <br>
  4045. As best practice it is proposed to create an user in DSM as well as in SVS too: <br><br>
  4046. <ul>
  4047. <li>DSM-User as member of admin group: unrestricted test of all module functions -&gt; session: DSM </li>
  4048. <li>SVS-User as Manager or observer: adjusted privilege profile -&gt; session: SurveillanceStation </li>
  4049. </ul>
  4050. <br>
  4051. Using the <a href="#SSCamattr">Attribute</a> "session" can be selected, if the session should be established to DSM or the SVS instead. <br>
  4052. If the session will be established to DSM, SVS Web-API methods are available as well as further API methods of other API's what possibly needed for processing. <br><br>
  4053. After device definition the default is "login to DSM", that means credentials with admin rights can be used to test all camera-functions firstly. <br>
  4054. After this the credentials can be switched to a SVS-session with a restricted privilege profile as needed on dependency what module functions are want to be executed. <br><br>
  4055. The following list shows the minimum rights what the particular module function needs. <br><br>
  4056. <ul>
  4057. <table>
  4058. <colgroup> <col width=20%> <col width=80%> </colgroup>
  4059. <tr><td><li>set ... on </td><td> session: ServeillanceStation - observer with enhanced privilege "manual recording" </li></td></tr>
  4060. <tr><td><li>set ... off </td><td> session: ServeillanceStation - observer with enhanced privilege "manual recording" </li></td></tr>
  4061. <tr><td><li>set ... snap </td><td> session: ServeillanceStation - observer </li></td></tr>
  4062. <tr><td><li>set ... disable </td><td> session: ServeillanceStation - manager </li></td></tr>
  4063. <tr><td><li>set ... enable </td><td> session: ServeillanceStation - manager </li></td></tr>
  4064. <tr><td><li>set ... expmode </td><td> session: ServeillanceStation - manager </li></td></tr>
  4065. <tr><td><li>set ... extevent </td><td> session: DSM - user as member of admin-group </li></td></tr>
  4066. <tr><td><li>set ... goPreset </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  4067. <tr><td><li>set ... homeMode </td><td> ssession: ServeillanceStation - observer with privilege Home Mode switch </li></td></tr>
  4068. <tr><td><li>set ... motdetsc </td><td> session: ServeillanceStation - manager </li></td></tr>
  4069. <tr><td><li>set ... runPatrol </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  4070. <tr><td><li>set ... goAbsPTZ </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  4071. <tr><td><li>set ... move </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  4072. <tr><td><li>set ... runView </td><td> session: ServeillanceStation - observer with privilege liveview of camera </li></td></tr>
  4073. <tr><td><li>set ... snapGallery </td><td> session: ServeillanceStation - observer </li></td></tr>
  4074. <tr><td><li>set ... stopView </td><td> - </li></td></tr>
  4075. <tr><td><li>set ... credentials </td><td> - </li></td></tr>
  4076. <tr><td><li>get ... caminfo[all] </td><td> session: ServeillanceStation - observer </li></td></tr>
  4077. <tr><td><li>get ... eventlist </td><td> session: ServeillanceStation - observer </li></td></tr>
  4078. <tr><td><li>get ... listLog </td><td> session: ServeillanceStation - observer </li></td></tr>
  4079. <tr><td><li>get ... scanVirgin </td><td> session: ServeillanceStation - observer </li></td></tr>
  4080. <tr><td><li>get ... svsinfo </td><td> session: ServeillanceStation - observer </li></td></tr>
  4081. <tr><td><li>get ... snapfileinfo </td><td> session: ServeillanceStation - observer </li></td></tr>
  4082. <tr><td><li>get ... snapinfo </td><td> session: ServeillanceStation - observer </li></td></tr>
  4083. <tr><td><li>get ... stmUrlPath </td><td> session: ServeillanceStation - observer </li></td></tr>
  4084. </table>
  4085. </ul>
  4086. <br><br>
  4087. <a name="SSCam_HTTPTimeout"></a>
  4088. <b>HTTP-Timeout Settings</b><br><br>
  4089. All functions of SSCam use HTTP-calls to SVS Web API. <br>
  4090. The default-value of HTTP-Timeout amounts 4 seconds. You can set the <a href="#SSCamattr">attribute</a> "httptimeout" > 0 to adjust the value as needed in your technical environment. <br>
  4091. </ul>
  4092. <br><br><br>
  4093. <a name="SSCamset"></a>
  4094. <b>Set </b>
  4095. <ul>
  4096. <br>
  4097. The specified set-commands are available for CAM/SVS-devices or only valid for CAM-devices or rather for SVS-Devices.
  4098. They can be selected in the drop-down-menu of the particular device. <br><br>
  4099. <ul>
  4100. <li><b> set &lt;name&gt; credentials &lt;username&gt; &lt;password&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM/SVS)</li> <br>
  4101. set username / password combination for access the Synology Surveillance Station.
  4102. See <a href="#SSCam_Credentials">Credentials</a><br> for further informations.
  4103. <br><br>
  4104. </ul>
  4105. <ul>
  4106. <li><b> set &lt;name&gt; createSnapGallery </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4107. A snapshot gallery will be created as a permanent (weblink)Device. The device will be provided in room "SnapGallery".
  4108. With the "snapGallery..."-<a href="#SSCamattr">attributes</a> respectively the weblink-device specific attributes (which was created)
  4109. you are able to manipulate the properties of the new snapshot gallery device. <br>
  4110. <br><br>
  4111. </ul>
  4112. <ul>
  4113. <li><b> set &lt;name&gt; [enable|disable] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4114. For <b>deactivating / activating</b> a list of cameras or all cameras by Regex-expression, subsequent two
  4115. examples using "at":
  4116. <pre>
  4117. define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
  4118. define a14 at 21:46 set Cam.* disable (enable)
  4119. </pre>
  4120. A bit more convenient is it to use a dummy-device for enable/disable all available cameras in Surveillance Station.<br>
  4121. At first the Dummy will be created.
  4122. <pre>
  4123. define allcams dummy
  4124. attr allcams eventMap on:enable off:disable
  4125. attr allcams room Cams
  4126. attr allcams webCmd enable:disable
  4127. </pre>
  4128. With combination of two created notifies, respectively one for "enable" and one for "diasble", you are able to switch all cameras into "enable" or "disable" state at the same time if you set the dummy to "enable" or "disable".
  4129. <pre>
  4130. define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
  4131. attr all_cams_disable room Cams
  4132. define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
  4133. attr all_cams_enable room Cams
  4134. </pre>
  4135. </ul>
  4136. <br><br>
  4137. <ul>
  4138. <li><b> set &lt;name&gt; expmode [day|night|auto] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4139. With this command you are able to control the exposure mode and can set it to day, night or automatic mode.
  4140. Thereby, for example, the behavior of camera LED's will be suitable controlled.
  4141. The successful switch will be reported by the reading CamExposureMode (command "get ... caminfoall"). <br><br>
  4142. <b> Note: </b><br>
  4143. The successfully execution of this function depends on if SVS supports that functionality of the connected camera.
  4144. Is the field for the Day/Night-mode shown greyed in SVS -&gt; IP-camera -&gt; optimization -&gt; exposure mode, this function will be probably unsupported.
  4145. </ul>
  4146. <br><br>
  4147. <ul>
  4148. <li><b> set &lt;name&gt; extevent [ 1-10 ] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for SVS)</li> <br>
  4149. This command triggers an external event (1-10) in SVS.
  4150. The actions which will are used have to be defined in the actionrule editor of SVS at first. There are the events 1-10 possible.
  4151. In the message application of SVS you may select Email, SMS or Mobil (DS-Cam) messages to release if an external event has been triggerd.
  4152. Further informations can be found in the online help of the actionrule editor.
  4153. The used user needs to be a member of the admin-group and DSM-session is needed too.
  4154. </ul>
  4155. <br><br>
  4156. <ul>
  4157. <li><b> set &lt;name&gt; goAbsPTZ [ X Y | up | down | left | right ] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4158. This command can be used to move a PTZ-camera to an arbitrary absolute X/Y-coordinate, or to absolute position using up/down/left/right.
  4159. The option is only available for cameras which are having the Reading "CapPTZAbs=true". The property of a camera can be requested with "get &lt;name&gt; caminfoall" .
  4160. <br><br>
  4161. Example for a control to absolute X/Y-coordinates: <br>
  4162. <pre>
  4163. set &lt;name&gt; goAbsPTZ 120 450
  4164. </pre>
  4165. In this example the camera lense moves to position X=120 und Y=450. <br>
  4166. The valuation is:
  4167. <pre>
  4168. X = 0 - 640 (0 - 319 moves lense left, 321 - 640 moves lense right, 320 don't move lense)
  4169. Y = 0 - 480 (0 - 239 moves lense down, 241 - 480 moves lense up, 240 don't move lense)
  4170. </pre>
  4171. The lense can be moved in smallest steps to very large steps into the desired direction.
  4172. If necessary the procedure has to be repeated to bring the lense into the desired position. <br><br>
  4173. If the motion should be done with the largest possible increment the following command can be used for simplification:
  4174. <pre>
  4175. set &lt;name&gt; goAbsPTZ up [down|left|right]
  4176. </pre>
  4177. In this case the lense will be moved with largest possible increment into the given absolute position.
  4178. Also in this case the procedure has to be repeated to bring the lense into the desired position if necessary.
  4179. </ul>
  4180. <br><br>
  4181. <ul>
  4182. <li><b> set &lt;name&gt; goPreset &lt;Preset&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4183. Using this command you can move PTZ-cameras to a predefined position. <br>
  4184. The Preset-positions have to be defined first of all in the Synology Surveillance Station. This usually happens in the PTZ-control of IP-camera setup in SVS.
  4185. The Presets will be read ito FHEM with command "get &lt;name&gt; caminfoall" (happens automatically when FHEM restarts). The import process can be repeated regular by camera polling.
  4186. A long polling interval is recommendable in this case because of the Presets are only will be changed if the user change it in the IP-camera setup itself.
  4187. <br><br>
  4188. Here it is an example of a PTZ-control depended on IR-motiondetector event:
  4189. <pre>
  4190. define CamFL.Preset.Wandschrank notify MelderTER:on.* set CamFL goPreset Wandschrank, ;; define CamFL.Preset.record at +00:00:10 set CamFL on 5 ;;;; define s3 at +*{3}00:00:05 set CamFL snap ;; define CamFL.Preset.back at +00:00:30 set CamFL goPreset Home
  4191. </pre>
  4192. Operating Mode: <br>
  4193. The IR-motiondetector registers a motion. Hereupon the camera "CamFL" moves to Preset-posion "Wandschrank". A recording with the length of 5 seconds starts 10 seconds later.
  4194. Because of the prerecording time of the camera is set to 10 seconds (cf. Reading "CamPreRecTime"), the effectice recording starts when the camera move begins. <br>
  4195. When the recording starts 3 snapshots with an interval of 5 seconds will be taken as well. <br>
  4196. After a time of 30 seconds in position "Wandschrank" the camera moves back to postion "Home". <br><br>
  4197. An extract of the log illustrates the process:
  4198. <pre>
  4199. 2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
  4200. 2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
  4201. 2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4202. 2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
  4203. 2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4204. 2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4205. 2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
  4206. </pre>
  4207. </ul>
  4208. <br><br>
  4209. <ul>
  4210. <li><b> set &lt;name&gt; homeMode [on|off] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for SVS)</li> <br>
  4211. Switch the HomeMode of the Surveillance Station on or off.
  4212. Further informations about HomeMode you can find in the <a href="https://www.synology.com/en-global/knowledgebase/Surveillance/help/SurveillanceStation/home_mode">Synology Onlinehelp</a>.
  4213. <br><br>
  4214. </ul>
  4215. <ul>
  4216. <li><b> set &lt;name&gt; motdetsc [camera|SVS|disable] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4217. The command "motdetsc" (stands for "motion detection source") switchover the motion detection to the desired mode.
  4218. If motion detection will be done by camera / SVS without any parameters, the original camera motion detection settings are kept.
  4219. The successful execution of that opreration one can retrace by the state in SVS -&gt; IP-camera -&gt; event detection -&gt; motion. <br><br>
  4220. For the motion detection further parameter can be specified. The available options for motion detection by SVS are "sensitivity" and "threshold". <br><br>
  4221. <ul>
  4222. <table>
  4223. <colgroup> <col width=50%> <col width=50%> </colgroup>
  4224. <tr><td>set &lt;name&gt; motdetsc SVS [sensitivity] [threshold] </td><td># command pattern </td></tr>
  4225. <tr><td>set &lt;name&gt; motdetsc SVS 91 30 </td><td># set the sensitivity to 91 and threshold to 30 </td></tr>
  4226. <tr><td>set &lt;name&gt; motdetsc SVS 0 40 </td><td># keep the old value of sensitivity, set threshold to 40 </td></tr>
  4227. <tr><td>set &lt;name&gt; motdetsc SVS 15 </td><td># set the sensitivity to 15, threshold keep unchanged </td></tr>
  4228. </table>
  4229. </ul>
  4230. <br><br>
  4231. If the motion detection is used by camera, there are the options "sensitivity", "object size", "percentage for release" available. <br><br>
  4232. <ul>
  4233. <table>
  4234. <colgroup> <col width=50%> <col width=50%> </colgroup>
  4235. <tr><td>set &lt;name&gt; motdetsc camera [sensitivity] [threshold] [percentage] </td><td># command pattern </td></tr>
  4236. <tr><td>set &lt;name&gt; motdetsc camera 89 0 20 </td><td># set the sensitivity to 89, percentage to 20 </td></tr>
  4237. <tr><td>set &lt;name&gt; motdetsc camera 0 40 10 </td><td># keep old value for sensitivity, set threshold to 40, percentage to 10 </td></tr>
  4238. <tr><td>set &lt;name&gt; motdetsc camera 30 </td><td># set the sensitivity to 30, other values keep unchanged </td></tr>
  4239. </table>
  4240. </ul>
  4241. <br><br>
  4242. Please consider always the sequence of parameters. Unwanted options have to be set to "0" if further options which have to be changed are follow (see example above).
  4243. The numerical values are between 1 - 99 (except special case "0"). <br><br>
  4244. The each available options are dependend of camera type respectively the supported functions by SVS. Only the options can be used they are available in
  4245. SVS -&gt; edit camera -&gt; motion detection. Further informations please read in SVS online help. <br><br>
  4246. With the command "get &lt;name&gt; caminfoall" the <a href="#SSCamreadings">Reading</a> "CamMotDetSc" also will be updated which documents the current setup of motion detection.
  4247. Only the parameters and parameter values supported by SVS at present will be shown. The camera itself may offer further options to adjust. <br><br>
  4248. Example:
  4249. <pre>
  4250. CamMotDetSc SVS, sensitivity: 76, threshold: 55
  4251. </pre>
  4252. </ul>
  4253. <br><br>
  4254. <ul>
  4255. <li><b> set &lt;name&gt; move [ right | up | down | left | dir_X ] [Sekunden] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM up to SVS version 7.1)</li>
  4256. <b> set &lt;name&gt; move [ right | upright | up | upleft | left | downleft | down | downright ] [Sekunden] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM and SVS Version 7.2 and above) <br><br>
  4257. With this command a continuous move of a PTZ-camera will be started. In addition to the four basic directions up/down/left/right is it possible to use angular dimensions
  4258. "dir_X". The grain size of graduation depends on properties of the camera and can be identified by the Reading "CapPTZDirections". <br><br>
  4259. The radian measure of 360 degrees will be devided by the value of "CapPTZDirections" and describes the move drections starting with "0=right" counterclockwise.
  4260. That means, if a camera Reading is "CapPTZDirections = 8" it starts with dir_0 = right, dir_2 = top, dir_4 = left, dir_6 = bottom and respectively dir_1, dir_3, dir_5 and dir_7
  4261. the appropriate directions between. The possible moving directions of cameras with "CapPTZDirections = 32" are correspondingly divided into smaller sections. <br><br>
  4262. In opposite to the "set &lt;name&gt; goAbsPTZ"-command starts "set &lt;name&gt; move" a continuous move until a stop-command will be received.
  4263. The stop-command will be generated after the optional assignable time of [seconds]. If that retention period wouldn't be set by the command, a time of 1 second will be set implicit. <br><br>
  4264. Examples: <br>
  4265. <pre>
  4266. set &lt;name&gt; move up 0.5 : moves PTZ 0,5 Sek. (plus processing time) to the top
  4267. set &lt;name&gt; move dir_1 1.5 : moves PTZ 1,5 Sek. (plus processing time) to top-right
  4268. set &lt;name&gt; move dir_20 0.7 : moves PTZ 1,5 Sek. (plus processing time) to left-bottom ("CapPTZDirections = 32)"
  4269. </pre>
  4270. </ul>
  4271. <br><br>
  4272. <ul>
  4273. <li><b>set &lt;name&gt; [on|off] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4274. The command "set &lt;name&gt; on" starts a recording. The default recording time takes 15 seconds. It can be changed by the <a href="#SSCamattr">attribute</a> "rectime" individualy.
  4275. With the <a href="#SSCamattr">attribute</a> (respectively the default value) provided recording time can be overwritten once by "set &lt;name&gt; on [rectime]".
  4276. The recording will be stopped after processing time "rectime"automatically.<br>
  4277. A special case is the start using "set &lt;name&gt; on 0" respectively the attribute value "rectime = 0". In that case a endless-recording will be started. One have to stop this recording
  4278. by command "set &lt;name&gt; off" explicitely.<br>
  4279. The recording behavior can be impacted with <a href="#SSCamattr">attribute</a> "recextend" furthermore as explained as follows.<br><br>
  4280. <b>Attribute "recextend = 0" or not set (default):</b><br><br>
  4281. <ul>
  4282. <li> if, for example, a recording with rectimeme=22 is started, no other startcommand (for a recording) will be accepted until this started recording is finished.
  4283. A hint will be logged in case of verboselevel = 3. </li>
  4284. </ul>
  4285. <br>
  4286. <b>Attribute "recextend = 1" is set:</b><br><br>
  4287. <ul>
  4288. <li> a before started recording will be extend by the recording time "rectime" if a new start command is received. That means, the timer for the automatic stop-command will be
  4289. renewed to "rectime" given bei the command, attribute or default value. This procedure will be repeated every time a new start command for recording is received.
  4290. Therefore a running recording will be extended until no start command will be get. </li>
  4291. <li> a before started endless-recording will be stopped after recordingtime 2rectime" if a new "set <name> on"-command is received (new set of timer). If it is unwanted make sure you
  4292. don't set the <a href="#SSCamattr">attribute</a> "recextend" in case of endless-recordings. </li>
  4293. </ul>
  4294. <br>
  4295. Examples for simple <b>Start/Stop a Recording</b>: <br><br>
  4296. <table>
  4297. <colgroup> <col width=20%> <col width=80%> </colgroup>
  4298. <tr><td>set &lt;name&gt; on [rectime] </td><td>starts a recording of camera &lt;name&gt;, stops automatically after [rectime] (default 15s or defined by <a href="#SSCamattr">attribute</a>) </td></tr>
  4299. <tr><td>set &lt;name&gt; off </td><td>stops the recording of camera &lt;name&gt;</td></tr>
  4300. </table>
  4301. </ul>
  4302. <br><br>
  4303. <ul>
  4304. <li><b> set &lt;name&gt; optimizeParams [mirror:&lt;value&gt;] [flip:&lt;value&gt;] [rotate:&lt;value&gt;] [ntp:&lt;value&gt;]</b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4305. Set one or several properties of the camera. The video can be mirrored (mirror), turned upside down (flip) or
  4306. rotated (rotate). Specified properties must be supported by the camera type. With "ntp" you can set a time server the camera
  4307. use for time synchronization. <br><br>
  4308. &lt;value&gt; can be for: <br>
  4309. <ul>
  4310. <li> <b>mirror, flip, rotate: </b> true | false </li>
  4311. <li> <b>ntp: </b> the name or the IP-address of time server </li>
  4312. </ul>
  4313. <br><br>
  4314. <b>Examples:</b> <br>
  4315. <code> set &lt;name&gt; optimizeParams mirror:true flip:true ntp:time.windows.com </code><br>
  4316. # The video will be mirrored, turned upside down and the time server is set to "time.windows.com".<br>
  4317. <code> set &lt;name&gt; optimizeParams ntp:Surveillance%20Station </code><br>
  4318. # The Surveillance Station is set as time server. (NTP-service has to be activated in DSM) <br>
  4319. <code> set &lt;name&gt; optimizeParams mirror:true flip:false rotate:true </code><br>
  4320. # The video will be mirrored and rotated round 90 degrees. <br>
  4321. <br><br>
  4322. </ul>
  4323. <ul>
  4324. <li><b> set &lt;name&gt; runPatrol &lt;Patrolname&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4325. This commans starts a predefined patrol (tour) of a PTZ-camera. <br>
  4326. At first the patrol has to be predefined in the Synology Surveillance Station. It can be done in the PTZ-control of IP-Kamera Setup -&gt; PTZ-control -&gt; patrol.
  4327. The patrol tours will be read with command "get &lt;name&gt; caminfoall" which is be executed automatically when FHEM restarts.
  4328. The import process can be repeated regular by camera polling. A long polling interval is recommendable in this case because of the patrols are only will be changed
  4329. if the user change it in the IP-camera setup itself.
  4330. Further informations for creating patrols you can get in the online-help of Surveillance Station.
  4331. </ul>
  4332. <br><br>
  4333. <ul>
  4334. <li><b> set &lt;name&gt; runView [live_fw | live_link | live_open [&lt;room&gt;] | lastrec_fw | lastrec_open [&lt;room&gt;] | lastsnap_fw] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4335. With "live_fw, live_link, live_open" a livestream (mjpeg-stream) of a camera will be started, either as embedded image
  4336. or as a generated link. <br>
  4337. The option "live_open" starts a new browser window. If the optional &lt;room&gt; was set, the window will only be
  4338. started if the specified room is currently opend in a browser session. <br><br>
  4339. The command <b>"set &lt;name&gt; runView lastsnap_fw"</b> shows the last snapshot of the camera embedded in room- or detailview. <br><br>
  4340. Access to the last recording of a camera can be done using "lastrec_fw" respectively "lastrec_open".
  4341. The recording will be opened in iFrame. So there are some control elements available, e.g. to increase/descrease
  4342. reproduce speed. <br>
  4343. The kind of windows in FHEMWEB can be affected by HTML-tags in <a href="#SSCamattr">attribute</a> "htmlattr".
  4344. <br><br>
  4345. <b>Examples:</b><br>
  4346. <pre>
  4347. attr &lt;name&gt; htmlattr width="500" height="375"
  4348. attr &lt;name&gt; htmlattr width="700",height="525",top="200",left="300"
  4349. </pre>
  4350. The command <b>"set &lt;name&gt; runView live_open"</b> starts the stream immediately in a new browser window (longpoll=1
  4351. must be set for WEB).
  4352. A browser window will be initiated to open for every FHEM session which is active. If you want to change this behavior,
  4353. you can use command <b>"set &lt;name&gt; runView live_open &lt;room&gt;"</b>. It initiates open a browser window in that
  4354. FHEM session which has just opend the room &lt;room&gt;.
  4355. The settings of <a href="#SSCamattr">attribute</a> "livestreamprefix" overwrites the data for protocol, servername and
  4356. port in <a href="#SSCamreadings">reading</a> "LiveStreamUrl".
  4357. By "livestreamprefix" the LivestreamURL (is shown if <a href="#SSCamattr">attribute</a> "showStmInfoFull" is set) can
  4358. be modified and used for distribution and external access to SVS livestream. <br><br>
  4359. <b>Example:</b><br>
  4360. <pre>
  4361. attr &lt;name&gt; livestreamprefix https://&lt;Servername&gt;:&lt;Port&gt;
  4362. </pre>
  4363. The livestream can be stopped again by command <b>"set &lt;name&gt; stopView"</b>.
  4364. </ul>
  4365. <br><br>
  4366. <ul>
  4367. <li><b> set &lt;name&gt; snap </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4368. A snapshot can be triggered with:
  4369. <pre>
  4370. set &lt;name&gt; snap
  4371. </pre>
  4372. Subsequent some Examples for <b>taking snapshots</b>: <br><br>
  4373. If a serial of snapshots should be released, it can be done using the following notify command.
  4374. For the example a serial of snapshots are to be triggerd if the recording of a camera starts. <br>
  4375. When the recording of camera "CamHE1" starts (Attribut event-on-change-reading -> "Record" has to be set), then 3 snapshots at intervals of 2 seconds are triggered.
  4376. <pre>
  4377. define he1_snap_3 notify CamHE1:Record.*on define h3 at +*{3}00:00:02 set CamHE1 snap
  4378. </pre>
  4379. Release of 2 Snapshots of camera "CamHE1" at intervals of 6 seconds after the motion sensor "MelderHE1" has sent an event, <br>
  4380. can be done e.g. with following notify-command:
  4381. <pre>
  4382. define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap
  4383. </pre>
  4384. The ID and the filename of the last snapshot will be displayed as value of variable "LastSnapId" respectively "LastSnapFilename" in the device-Readings. <br><br>
  4385. </ul>
  4386. <br><br>
  4387. <ul>
  4388. <li><b> set &lt;name&gt; snapGallery [1-10] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4389. The command is only available if the attribute "snapGalleryBoost=1" is set. <br>
  4390. It creates an output of the last [x] snapshots as well as "get ... snapGallery". But differing from "get" with
  4391. <a href="#SSCamattr">attribute</a> "snapGalleryBoost=1" no popup will be created. The snapshot gallery will be depicted as
  4392. an browserpage instead. All further functions and attributes are appropriate the <a href="#SSCamget">"get &lt;name&gt; snapGallery"</a>
  4393. command. <br>
  4394. If you want create a snapgallery output by triggering, e.g. with an "at" or "notify", you should use the
  4395. <a href="#SSCamget">"get &lt;name&gt; snapGallery"</a> command instead of "set".
  4396. </ul>
  4397. <br><br>
  4398. </ul>
  4399. <br>
  4400. <a name="SSCamget"></a>
  4401. <b>Get</b>
  4402. <ul>
  4403. <br>
  4404. With SSCam the properties of SVS and defined Cameras could be retrieved. <br>
  4405. The specified get-commands are available for CAM/SVS-devices or only valid for CAM-devices or rather for SVS-Devices.
  4406. They can be selected in the drop-down-menu of the particular device. <br><br>
  4407. <ul>
  4408. <li><b> get &lt;name&gt; caminfoall </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM/SVS)</li>
  4409. <b> get &lt;name&gt; caminfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM) <br><br>
  4410. Dependend of the type of camera (e.g. Fix- or PTZ-Camera) the available properties are retrieved and provided as Readings.<br>
  4411. For example the Reading "Availability" will be set to "disconnected" if the camera would be disconnected from Synology
  4412. Surveillance Station and can't be used for further processing like creating events. <br>
  4413. "getcaminfo" retrieves a subset of "getcaminfoall".
  4414. </ul>
  4415. <br><br>
  4416. <ul>
  4417. <li><b> get &lt;name&gt; eventlist </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4418. The <a href="#SSCamreadings">Reading</a> "CamEventNum" and "CamLastRecord" will be refreshed which containes the total number
  4419. of in SVS registered camera events and the path/name of the last recording.
  4420. This command will be implicit executed when "get &lt;name&gt; caminfoall" is running. <br>
  4421. The <a href="#SSCamattr">attribute</a> "videofolderMap" replaces the content of reading "VideoFolder". You can use it for
  4422. example if you have mounted the videofolder of SVS under another name or path and want to access by your local pc.
  4423. </ul>
  4424. <br><br>
  4425. <ul>
  4426. <li><b> get &lt;name&gt; homeModeState </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for SVS)</li> <br>
  4427. HomeMode-state of the Surveillance Station will be retrieved.
  4428. </ul>
  4429. <br><br>
  4430. <ul>
  4431. <li><b> get &lt;name&gt; listLog [severity:&lt;Loglevel&gt;] [limit:&lt;Number of lines&gt;] [match:&lt;Searchstring&gt;] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for SVS)</li> <br>
  4432. Fetches the Surveillance Station Log from Synology server. Without any further options the whole log will be retrieved. <br>
  4433. You can specify all or any of the following options: <br><br>
  4434. <ul>
  4435. <li> &lt;Loglevel&gt; - Information, Warning or Error. Only datasets having this severity are retrieved (default: all) </li>
  4436. <li> &lt;Number of lines&gt; - the specified number of lines (newest) of the log are retrieved (default: all) </li>
  4437. <li> &lt;Searchstring&gt; - only log entries containing the searchstring are retrieved (Note: no Regex possible, the searchstring will be given into the call to SVS) </li>
  4438. </ul>
  4439. <br>
  4440. <b>Examples</b> <br>
  4441. <ul>
  4442. <code>get &lt;name&gt; listLog severity:Error limit:5 </code> <br>
  4443. Reports the last 5 Log entries with severity "Error" <br>
  4444. <code>get &lt;name&gt; listLog severity:Information match:Carport </code> <br>
  4445. Reports all Log entries with severity "Information" and containing the string "Carport" <br>
  4446. <code>get &lt;name&gt; listLog severity:Warning </code> <br>
  4447. Reports all Log entries with severity "Warning" <br><br>
  4448. </ul>
  4449. If the polling of SVS is activated by setting the <a href="#SSCamattr">attribute</a> "pollcaminfoall", the <a href="#SSCamreadings">reading</a>
  4450. "LastLogEntry" will be created. <br>
  4451. In the protocol-setup of the SVS you can adjust what data you want to log. For further informations please have a look at
  4452. <a href="https://www.synology.com/en-uk/knowledgebase/Surveillance/help/SurveillanceStation/log_advanced">Synology Online-Help</a>.
  4453. </ul>
  4454. <br><br>
  4455. <ul>
  4456. <li><b> get &lt;name&gt; scanVirgin </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM/SVS)</li> <br>
  4457. This command is similar to get caminfoall, informations relating to SVS and the camera will be retrieved.
  4458. In difference to caminfoall in either case a new session ID will be generated (do a new login), the camera ID will be
  4459. new identified and all necessary API-parameters will be new investigated.
  4460. </ul>
  4461. <br><br>
  4462. <ul>
  4463. <li><b> get &lt;name&gt; snapGallery [1-10] </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4464. A popup with the last [x] snapshots will be created. If the <a href="#SSCamattr">attribute</a> "snapGalleryBoost" is set,
  4465. the last snapshots (default 3) are requested by polling and they will be stored in the FHEM-servers main memory.
  4466. This method is helpful to speed up the output especially in case of full size images, but it can be possible
  4467. that NOT the newest snapshots are be shown if they have not be initialized by the SSCAm-module itself. <br>
  4468. The function can also be triggered, e.g. by an "at" or "notify". In that case the snapshotgallery will be displayed on all
  4469. connected FHEMWEB instances as a popup. <br><br>
  4470. To control this function behavior there are further <a href="#SSCamattr">attributes</a>: <br><br>
  4471. <ul>
  4472. <li>snapGalleryBoost </li>
  4473. <li>snapGalleryColumns </li>
  4474. <li>snapGalleryHtmlAttr </li>
  4475. <li>snapGalleryNumber </li>
  4476. <li>snapGallerySize </li>
  4477. </ul> <br>
  4478. available.
  4479. </ul> <br>
  4480. <ul>
  4481. <b>Note:</b><br>
  4482. Depended from quantity and resolution (quality) of the snapshot images adequate CPU and/or main memory
  4483. ressources are needed.
  4484. </ul>
  4485. <br><br>
  4486. <ul>
  4487. <li><b> get &lt;name&gt; snapfileinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4488. The filename of the last snapshot will be retrieved. This command will be executed with <b>"get &lt;name&gt; snap"</b>
  4489. automatically.
  4490. </ul>
  4491. <br><br>
  4492. <ul>
  4493. <li><b> get &lt;name&gt; snapinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4494. Informations about snapshots will be retrieved. Heplful if snapshots are not triggerd by SSCam, but by motion detection of the camera or surveillance
  4495. station instead.
  4496. </ul>
  4497. <br><br>
  4498. <ul>
  4499. <li><b> get &lt;name&gt; stmUrlPath </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM)</li> <br>
  4500. This command is to fetch the streamkey information and streamurl using that streamkey. The reading "StmKey" will be filled when this command will be executed and can be used
  4501. to send it and run by your own application like a browser (see example).
  4502. If the <a href="#SSCamattr">attribute</a> "showStmInfoFull" is set, additional stream readings like "StmKeyUnicst", "StmKeymjpegHttp" will be shown and can be used to run the
  4503. appropriate livestream without session id. Is the attribute "livestreamprefix" (usage: "http(s)://&lt;hostname&gt;&lt;port&gt;) used, the servername / port will be replaced if necessary.
  4504. The strUrlPath function will be included automatically if polling is used.
  4505. <br><br>
  4506. Example to create an http-call to a livestream using StmKey: <br>
  4507. <pre>
  4508. http(s)://&lt;hostname&gt;&lt;port&gt;/webapi/entry.cgi?api=SYNO.SurveillanceStation.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey="31fd87279976d89bb98409728cced890"
  4509. </pre>
  4510. cameraId (Internal CAMID) and StmKey has to be replaced by valid values. <br><br>
  4511. <b>Note:</b> <br>
  4512. If you use the stream-call from external and replace hostname / port with valid values and open your router ip ports, please
  4513. make shure that no unauthorized person could get this sensible data !
  4514. </ul>
  4515. <br><br>
  4516. <ul>
  4517. <li><b> get &lt;name&gt; storedCredentials </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM/SVS)</li> <br>
  4518. Shows the stored login credentials in a popup as plain text.
  4519. </ul>
  4520. <br><br>
  4521. <ul>
  4522. <li><b> get &lt;name&gt; svsinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(valid for CAM/SVS)</li> <br>
  4523. Determines common informations about the installed SVS-version and other properties. <br>
  4524. </ul>
  4525. <br><br>
  4526. <b>Polling of Camera/SVS-Properties</b><br><br>
  4527. <ul>
  4528. Retrieval of Camera-Properties can be done automatically if the attribute "pollcaminfoall" will be set to a value &gt; 10. <br>
  4529. As default that attribute "pollcaminfoall" isn't be set and the automatic polling isn't be active. <br>
  4530. The value of that attribute determines the interval of property-retrieval in seconds. If that attribute isn't be set or &lt; 10 the automatic polling won't be started <br>
  4531. respectively stopped when the value was set to &gt; 10 before. <br><br>
  4532. The attribute "pollcaminfoall" is monitored by a watchdog-timer. Changes of the attribute-value will be checked every 90 seconds and transact corresponding. <br>
  4533. Changes of the pollingstate and pollinginterval will be reported in FHEM-Logfile. The reporting can be switched off by setting the attribute "pollnologging=1". <br>
  4534. Thereby the needless growing of the logfile can be avoided. But if verbose level is set to 4 or above even though the attribute "pollnologging" is set as well, the polling <br>
  4535. will be actived due to analysis purposes. <br><br>
  4536. If FHEM will be restarted, the first data retrieval will be done within 60 seconds after start. <br><br>
  4537. The state of automatic polling will be displayed by reading "PollState": <br><br>
  4538. <ul>
  4539. <li><b> PollState = Active </b> - automatic polling will be executed with interval correspondig value of attribute "pollcaminfoall" </li>
  4540. <li><b> PollState = Inactive </b> - automatic polling won't be executed </li>
  4541. </ul>
  4542. <br>
  4543. The readings are described <a href="#SSCamreadings">here</a>. <br><br>
  4544. <b>Notes:</b> <br><br>
  4545. If polling is used, the interval should be adjusted only as short as needed due to the detected camera values are predominantly static. <br>
  4546. A feasible guide value for attribute "pollcaminfoall" could be between 600 - 1800 (s). <br>
  4547. Per polling call and camera approximately 10 - 20 Http-calls will are stepped against Surveillance Station. <br>
  4548. Because of that if HTTP-Timeout (pls. refer <a href="#SSCamattr">Attribut</a> "httptimeout") is set to 4 seconds, the theoretical processing time couldn't be higher than 80 seconds. <br>
  4549. Considering a safety margin, in that example you shouldn't set the polling interval lower than 160 seconds. <br><br>
  4550. If several Cameras are defined in SSCam, attribute "pollcaminfoall" of every Cameras shouldn't be set exactly to the same value to avoid processing bottlenecks <br>
  4551. and thereby caused potential source of errors during request Synology Surveillance Station. <br>
  4552. A marginal difference between the polling intervals of the defined cameras, e.g. 1 second, can already be faced as
  4553. sufficient value. <br><br>
  4554. </ul>
  4555. </ul>
  4556. <a name="SSCaminternals"></a>
  4557. <b>Internals</b> <br><br>
  4558. <ul>
  4559. The meaning of used Internals is depicted in following list: <br><br>
  4560. <ul>
  4561. <li><b>CAMID</b> - the ID of camera defined in SVS, the value will be retrieved automatically on the basis of SVS-cameraname </li>
  4562. <li><b>CAMNAME</b> - the name of the camera in SVS </li>
  4563. <li><b>CREDENTIALS</b> - the value is "Set" if Credentials are set </li>
  4564. <li><b>NAME</b> - the cameraname in FHEM </li>
  4565. <li><b>MODEL</b> - distinction between camera device (CAM) and Surveillance Station device (SVS) </li>
  4566. <li><b>OPMODE</b> - the last executed operation of the module </li>
  4567. <li><b>SERVERADDR</b> - IP-Address of SVS Host </li>
  4568. <li><b>SERVERPORT</b> - SVS-Port </li>
  4569. <br><br>
  4570. </ul>
  4571. </ul>
  4572. <a name="SSCamattr"></a>
  4573. <b>Attributes</b>
  4574. <br><br>
  4575. <ul>
  4576. <ul>
  4577. <li><b>debugactivetoken</b><br>
  4578. if set the state of active token will be logged - only for debugging, don't use it in normal operation ! </li><br>
  4579. <li><b>disable</b><br>
  4580. deactivates the module (device definition) </li><br>
  4581. <li><b>httptimeout</b><br>
  4582. Timeout-Value of HTTP-Calls to Synology Surveillance Station, Default: 4 seconds (if httptimeout = "0"
  4583. or not set) </li><br>
  4584. <li><b>htmlattr</b><br>
  4585. additional specifications to inline oictures to manipulate the behavior of stream, e.g. size of the image. </li><br>
  4586. <ul>
  4587. <b>Example:</b><br>
  4588. attr &lt;name&gt; htmlattr width="500" height="325" top="200" left="300"
  4589. </ul>
  4590. <br>
  4591. <li><b>livestreamprefix</b><br>
  4592. overwrites the specifications of protocol, servername and port for further use of the livestream address, e.g.
  4593. as an link to external use. It has to be specified as "http(s)://&lt;servername&gt;:&lt;port&gt;" </li><br>
  4594. <li><b>loginRetries</b><br>
  4595. set the amount of login-repetitions in case of failure (default = 1) </li><br>
  4596. <li><b>noQuotesForSID</b><br>
  4597. this attribute may be helpfull in some cases to avoid errormessage "402 - permission denied" and makes login
  4598. possible. </li><br>
  4599. <li><b>pollcaminfoall</b><br>
  4600. Interval of automatic polling the Camera properties (if < 10: no polling, if &gt; 10: polling with interval) </li><br>
  4601. <li><b>pollnologging</b><br>
  4602. "0" resp. not set = Logging device polling active (default), "1" = Logging device polling inactive</li><br>
  4603. <li><b>rectime</b><br>
  4604. determines the recordtime when a recording starts. If rectime = 0 an endless recording will be started. If
  4605. it isn't defined, the default recordtime of 15s is activated </li><br>
  4606. <li><b>recextend</b><br>
  4607. "rectime" of a started recording will be set new. Thereby the recording time of the running recording will be
  4608. extended </li><br>
  4609. <li><b>session</b><br>
  4610. selection of login-Session. Not set or set to "DSM" -&gt; session will be established to DSM (Sdefault).
  4611. "SurveillanceStation" -&gt; session will be established to SVS </li><br>
  4612. <li><b>simu_SVSversion</b><br>
  4613. simulates another SVS version. (only a lower version than the installed one is possible !) </li><br>
  4614. <li><b>snapGalleryBoost</b><br>
  4615. If set, the last snapshots (default 3) will be retrieved by Polling, will be stored in the FHEM-servers main memory
  4616. and can be displayed by the "set/get ... snapGallery" command. <br>
  4617. This mode is helpful if many or full size images shall be displayed.
  4618. If the attribute is set, you can't specify arguments in addition to the "set/get ... snapGallery" command.
  4619. (see also attribut "snapGalleryNumber") </li><br>
  4620. <li><b>snapGalleryColumns</b><br>
  4621. The number of snapshots which shall appear in one row of the gallery popup (default 3). </li><br>
  4622. <li><b>snapGalleryHtmlAttr</b><br>
  4623. the image parameter can be controlled by this attribute. <br>
  4624. If the attribute isn't set, the value of attribute "htmlattr" will be used. <br>
  4625. If "htmlattr" is also not set, default parameters are used instead (width="500" height="325"). <br><br>
  4626. <ul>
  4627. <b>Example:</b><br>
  4628. attr &lt;name&gt; snapGalleryHtmlAttr width="325" height="225"
  4629. </ul>
  4630. <br>
  4631. </li>
  4632. <li><b>snapGalleryNumber</b><br>
  4633. The number of snapshots to retrieve (default 3). </li><br>
  4634. <li><b>snapGallerySize</b><br>
  4635. By this attribute the quality of the snapshot images can be controlled (default "Icon"). <br>
  4636. If mode "Full" is set, the images are retrieved with their original available resolution. That requires more ressources
  4637. and may slow down the display. By setting attribute "snapGalleryBoost=1" the display may accelerated, because in that case
  4638. the images will be retrieved by continuous polling and need only bring to display. </li><br>
  4639. <li><b>showStmInfoFull</b><br>
  4640. additional stream informations like LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp will be created </li><br>
  4641. <li><b>showPassInLog</b><br>
  4642. if set the used password will be shown in logfile with verbose 4. (default = 0) </li><br>
  4643. <li><b>videofolderMap</b><br>
  4644. replaces the content of reading "VideoFolder", Usage if e.g. folders are mountet with different names than original
  4645. (SVS) </li><br>
  4646. <li><b>verbose</b></li><br>
  4647. <ul>
  4648. Different Verbose-Level are supported.<br>
  4649. Those are in detail:
  4650. <table>
  4651. <colgroup> <col width=5%> <col width=95%> </colgroup>
  4652. <tr><td> 0 </td><td>- Start/Stop-Event will be logged </td></tr>
  4653. <tr><td> 1 </td><td>- Error messages will be logged </td></tr>
  4654. <tr><td> 2 </td><td>- messages according to important events were logged </td></tr>
  4655. <tr><td> 3 </td><td>- sended commands will be logged </td></tr>
  4656. <tr><td> 4 </td><td>- sended and received informations will be logged </td></tr>
  4657. <tr><td> 5 </td><td>- all outputs will be logged for error-analyses. <b>Caution:</b> a lot of data could be written into logfile ! </td></tr>
  4658. </table>
  4659. </ul>
  4660. <br>
  4661. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  4662. </ul>
  4663. </ul>
  4664. <br><br>
  4665. <a name="SSCamreadings"></a>
  4666. <b>Readings</b>
  4667. <ul>
  4668. <br>
  4669. Using the polling mechanism or retrieval by "get"-call readings are provieded, The meaning of the readings are listed in subsequent table: <br>
  4670. The transfered Readings can be deversified dependend on the type of camera.<br><br>
  4671. <ul>
  4672. <table>
  4673. <colgroup> <col width=5%> <col width=95%> </colgroup>
  4674. <tr><td><li>Availability</li> </td><td>- Availability of Camera (disabled, enabled, disconnected, other) </td></tr>
  4675. <tr><td><li>CamEventNum</li> </td><td>- delivers the total number of in SVS registered events of the camera </td></tr>
  4676. <tr><td><li>CamExposureControl</li> </td><td>- indicating type of exposure control </td></tr>
  4677. <tr><td><li>CamExposureMode</li> </td><td>- current exposure mode (Day, Night, Auto, Schedule, Unknown) </td></tr>
  4678. <tr><td><li>CamForceEnableMulticast</li> </td><td>- Is the camera forced to enable multicast. </td></tr>
  4679. <tr><td><li>CamIP</li> </td><td>- IP-Address of Camera </td></tr>
  4680. <tr><td><li>CamLastRec</li> </td><td>- Path / name of the last recording </td></tr>
  4681. <tr><td><li>CamLastRecTime</li> </td><td>- date / starttime / endtime of the last recording </td></tr>
  4682. <tr><td><li>CamLiveMode</li> </td><td>- Source of Live-View (DS, Camera) </td></tr>
  4683. <tr><td><li>CamModel</li> </td><td>- Model of camera </td></tr>
  4684. <tr><td><li>CamMotDetSc</li> </td><td>- state of motion detection source (disabled, by camera, by SVS) and their parameter </td></tr>
  4685. <tr><td><li>CamNTPServer</li> </td><td>- set time server </td></tr>
  4686. <tr><td><li>CamPort</li> </td><td>- IP-Port of Camera </td></tr>
  4687. <tr><td><li>CamPreRecTime</li> </td><td>- Duration of Pre-Recording (in seconds) adjusted in SVS </td></tr>
  4688. <tr><td><li>CamRecShare</li> </td><td>- shared folder on disk station for recordings </td></tr>
  4689. <tr><td><li>CamRecVolume</li> </td><td>- Volume on disk station for recordings </td></tr>
  4690. <tr><td><li>CamVendor</li> </td><td>- Identifier of camera producer </td></tr>
  4691. <tr><td><li>CamVideoFlip</li> </td><td>- Is the video flip </td></tr>
  4692. <tr><td><li>CamVideoMirror</li> </td><td>- Is the video mirror </td></tr>
  4693. <tr><td><li>CamVideoRotate</li> </td><td>- Is the video rotate </td></tr>
  4694. <tr><td><li>CapAudioOut</li> </td><td>- Capability to Audio Out over Surveillance Station (false/true) </td></tr>
  4695. <tr><td><li>CapChangeSpeed</li> </td><td>- Capability to various motion speed </td></tr>
  4696. <tr><td><li>CapPTZAbs</li> </td><td>- Capability to perform absolute PTZ action </td></tr>
  4697. <tr><td><li>CapPTZAutoFocus</li> </td><td>- Capability to perform auto focus action </td></tr>
  4698. <tr><td><li>CapPTZDirections</li> </td><td>- the PTZ directions that camera support </td></tr>
  4699. <tr><td><li>CapPTZFocus</li> </td><td>- mode of support for focus action </td></tr>
  4700. <tr><td><li>CapPTZHome</li> </td><td>- Capability to perform home action </td></tr>
  4701. <tr><td><li>CapPTZIris</li> </td><td>- mode of support for iris action </td></tr>
  4702. <tr><td><li>CapPTZPan</li> </td><td>- Capability to perform pan action </td></tr>
  4703. <tr><td><li>CapPTZTilt</li> </td><td>- mode of support for tilt action </td></tr>
  4704. <tr><td><li>CapPTZZoom</li> </td><td>- Capability to perform zoom action </td></tr>
  4705. <tr><td><li>DeviceType</li> </td><td>- device type (Camera, Video_Server, PTZ, Fisheye) </td></tr>
  4706. <tr><td><li>Error</li> </td><td>- message text of last error </td></tr>
  4707. <tr><td><li>Errorcode</li> </td><td>- error code of last error </td></tr>
  4708. <tr><td><li>HomeModeState</li> </td><td>- HomeMode-state (SVS-version 8.1.0 and above) </td></tr>
  4709. <tr><td><li>LastLogEntry</li> </td><td>- the neweset entry of Surveillance Station Log (only if SVS-device and if attribute pollcaminfoall is set) </td></tr>
  4710. <tr><td><li>LastSnapFilename</li> </td><td>- the filename of the last snapshot </td></tr>
  4711. <tr><td><li>LastSnapId</li> </td><td>- the ID of the last snapshot </td></tr>
  4712. <tr><td><li>LastSnapTime</li> </td><td>- timestamp of the last snapshot </td></tr>
  4713. <tr><td><li>LastUpdateTime</li> </td><td>- date / time the last update of readings by "caminfoall" </td></tr>
  4714. <tr><td><li>LiveStreamUrl </li> </td><td>- the livestream URL if stream is started (is shown if <a href="#SSCamattr">attribute</a> "showStmInfoFull" is set) </td></tr>
  4715. <tr><td><li>Patrols</li> </td><td>- in Synology Surveillance Station predefined patrols (at PTZ-Cameras) </td></tr>
  4716. <tr><td><li>PollState</li> </td><td>- shows the state of automatic polling </td></tr>
  4717. <tr><td><li>Presets</li> </td><td>- in Synology Surveillance Station predefined Presets (at PTZ-Cameras) </td></tr>
  4718. <tr><td><li>Record</li> </td><td>- if recording is running = Start, if no recording is running = Stop </td></tr>
  4719. <tr><td><li>StmKey</li> </td><td>- current streamkey. it can be used to open livestreams without session id </td></tr>
  4720. <tr><td><li>StmKeyUnicst</li> </td><td>- Uni-cast stream path of the camera. (<a href="#SSCamattr">attribute</a> "showStmInfoFull" has to be set) </td></tr>
  4721. <tr><td><li>StmKeymjpegHttp</li> </td><td>- Mjpeg stream path(over http) of the camera (<a href="#SSCamattr">attribute</a> "showStmInfoFull" has to be set) </td></tr>
  4722. <tr><td><li>SVScustomPortHttp</li> </td><td>- Customized port of Surveillance Station (HTTP) (to get with "svsinfo") </td></tr>
  4723. <tr><td><li>SVScustomPortHttps</li> </td><td>- Customized port of Surveillance Station (HTTPS) (to get with "svsinfo") </td></tr>
  4724. <tr><td><li>SVSlicenseNumber</li> </td><td>- The total number of installed licenses (to get with "svsinfo") </td></tr>
  4725. <tr><td><li>SVSuserPriv</li> </td><td>- The effective rights of the user used for log in (to get with "svsinfo") </td></tr>
  4726. <tr><td><li>SVSversion</li> </td><td>- package version of the installed Surveillance Station (to get with "svsinfo") </td></tr>
  4727. <tr><td><li>UsedSpaceMB</li> </td><td>- used disk space of recordings by Camera </td></tr>
  4728. <tr><td><li>VideoFolder</li> </td><td>- Path to the recorded video </td></tr>
  4729. </table>
  4730. </ul>
  4731. <br><br>
  4732. </ul>
  4733. </ul>
  4734. =end html
  4735. =begin html_DE
  4736. <a name="SSCam"></a>
  4737. <h3>SSCam</h3>
  4738. <ul>
  4739. Mit diesem Modul können Operationen von in der Synology Surveillance Station (SVS) definierten Kameras und Funktionen
  4740. der SVS ausgeführt werden. Es basiert auf der SVS API und unterstützt die SVS ab Version 7. <br>
  4741. Zur Zeit werden folgende Funktionen unterstützt: <br><br>
  4742. <ul>
  4743. <ul>
  4744. <li>Start einer Aufnahme</li>
  4745. <li>Stop einer Aufnahme (per Befehl bzw. automatisch nach Ablauf der Aufnahmedauer) </li>
  4746. <li>Aufnehmen eines Schnappschusses und Ablage in der Synology Surveillance Station </li>
  4747. <li>Deaktivieren einer Kamera in Synology Surveillance Station</li>
  4748. <li>Aktivieren einer Kamera in Synology Surveillance Station</li>
  4749. <li>Steuerung der Belichtungsmodi Tag, Nacht bzw. Automatisch </li>
  4750. <li>Umschaltung der Ereigniserkennung durch Kamera, durch SVS oder deaktiviert </li>
  4751. <li>steuern der Erkennungsparameterwerte Empfindlichkeit, Schwellwert, Objektgröße und Prozentsatz für Auslösung </li>
  4752. <li>Abfrage von Kameraeigenschaften (auch mit Polling) sowie den Eigenschaften des installierten SVS-Paketes</li>
  4753. <li>Bewegen an eine vordefinierte Preset-Position (bei PTZ-Kameras) </li>
  4754. <li>Start einer vordefinierten Überwachungstour (bei PTZ-Kameras) </li>
  4755. <li>Positionieren von PTZ-Kameras zu absoluten X/Y-Koordinaten </li>
  4756. <li>kontinuierliche Bewegung von PTZ-Kameras </li>
  4757. <li>auslösen externer Ereignisse 1-10 (Aktionsregel SVS) </li>
  4758. <li>starten und beenden von Kamera-Livestreams, anzeigen der letzten Aufnahme oder des letzten Schnappschusses </li>
  4759. <li>Abruf und Ausgabe der Kamera Streamkeys sowie Stream-Urls (Nutzung von Kamera-Livestreams ohne Session Id) </li>
  4760. <li>abspielen der letzten Aufnahme bzw. Anzeige des letzten Schnappschusses </li>
  4761. <li>anzeigen der gespeicherten Anmeldeinformationen (Credentials) </li>
  4762. <li>Ein- bzw. Ausschalten des Surveillance Station HomeMode und abfragen des HomeMode-Status </li>
  4763. <li>abrufen des Surveillance Station Logs, auswerten des neuesten Eintrags als Reading </li>
  4764. <li>erzeugen einer Gallerie der letzten 1-10 Schnappschüsse (als Popup oder permanentes Device) </li><br>
  4765. </ul>
  4766. </ul>
  4767. Die Aufnahmen stehen in der Synology Surveillance Station (SVS) zur Verfügung und unterliegen, wie jede andere Aufnahme, den in der Synology Surveillance Station eingestellten Regeln. <br>
  4768. So werden zum Beispiel die Aufnahmen entsprechend ihrer Archivierungsfrist gespeichert und dann gelöscht. <br><br>
  4769. Wenn sie über dieses Modul diskutieren oder zur Verbesserung des Moduls beitragen möchten, ist im FHEM-Forum ein Sammelplatz unter:<br>
  4770. <a href="http://forum.fhem.de/index.php/topic,45671.msg374390.html#msg374390">49_SSCam: Fragen, Hinweise, Neuigkeiten und mehr rund um dieses Modul</a>.<br><br>
  4771. Weitere Infomationen zum Modul sind im FHEM-Wiki zu finden:<br>
  4772. <a href="http://www.fhemwiki.de/wiki/SSCAM_-_Steuerung_von_Kameras_in_Synology_Surveillance_Station">SSCAM - Steuerung von Kameras in Synology Surveillance Station</a>.<br><br>
  4773. <b>Vorbereitung </b> <br><br>
  4774. Dieses Modul nutzt das Perl-Modul JSON. <br>
  4775. Auf Debian-Linux basierenden Systemen kann es installiert werden mit: <br><br>
  4776. <code>sudo apt-get install libjson-perl</code> <br><br>
  4777. Das Modul verwendet für HTTP-Calls die nichtblockierenden Funktionen von HttpUtils bzw. HttpUtils_NonblockingGet. <br>
  4778. Im DSM bzw. der Synology Surveillance Station muß ein Nutzer angelegt sein. Die Zugangsdaten werden später über ein Set-Kommando dem angelegten Gerät zugewiesen. <br>
  4779. Nähere Informationen dazu unter <a href="#SSCam_Credentials">Credentials</a><br><br>
  4780. Überblick über die Perl-Module welche von SSCam genutzt werden: <br><br>
  4781. JSON <br>
  4782. Data::Dumper <br>
  4783. MIME::Base64 <br>
  4784. Time::HiRes <br>
  4785. HttpUtils (FHEM-Modul) <br><br>
  4786. <a name="SSCamdefine"></a>
  4787. <b>Definition</b>
  4788. <ul>
  4789. <br>
  4790. Bei der Definition wird zwischen einer Kamera-Definition und der Definition einer Surveillance Station (SVS)
  4791. unterschieden. Abhängig von der Art des definierten Devices wird das Internal MODEL auf CAM oder SVS gesetzt und eine
  4792. passende Teilmenge der beschriebenen set/get-Befehle dem Device zugewiesen. <br>
  4793. Der Gültigkeitsbereich von set/get-Befehlen ist nach dem jeweiligen Befehl angegeben (gilt für CAM, SVS, CAM/SVS).
  4794. <br><br>
  4795. Eine Kamera wird definiert durch: <br><br>
  4796. <code>define &lt;name&gt; SSCAM &lt;Kameraname in SVS&gt; &lt;ServerAddr&gt; [Port] </code> <br><br>
  4797. Zunächst muß diese Kamera in der Synology Surveillance Station 7.0 oder höher eingebunden sein und entsprechend
  4798. funktionieren. <br><br>
  4799. Ein SVS-Device zur Steuerung von Funktionen der Surveillance Station wird definiert mit: <br><br>
  4800. <code>define &lt;name&gt; SSCAM SVS &lt;ServerAddr&gt; [Port] </code> <br><br>
  4801. In diesem Fall wird statt &lt;Kameraname in SVS&gt; nur <b>SVS</b> angegeben. <br><br>
  4802. Das Modul SSCam basiert auf Funktionen der Synology Surveillance Station API. <br>
  4803. Momentan wird nur das HTTP-Protokoll unterstützt um die Web-Services der Synology DS aufzurufen. <br><br>
  4804. Die Parameter beschreiben im Einzelnen:
  4805. <br>
  4806. <br>
  4807. <table>
  4808. <colgroup> <col width=15%> <col width=85%> </colgroup>
  4809. <tr><td>name: </td><td>der Name des neuen Gerätes in FHEM</td></tr>
  4810. <tr><td>Kameraname: </td><td>Kameraname wie er in der Synology Surveillance Station angegeben ist für Kamera-Device, "SVS" für SVS-Device. Leerzeichen im Namen sind nicht erlaubt. </td></tr>
  4811. <tr><td>ServerAddr: </td><td>die IP-Addresse des Synology Surveillance Station Host. Hinweis: Es sollte kein Servername verwendet werden weil DNS-Aufrufe in FHEM blockierend sind.</td></tr>
  4812. <tr><td>Port: </td><td>optional - der Port der Synology Surveillance Station. Wenn nicht angegeben wird der Default-Port 5000 (nur HTTP) gesetzt </td></tr>
  4813. </table>
  4814. <br><br>
  4815. <b>Beispiel:</b>
  4816. <pre>
  4817. <code>define CamCP SSCAM Carport 192.168.2.20 [5000] </code>
  4818. erstellt ein neues Kamera-Device CamCP
  4819. <code>define DS1 SSCAM SVS 192.168.2.20 [5000] </code>
  4820. erstellt ein neues SVS-Device DS1
  4821. </pre>
  4822. Wird eine neue Kamera definiert, wird diesem Device zunächst eine Standardaufnahmedauer von 15 zugewiesen. <br>
  4823. Über das <a href="#SSCamattr">Attribut</a> "rectime" kann die Aufnahmedauer für jede Kamera individuell angepasst werden. Der Wert "0" für "rectime" führt zu einer Endlosaufnahme, die durch "set &lt;name&gt; off" wieder gestoppt werden muß. <br>
  4824. Ein Logeintrag mit einem entsprechenden Hinweis auf diesen Umstand wird geschrieben. <br><br>
  4825. Wird das <a href="#SSCamattr">Attribut</a> "rectime" gelöscht, greift wieder der Default-Wert (15s) für die Aufnahmedauer. <br><br>
  4826. Mit dem <a href="#SSCamset">Befehl</a> <b>"set &lt;name&gt; on [rectime]"</b> wird die Aufnahmedauer temporär festgelegt und überschreibt einmalig sowohl den Defaultwert als auch den Wert des gesetzten Attributs "rectime". <br>
  4827. Auch in diesem Fall führt <b>"set &lt;name&gt; on 0"</b> zu einer Daueraufnahme. <br><br>
  4828. Eine eventuell in der SVS eingestellte Dauer der Voraufzeichnung wird weiterhin berücksichtigt. <br><br><br>
  4829. <a name="SSCam_Credentials"></a>
  4830. <b>Credentials </b><br><br>
  4831. Nach dem Definieren des Gerätes müssen zuerst die Zugangsparameter gespeichert werden. Das geschieht mit dem Befehl:
  4832. <pre>
  4833. set &lt;name&gt; credentials &lt;Username&gt; &lt;Passwort&gt;
  4834. </pre>
  4835. Die Passwortlänge beträgt maximal 20 Zeichen. <br>
  4836. Der Anwender kann in Abhängigkeit der beabsichtigten einzusetzenden Funktionen einen Nutzer im DSM bzw. in der Surveillance Station einrichten. <br>
  4837. Ist der DSM-Nutzer der Gruppe Administratoren zugeordnet, hat er auf alle Funktionen Zugriff. Ohne diese Gruppenzugehörigkeit können nur Funktionen mit niedrigeren <br>
  4838. Rechtebedarf ausgeführt werden. Die benötigten Mindestrechte der Funktionen sind in der Tabelle weiter unten aufgeführt. <br>
  4839. Alternativ zum DSM-Nutzer kann ein in der SVS angelegter Nutzer verwendet werden. Auch in diesem Fall hat ein Nutzer vom Typ Manager das Recht alle Funktionen <br>
  4840. auszuführen, wobei der Zugriff auf bestimmte Kameras/ im Privilegienprofil beschränkt werden kann (siehe Hilfefunktion in SVS). <br>
  4841. Als Best Practice wird vorgeschlagen jeweils einen User im DSM und einen in der SVS anzulegen: <br><br>
  4842. <ul>
  4843. <li>DSM-User als Mitglied der Admin-Gruppe: uneingeschränkter Test aller Modulfunktionen -> session:DSM </li>
  4844. <li>SVS-User als Manager oder Betrachter: angepasstes Privilegienprofil -> session: SurveillanceStation </li>
  4845. </ul>
  4846. <br>
  4847. Über das <a href="#SSCamattr">Attribut</a> "session" kann ausgewählt werden, ob die Session mit dem DSM oder der SVS augebaut werden soll. <br>
  4848. Erfolgt der Session-Aufbau mit dem DSM, stehen neben der SVS Web-API auch darüber hinaus gehende API-Zugriffe zur Verfügung die unter Umständen zur Verarbeitung benötigt werden. <br><br>
  4849. Nach der Gerätedefinition ist die Grundeinstellung "Login in das DSM", d.h. es können Credentials mit Admin-Berechtigungen genutzt werden um zunächst alle <br>
  4850. Funktionen der Kameras testen zu können. Danach können die Credentials z.B. in Abhängigkeit der benötigten Funktionen auf eine SVS-Session mit entsprechend beschränkten Privilegienprofil umgestellt werden. <br><br>
  4851. Die nachfolgende Aufstellung zeigt die Mindestanforderungen der jeweiligen Modulfunktionen an die Nutzerrechte. <br><br>
  4852. <ul>
  4853. <table>
  4854. <colgroup> <col width=20%> <col width=80%> </colgroup>
  4855. <tr><td><li>set ... credentials </td><td> - </li></td></tr>
  4856. <tr><td><li>set ... disable </td><td> session: ServeillanceStation - Manager </li></td></tr>
  4857. <tr><td><li>set ... enable </td><td> session: ServeillanceStation - Manager </li></td></tr>
  4858. <tr><td><li>set ... expmode </td><td> session: ServeillanceStation - Manager </li></td></tr>
  4859. <tr><td><li>set ... extevent </td><td> session: DSM - Nutzer Mitglied von Admin-Gruppe </li></td></tr>
  4860. <tr><td><li>set ... goPreset </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  4861. <tr><td><li>set ... homeMode </td><td> session: ServeillanceStation - Betrachter mit Privileg Home-Modus schalten </li></td></tr>
  4862. <tr><td><li>set ... goAbsPTZ </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  4863. <tr><td><li>set ... move </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  4864. <tr><td><li>set ... motdetsc </td><td> session: ServeillanceStation - Manager </li></td></tr>
  4865. <tr><td><li>set ... on </td><td> session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme" </li></td></tr>
  4866. <tr><td><li>set ... off </td><td> session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme" </li></td></tr>
  4867. <tr><td><li>set ... runView </td><td> session: ServeillanceStation - Betrachter mit Privileg Liveansicht für Kamera </li></td></tr>
  4868. <tr><td><li>set ... runPatrol </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  4869. <tr><td><li>set ... snap </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4870. <tr><td><li>set ... snapGallery </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4871. <tr><td><li>set ... stopView </td><td> - </li></td></tr>
  4872. <tr><td><li>get ... caminfo[all] </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4873. <tr><td><li>get ... eventlist </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4874. <tr><td><li>get ... listLog </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4875. <tr><td><li>get ... scanVirgin </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4876. <tr><td><li>get ... svsinfo </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4877. <tr><td><li>get ... snapfileinfo </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4878. <tr><td><li>get ... snapGallery </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4879. <tr><td><li>get ... snapinfo </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4880. <tr><td><li>get ... stmUrlPath </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  4881. </table>
  4882. </ul>
  4883. <br><br>
  4884. <a name="SSCam_HTTPTimeout"></a>
  4885. <b>HTTP-Timeout setzen</b><br><br>
  4886. Alle Funktionen dieses Moduls verwenden HTTP-Aufrufe gegenüber der SVS Web API. <br>
  4887. Der Standardwert für den HTTP-Timeout beträgt 4 Sekunden. Durch Setzen des <a href="#SSCamattr">Attributes</a> "httptimeout" > 0 kann dieser Wert bei Bedarf entsprechend den technischen Gegebenheiten angepasst werden. <br>
  4888. </ul>
  4889. <br><br><br>
  4890. <a name="SSCamset"></a>
  4891. <b>Set </b>
  4892. <ul>
  4893. <br>
  4894. Die aufgeführten set-Befehle sind für CAM/SVS-Devices oder nur für CAM-Devices bzw. nur für SVS-Devices gültig. Sie stehen im
  4895. Drop-Down-Menü des jeweiligen Devices zur Auswahl zur Verfügung. <br><br>
  4896. <ul>
  4897. <li><b> set &lt;name&gt; credentials &lt;username&gt; &lt;password&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM/SVS)</li> <br>
  4898. Setzt Username / Passwort für den Zugriff auf die Synology Surveillance Station.
  4899. Siehe <a href="#SSCam_Credentials">Credentials</a><br>
  4900. <br><br>
  4901. </ul>
  4902. <ul>
  4903. <li><b> set &lt;name&gt; createSnapGallery </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4904. Es wird eine Schnappschußgallerie als permanentes (weblink)Device erzeugt. Das Device wird im Raum "SnapGallery" erstellt.
  4905. Mit den "snapGallery..."-<a href="#SSCamattr">Attributen</a> bzw. den spezifischen Attributen des entstandenen Weblink-Devices
  4906. können die Eigenschaften der Schnappschußgallerie beeinflusst werden. <br>
  4907. <br><br>
  4908. </ul>
  4909. <ul>
  4910. <li><b> set &lt;name&gt; [enable|disable] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4911. Aktviviert / deaktiviert eine Kamera. <br>
  4912. Um eine Liste von Kameras oder alle Kameras (mit Regex) zum Beispiel um 21:46 zu <b>deaktivieren</b> / zu <b>aktivieren</b> zwei Beispiele mit at:
  4913. <pre>
  4914. define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
  4915. define a14 at 21:46 set Cam.* disable (enable)
  4916. </pre>
  4917. Etwas komfortabler gelingt das Schalten aller Kameras über einen Dummy. Zunächst wird der Dummy angelegt:
  4918. <pre>
  4919. define allcams dummy
  4920. attr allcams eventMap on:enable off:disable
  4921. attr allcams room Cams
  4922. attr allcams webCmd enable:disable
  4923. </pre>
  4924. Durch Verknüpfung mit zwei angelegten notify, jeweils ein notify für "enable" und "disable", kann man durch Schalten des Dummys auf "enable" bzw. "disable" alle Kameras auf einmal aktivieren bzw. deaktivieren.
  4925. <pre>
  4926. define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
  4927. attr all_cams_disable room Cams
  4928. define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
  4929. attr all_cams_enable room Cams
  4930. </pre>
  4931. </ul>
  4932. <br>
  4933. <ul>
  4934. <li><b> set &lt;name&gt; expmode [day|night|auto] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4935. Mit diesem Befehl kann der Belichtungsmodus der Kameras gesetzt werden. Dadurch wird z.B. das Verhalten der Kamera-LED's entsprechend gesteuert.
  4936. Die erfolgreiche Umschaltung wird durch das Reading CamExposureMode ("get ... caminfoall") reportet. <br><br>
  4937. <b> Hinweis: </b> <br>
  4938. Die erfolgreiche Ausführung dieser Funktion ist davon abhängig ob die SVS diese Funktionalität der Kamera unterstützt.
  4939. Ist in SVS -&gt; IP-Kamera -&gt; Optimierung -&gt; Belichtungsmodus das Feld für den Tag/Nachtmodus grau hinterlegt, ist nicht von einer lauffähigen Unterstützung dieser
  4940. Funktion auszugehen.
  4941. <br><br>
  4942. </ul>
  4943. <ul>
  4944. <li><b> set &lt;name&gt; extevent [ 1-10 ] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für SVS)</li> <br>
  4945. Dieses Kommando triggert ein externes Ereignis (1-10) in der SVS.
  4946. Die Aktionen, die dieses Ereignis auslöst, sind zuvor in dem Aktionsregeleditor der SVS einzustellen. Es stehen die Ereignisse
  4947. 1-10 zur Verfügung.
  4948. In der Benachrichtigungs-App der SVS können auch Email, SMS oder Mobil (DS-Cam) Nachrichten ausgegeben werden wenn ein externes
  4949. Ereignis ausgelöst wurde.
  4950. Nähere Informationen dazu sind in der Hilfe zum Aktionsregeleditor zu finden.
  4951. Der verwendete User benötigt Admin-Rechte in einer DSM-Session.
  4952. </ul>
  4953. <br><br>
  4954. <ul>
  4955. <li><b> set &lt;name&gt; goAbsPTZ [ X Y | up | down | left | right ] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4956. Mit diesem Kommando wird eine PTZ-Kamera in Richtung einer wählbaren absoluten X/Y-Koordinate bewegt, oder zur maximalen Absolutposition in Richtung up/down/left/right.
  4957. Die Option ist nur für Kameras verfügbar die das Reading "CapPTZAbs=true" (die Fähigkeit für PTZAbs-Aktionen) besitzen. Die Eigenschaften der Kamera kann mit "get &lt;name&gt; caminfoall" abgefragt werden.
  4958. <br><br>
  4959. Beispiel für Ansteuerung absoluter X/Y-Koordinaten: <br>
  4960. <pre>
  4961. set &lt;name&gt; goAbsPTZ 120 450
  4962. </pre>
  4963. Dieses Beispiel bewegt die Kameralinse in die Position X=120 und Y=450. <br>
  4964. Der Wertebereich ist dabei:
  4965. <pre>
  4966. X = 0 - 640 (0 - 319 bewegt nach links, 321 - 640 bewegt nach rechts, 320 bewegt die Linse nicht)
  4967. Y = 0 - 480 (0 - 239 bewegt nach unten, 241 - 480 bewegt nach oben, 240 bewegt die Linse nicht)
  4968. </pre>
  4969. Die Linse kann damit in kleinsten bis sehr großen Schritten in die gewünschte Richtung bewegt werden.
  4970. Dieser Vorgang muß ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen. <br><br>
  4971. Soll die Bewegung mit der maximalen Schrittweite erfolgen, kann zur Vereinfachung der Befehl:
  4972. <pre>
  4973. set &lt;name&gt; goAbsPTZ [up|down|left|right]
  4974. </pre>
  4975. verwendet werden. Die Optik wird in diesem Fall mit der größt möglichen Schrittweite zur Absolutposition in der angegebenen Richtung bewegt.
  4976. Auch in diesem Fall muß der Vorgang ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen.
  4977. </ul>
  4978. <br><br>
  4979. <ul>
  4980. <li><b> set &lt;name&gt; goPreset &lt;Preset&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  4981. Mit diesem Kommando können PTZ-Kameras in eine vordefininierte Position bewegt werden. <br>
  4982. Die Preset-Positionen müssen dazu zunächst in der Synology Surveillance Station angelegt worden sein. Das geschieht in der PTZ-Steuerung im IP-Kamera Setup.
  4983. Die Presets werden über das Kommando "get &lt;name&gt; caminfoall" eingelesen (geschieht bei restart von FHEM automatisch). Der Einlesevorgang kann durch ein Kamerapolling
  4984. regelmäßig wiederholt werden. Ein langes Pollingintervall ist in diesem Fall empfehlenswert, da sich die Presetpositionen nur im Fall der Neuanlage bzw. Änderung verändern werden.
  4985. <br><br>
  4986. Hier ein Beispiel einer PTZ-Steuerung in Abhängigkeit eines IR-Melder Events:
  4987. <pre>
  4988. define CamFL.Preset.Wandschrank notify MelderTER:on.* set CamFL goPreset Wandschrank, ;; define CamFL.Preset.record at +00:00:10 set CamFL on 5 ;;;; define s3 at +*{3}00:00:05 set CamFL snap ;; define CamFL.Preset.back at +00:00:30 set CamFL goPreset Home
  4989. </pre>
  4990. Funktionsweise: <br>
  4991. Der IR-Melder "MelderTER" registriert eine Bewegung. Daraufhin wird die Kamera CamFL in die Preset-Position "Wandschrank" gebracht. Eine Aufnahme mit Dauer von 5 Sekunden startet 10 Sekunden
  4992. später. Da die Voraufnahmezeit der Kamera 10s beträgt (vgl. Reading "CamPreRecTime"), startet die effektive Aufnahme wenn der Kameraschwenk beginnt. <br>
  4993. Mit dem Start der Aufnahme werden drei Schnappschüsse im Abstand von 5 Sekunden angefertigt. <br>
  4994. Nach einer Zeit von 30 Sekunden fährt die Kamera wieder zurück in die "Home"-Position. <br><br>
  4995. Ein Auszug aus dem Log verdeutlicht den Ablauf:
  4996. <pre>
  4997. 2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
  4998. 2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
  4999. 2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  5000. 2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
  5001. 2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  5002. 2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  5003. 2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
  5004. </pre>
  5005. </ul>
  5006. <br><br>
  5007. <ul>
  5008. <li><b> set &lt;name&gt; homeMode [on|off] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für SVS)</li> <br>
  5009. Schaltet den HomeMode der Surveillance Station ein bzw. aus.
  5010. Informationen zum HomeMode sind in der <a href="https://www.synology.com/de-de/knowledgebase/Surveillance/help/SurveillanceStation/home_mode">Synology Onlinehilfe</a>
  5011. enthalten.
  5012. <br><br>
  5013. </ul>
  5014. <ul>
  5015. <li><b> set &lt;name&gt; motdetsc [camera|SVS|disable] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5016. Der Befehl "motdetsc" (steht für motion detection source) schaltet die Bewegungserkennung in den gewünschten Modus.
  5017. Wird die Bewegungserkennung durch die Kamera / SVS ohne weitere Optionen eingestellt, werden die momentan gültigen Bewegungserkennungsparameter der
  5018. Kamera / SVS beibehalten. Die erfolgreiche Ausführung der Operation lässt sich u.a. anhand des Status von SVS -&gt; IP-Kamera -&gt; Ereigniserkennung -&gt;
  5019. Bewegung nachvollziehen. <br><br>
  5020. Für die Bewegungserkennung durch SVS bzw. durch Kamera können weitere Optionen angegeben werden. Die verfügbaren Optionen bezüglich der Bewegungserkennung
  5021. durch SVS sind "Empfindlichkeit" und "Schwellwert". <br><br>
  5022. <ul>
  5023. <table>
  5024. <colgroup> <col width=50%> <col width=50%> </colgroup>
  5025. <tr><td>set &lt;name&gt; motdetsc SVS [Empfindlichkeit] [Schwellwert] </td><td># Befehlsmuster </td></tr>
  5026. <tr><td>set &lt;name&gt; motdetsc SVS 91 30 </td><td># setzt die Empfindlichkeit auf 91 und den Schwellwert auf 30 </td></tr>
  5027. <tr><td>set &lt;name&gt; motdetsc SVS 0 40 </td><td># behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40 </td></tr>
  5028. <tr><td>set &lt;name&gt; motdetsc SVS 15 </td><td># setzt die Empfindlichkeit auf 15, Schwellwert bleibt unverändert </td></tr>
  5029. </table>
  5030. </ul>
  5031. <br><br>
  5032. Wird die Bewegungserkennung durch die Kamera genutzt, stehen die Optionen "Empfindlichkeit", "Objektgröße" und "Prozentsatz für Auslösung" zur Verfügung. <br><br>
  5033. <ul>
  5034. <table>
  5035. <colgroup> <col width=50%> <col width=50%> </colgroup>
  5036. <tr><td>set &lt;name&gt; motdetsc camera [Empfindlichkeit] [Schwellwert] [Prozentsatz] </td><td># Befehlsmuster </td></tr>
  5037. <tr><td>set &lt;name&gt; motdetsc camera 89 0 20 </td><td># setzt die Empfindlichkeit auf 89, Prozentsatz auf 20 </td></tr>
  5038. <tr><td>set &lt;name&gt; motdetsc camera 0 40 10 </td><td># behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40, Prozentsatz auf 10 </td></tr>
  5039. <tr><td>set &lt;name&gt; motdetsc camera 30 </td><td># setzt die Empfindlichkeit auf 30, andere Werte bleiben unverändert </td></tr>
  5040. </table>
  5041. </ul>
  5042. <br><br>
  5043. Es ist immer die Reihenfolge der Optionswerte zu beachten. Nicht gewünschte Optionen sind mit "0" zu besetzen sofern danach Optionen folgen
  5044. deren Werte verändert werden sollen (siehe Beispiele oben). Der Zahlenwert der Optionen beträgt 1 - 99 (außer Sonderfall "0"). <br><br>
  5045. Die jeweils verfügbaren Optionen unterliegen der Funktion der Kamera und der Unterstützung durch die SVS. Es können jeweils nur die Optionen genutzt werden die in
  5046. SVS -&gt; Kamera bearbeiten -&gt; Ereigniserkennung zur Verfügung stehen. Weitere Infos sind der Online-Hilfe zur SVS zu entnehmen. <br><br>
  5047. Über den Befehl "get &lt;name&gt; caminfoall" wird auch das <a href="#SSCamreadings">Reading</a> "CamMotDetSc" aktualisiert welches die gegenwärtige Einstellung der Bewegungserkennung dokumentiert.
  5048. Es werden nur die Parameter und Parameterwerte angezeigt, welche die SVS aktiv unterstützt. Die Kamera selbst kann weiterführende Einstellmöglichkeiten besitzen. <br><br>
  5049. Beipiel:
  5050. <pre>
  5051. CamMotDetSc SVS, sensitivity: 76, threshold: 55
  5052. </pre>
  5053. <br><br>
  5054. </ul>
  5055. <ul>
  5056. <li><b> set &lt;name&gt; move [ right | up | down | left | dir_X ] [Sekunden] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM bis SVS Version 7.1)</li>
  5057. <b> set &lt;name&gt; move [ right | upright | up | upleft | left | downleft | down | downright ] [Sekunden] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM ab SVS Version 7.2) <br><br>
  5058. Mit diesem Kommando wird eine kontinuierliche Bewegung der PTZ-Kamera gestartet. Neben den vier Grundrichtungen up/down/left/right stehen auch
  5059. Zwischenwinkelmaße "dir_X" zur Verfügung. Die Feinheit dieser Graduierung ist von der Kamera abhängig und kann dem Reading "CapPTZDirections" entnommen werden. <br><br>
  5060. Das Bogenmaß von 360 Grad teilt sich durch den Wert von "CapPTZDirections" und beschreibt die Bewegungsrichtungen beginnend mit "0=rechts" entgegen dem
  5061. Uhrzeigersinn. D.h. bei einer Kamera mit "CapPTZDirections = 8" bedeutet dir_0 = rechts, dir_2 = oben, dir_4 = links, dir_6 = unten bzw. dir_1, dir_3, dir_5 und dir_7
  5062. die entsprechenden Zwischenrichtungen. Die möglichen Bewegungsrichtungen bei Kameras mit "CapPTZDirections = 32" sind dementsprechend kleinteiliger. <br><br>
  5063. Im Gegensatz zum "set &lt;name&gt; goAbsPTZ"-Befehl startet der Befehl "set &lt;name&gt; move" eine kontinuierliche Bewegung bis ein Stop-Kommando empfangen wird.
  5064. Das Stop-Kommando wird nach Ablauf der optional anzugebenden Zeit [Sekunden] ausgelöst. Wird diese Laufzeit nicht angegeben, wird implizit Sekunde = 1 gesetzt. <br><br>
  5065. <b>Beispiele: </b><br>
  5066. <pre>
  5067. set &lt;name&gt; move up 0.5 : bewegt PTZ 0,5 Sek. (zzgl. Prozesszeit) nach oben
  5068. set &lt;name&gt; move dir_1 1.5 : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach rechts-oben
  5069. set &lt;name&gt; move dir_20 0.7 : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach links-unten ("CapPTZDirections = 32)"
  5070. </pre>
  5071. </ul>
  5072. <br><br>
  5073. <ul>
  5074. <li><b> set &lt;name&gt; [on|off] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li><br>
  5075. Der Befehl "set &lt;name&gt; on" startet eine Aufnahme. Die Standardaufnahmedauer beträgt 15 Sekunden. Sie kann mit dem Attribut "rectime" individuell festgelegt werden.
  5076. Die im Attribut (bzw. im Standard) hinterlegte Aufnahmedauer kann einmalig mit "set &lt;name&gt; on [rectime]" überschrieben werden.
  5077. Die Aufnahme stoppt automatisch nach Ablauf der Zeit "rectime".<br>
  5078. Ein Sonderfall ist der Start einer Daueraufnahme mit "set &lt;name&gt; on 0" bzw. dem Attributwert "rectime = 0". In diesem Fall wird eine Daueraufnahme gestartet die
  5079. explizit wieder mit dem Befehl "set &lt;name&gt; off" gestoppt werden muß.<br>
  5080. Das Aufnahmeverhalten kann weiterhin mit dem Attribut "recextend" wie folgt beeinflusst werden.<br><br>
  5081. <b>Attribut "recextend = 0" bzw. nicht gesetzt (Standard):</b><br><br>
  5082. <ul>
  5083. <li> wird eine Aufnahme mit z.B. rectime=22 gestartet, wird kein weiterer Startbefehl für eine Aufnahme akzeptiert bis diese gestartete Aufnahme nach 22 Sekunden
  5084. beendet ist. Ein Hinweis wird bei verbose=3 im Logfile protokolliert. </li>
  5085. </ul>
  5086. <br>
  5087. <b>Attribut "recextend = 1" gesetzt:</b><br>
  5088. <ul>
  5089. <li> eine zuvor gestartete Aufnahme wird bei einem erneuten "set <name> on" -Befehl um die Aufnahmezeit "rectime" verlängert. Das bedeutet, dass der Timer für
  5090. den automatischen Stop auf den Wert "rectime" neu gesetzt wird. Dieser Vorgang wiederholt sich mit jedem Start-Befehl. Dadurch verlängert sich eine laufende
  5091. Aufnahme bis kein Start-Inpuls mehr registriert wird. </li>
  5092. <li> eine zuvor gestartete Endlos-Aufnahme wird mit einem erneuten "set <name> on"-Befehl nach der Aufnahmezeit "rectime" gestoppt (Timerneustart). Ist dies
  5093. nicht gewünscht, ist darauf zu achten dass bei der Verwendung einer Endlos-Aufnahme das Attribut "recextend" nicht verwendet wird. </li>
  5094. </ul>
  5095. <br>
  5096. Beispiele für einfachen <b>Start/Stop einer Aufnahme</b>: <br><br>
  5097. <table>
  5098. <colgroup> <col width=20%> <col width=80%> </colgroup>
  5099. <tr><td>set &lt;name&gt; on [rectime] </td><td>startet die Aufnahme der Kamera &lt;name&gt;, automatischer Stop der Aufnahme nach Ablauf der Zeit [rectime] (default 15s oder wie im <a href="#SSCamattr">Attribut</a> "rectime" angegeben)</td></tr>
  5100. <tr><td>set &lt;name&gt; off </td><td>stoppt die Aufnahme der Kamera &lt;name&gt;</td></tr>
  5101. </table>
  5102. </ul>
  5103. <br><br>
  5104. <ul>
  5105. <li><b> set &lt;name&gt; optimizeParams [mirror:&lt;value&gt;] [flip:&lt;value&gt;] [rotate:&lt;value&gt;] [ntp:&lt;value&gt;]</b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5106. Setzt eine oder mehrere Eigenschaften für die Kamera. Das Video kann gespiegelt (mirror), auf den Kopf gestellt (flip) oder
  5107. gedreht (rotate) werden. Die jeweiligen Eigenschaften müssen von der Kamera unterstützt werden. Mit "ntp" wird der Zeitserver
  5108. eingestellt den die Kamera zur Zeitsynchronisation verwendet. <br><br>
  5109. &lt;value&gt; kann sein für: <br>
  5110. <ul>
  5111. <li> <b>mirror, flip, rotate: </b> true | false </li>
  5112. <li> <b>ntp: </b> der Name oder die IP-Adresse des Zeitservers </li>
  5113. </ul>
  5114. <br><br>
  5115. <b>Beispiele:</b> <br>
  5116. <code> set &lt;name&gt; optimizeParams mirror:true flip:true ntp:time.windows.com </code><br>
  5117. # Das Bild wird gespiegelt, auf den Kopf gestellt und der Zeitserver auf "time.windows.com" eingestellt.<br>
  5118. <code> set &lt;name&gt; optimizeParams ntp:Surveillance%20Station </code><br>
  5119. # Die Surveillance Station wird als Zeitserver eingestellt. (NTP-Dienst muss im DSM aktiviert sein) <br>
  5120. <code> set &lt;name&gt; optimizeParams mirror:true flip:false rotate:true </code><br>
  5121. # Das Bild wird gespiegelt und um 90 Grad gedreht. <br>
  5122. <br><br>
  5123. </ul>
  5124. <ul>
  5125. <li><b> set &lt;name&gt; runPatrol &lt;Patrolname&gt; </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5126. Dieses Kommando startet die vordefinierterte Überwachungstour einer PTZ-Kamera. <br>
  5127. Die Überwachungstouren müssen dazu zunächst in der Synology Surveillance Station angelegt worden sein.
  5128. Das geschieht in der PTZ-Steuerung im IP-Kamera Setup -&gt; PTZ-Steuerung -&gt; Überwachung.
  5129. Die Überwachungstouren (Patrols) werden über das Kommando "get &lt;name&gt; caminfoall" eingelesen, welches beim Restart von FHEM automatisch abgearbeitet wird.
  5130. Der Einlesevorgang kann durch ein Kamerapolling regelmäßig wiederholt werden. Ein langes Pollingintervall ist in diesem Fall empfehlenswert, da sich die
  5131. Überwachungstouren nur im Fall der Neuanlage bzw. Änderung verändern werden.
  5132. Nähere Informationen zur Anlage von Überwachungstouren sind in der Hilfe zur Surveillance Station enthalten.
  5133. </ul>
  5134. <br><br>
  5135. <ul>
  5136. <li><b> set &lt;name&gt; runView [live_fw | live_link | live_open [&lt;room&gt;] | lastrec_fw | lastrec_open [&lt;room&gt;] | lastsnap_fw] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5137. Mit "live_fw, live_link, live_open" wird ein Livestream (mjpeg-Stream) der Kamera, entweder als eingebettetes Image
  5138. oder als generierter Link, gestartet. <br>
  5139. Die Option "live_open" startet ein separates Browserfenster mit dem Lifestream. Wird dabei optional der Raum mit
  5140. angegeben, wird das Browserfenster nur gestartet wenn dieser Raum aktuell im Browser geöffnet ist. <br><br>
  5141. Der Zugriff auf die letzte Aufnahme einer Kamera kann über die Optionen "lastrec_fw" bzw. "lastrec_open" erfolgen.
  5142. Bei Verwendung von "lastrec_fw" wird die letzte Aufnahme als eingebettetes iFrame-Objekt abgespielt. Es stehen entsprechende
  5143. Steuerungselemente zur Wiedergabegeschwindigkeit usw. zur Verfügung. <br><br>
  5144. Der Befehl <b>"set &lt;name&gt; runView lastsnap_fw"</b> zeigt den letzten Schnappschuss der Kamera eingebettet an. <br><br>
  5145. Durch Angabe des optionalen Raumes bei "lastrec_open" erfolgt die gleiche Einschränkung wie bei "live_open". <br><br>
  5146. Die Gestaltung der Fenster im FHEMWEB kann durch HTML-Tags im <a href="#SSCamattr">Attribut</a> "htmlattr" beeinflusst werden. <br><br>
  5147. <b>Beispiel:</b><br>
  5148. <pre>
  5149. attr &lt;name&gt; htmlattr width="500" height="375"
  5150. attr &lt;name&gt; htmlattr width="500" height="375" top="200" left="300"
  5151. </pre>
  5152. Wird der Stream als live_fw gestartet, ändert sich die Größe entsprechend der Angaben von Width und Hight. <br>
  5153. Das Kommando <b>"set &lt;name&gt; runView live_open"</b> startet den Livestreamlink sofort in einem neuen
  5154. Browserfenster (longpoll=1 muß für WEB gesetzt sein).
  5155. Dabei wird für jede aktive FHEM-Session eine Fensteröffnung initiiert. Soll dieses Verhalten geändert werden, kann
  5156. <b>"set &lt;name&gt; runView live_open &lt;room&gt;"</b> verwendet werden um das Öffnen des Browserwindows in einem
  5157. beliebigen, in einer FHEM-Session angezeigten Raum &lt;room&gt;, zu initiieren.<br>
  5158. Das gesetzte <a href="#SSCamattr">Attribut</a> "livestreamprefix" überschreibt im <a href="#SSCamreadings">Reading</a> "LiveStreamUrl"
  5159. die Angaben für Protokoll, Servername und Port. Damit kann z.B. die LiveStreamUrl für den Versand und externen Zugriff
  5160. auf die SVS modifiziert werden. <br><br>
  5161. <b>Beispiel:</b><br>
  5162. <pre>
  5163. attr &lt;name&gt; livestreamprefix https://&lt;Servername&gt;:&lt;Port&gt;
  5164. </pre>
  5165. Der Livestream wird über das Kommando <b>"set &lt;name&gt; stopView"</b> wieder beendet.
  5166. </ul>
  5167. <br><br>
  5168. <ul>
  5169. <li><b> set &lt;name&gt; snap </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5170. Ein <b>Schnappschuß</b> kann ausgelöst werden mit:
  5171. <pre>
  5172. set &lt;name&gt; snap
  5173. </pre>
  5174. Nachfolgend einige Beispiele für die <b>Auslösung von Schnappschüssen</b>. <br><br>
  5175. Soll eine Reihe von Schnappschüssen ausgelöst werden wenn eine Aufnahme startet, kann das z.B. durch folgendes notify geschehen. <br>
  5176. Sobald der Start der Kamera CamHE1 ausgelöst wird (Attribut event-on-change-reading -> "Record" setzen), werden abhängig davon 3 Snapshots im Abstand von 2 Sekunden getriggert.
  5177. <pre>
  5178. define he1_snap_3 notify CamHE1:Record.*Start define h3 at +*{3}00:00:02 set CamHE1 snap
  5179. </pre>
  5180. Triggern von 2 Schnappschüssen der Kamera "CamHE1" im Abstand von 6 Sekunden nachdem der Bewegungsmelder "MelderHE1" einen Event gesendet hat, <br>
  5181. kann z.B. mit folgendem notify geschehen:
  5182. <pre>
  5183. define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap
  5184. </pre>
  5185. Es wird die ID und der Filename des letzten Snapshots als Wert der Variable "LastSnapId" bzw. "LastSnapFilename" in den Readings der Kamera ausgegeben. <br><br>
  5186. </ul>
  5187. <br><br>
  5188. <ul>
  5189. <li><b> set &lt;name&gt; snapGallery [1-10] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5190. Der Befehl ist nur vorhanden wenn das Attribut "snapGalleryBoost=1" gesetzt wurde.
  5191. Er erzeugt eine Ausgabe der letzten [x] Schnappschüsse ebenso wie <a href="#SSCamget">"get &lt;name&gt; snapGallery"</a>. Abweichend von "get" wird mit Attribut
  5192. <a href="#SSCamattr">Attribut</a> "snapGalleryBoost=1" kein Popup erzeugt, sondern die Schnappschußgalerie als Browserseite
  5193. dargestellt. Alle weiteren Funktionen und Attribute entsprechen dem "get &lt;name&gt; snapGallery" Kommando. <br>
  5194. Wenn die Ausgabe einer Schnappschußgalerie, z.B. über ein "at oder "notify", getriggert wird, sollte besser das
  5195. <a href="#SSCamget">"get &lt;name&gt; snapGallery"</a> Kommando anstatt "set" verwendet werden.
  5196. </ul>
  5197. <br><br>
  5198. </ul>
  5199. <br>
  5200. <a name="SSCamget"></a>
  5201. <b>Get</b>
  5202. <ul>
  5203. <br>
  5204. Mit SSCam können die Eigenschaften der Surveillance Station und der Kameras abgefragt werden. <br>
  5205. Die aufgeführten get-Befehle sind für CAM/SVS-Devices oder nur für CAM-Devices bzw. nur für SVS-Devices gültig. Sie stehen im
  5206. Drop-Down-Menü des jeweiligen Devices zur Auswahl zur Verfügung. <br><br>
  5207. <ul>
  5208. <li><b> get &lt;name&gt; caminfoall </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM/SVS)</li>
  5209. <b> get &lt;name&gt; caminfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM) <br><br>
  5210. Es werden SVS-Parameter und abhängig von der Art der Kamera (z.B. Fix- oder PTZ-Kamera) die verfügbaren Kamera-Eigenschaften
  5211. ermittelt und als Readings zur Verfügung gestellt. <br>
  5212. So wird zum Beispiel das Reading "Availability" auf "disconnected" gesetzt falls die Kamera von der Surveillance Station
  5213. getrennt ist. <br>
  5214. "getcaminfo" ruft eine Teilmenge von "getcaminfoall" ab.
  5215. </ul>
  5216. <br><br>
  5217. <ul>
  5218. <li><b> get &lt;name&gt; eventlist </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5219. Es wird das <a href="#SSCamreadings">Reading</a> "CamEventNum" und "CamLastRec"
  5220. aktualisiert, welches die Gesamtanzahl der registrierten Kameraevents und den Pfad / Namen der letzten Aufnahme enthält.
  5221. Dieser Befehl wird implizit mit "get &lt;name&gt; caminfoall" ausgeführt. <br>
  5222. Mit dem <a href="#SSCamattr">Attribut</a> "videofolderMap" kann der Inhalt des Readings "VideoFolder" überschrieben werden.
  5223. Dies kann von Vortel sein wenn das Surveillance-Verzeichnis der SVS an dem lokalen PC unter anderem Pfadnamen gemountet ist
  5224. und darüber der Zugriff auf die Aufnahmen erfolgen soll (z.B. Verwendung bei Email-Versand). <br><br>
  5225. Ein DOIF-Beispiel für den Email-Versand von Snapshot und Aufnahmelink per non-blocking sendmail:
  5226. <pre>
  5227. define CamHE1.snap.email DOIF ([CamHE1:"LastSnapFilename"])
  5228. ({DebianMailnbl ('Recipient@Domain','Bewegungsalarm CamHE1','Eine Bewegung wurde an der Haustür registriert. Aufnahmelink: \
  5229. \[CamHE1:VideoFolder]\[CamHE1:CamLastRec]','/media/sf_surveillance/@Snapshot/[CamHE1:LastSnapFilename]')})
  5230. </pre>
  5231. </ul>
  5232. <ul>
  5233. <li><b> get &lt;name&gt; homeModeState </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für SVS)</li> <br>
  5234. HomeMode-Status der Surveillance Station wird abgerufen.
  5235. </ul>
  5236. <br><br>
  5237. <ul>
  5238. <li><b> get &lt;name&gt; listLog [severity:&lt;Loglevel&gt;] [limit:&lt;Zeilenzahl&gt;] [match:&lt;Suchstring&gt;] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für SVS)</li> <br>
  5239. Ruft das Surveillance Station Log vom Synology Server ab. Ohne Angabe der optionalen Zusätze wird das gesamte Log abgerufen. <br>
  5240. Es können alle oder eine Auswahl der folgenden Optionen angegeben werden: <br><br>
  5241. <ul>
  5242. <li> &lt;Loglevel&gt; - Information, Warning oder Error. Nur Sätze mit dem Schweregrad werden abgerufen (default: alle) </li>
  5243. <li> &lt;Zeilenzahl&gt; - die angegebene Anzahl der Logzeilen (neueste) wird abgerufen (default: alle) </li>
  5244. <li> &lt;Suchstring&gt; - nur Logeinträge mit dem angegeben String werden abgerufen (Achtung: kein Regex, der Suchstring wird im Call an die SVS mitgegeben) </li>
  5245. </ul>
  5246. <br>
  5247. <b>Beispiele</b> <br>
  5248. <ul>
  5249. <code>get &lt;name&gt; listLog severity:Error limit:5 </code> <br>
  5250. Zeigt die letzten 5 Logeinträge mit dem Schweregrad "Error" <br>
  5251. <code>get &lt;name&gt; listLog severity:Information match:Carport </code> <br>
  5252. Zeigt alle Logeinträge mit dem Schweregrad "Information" die den String "Carport" enthalten <br>
  5253. <code>get &lt;name&gt; listLog severity:Warning </code> <br>
  5254. Zeigt alle Logeinträge mit dem Schweregrad "Warning" <br><br>
  5255. </ul>
  5256. Wurde mit dem <a href="#SSCamattr">Attribut</a> "pollcaminfoall" das Polling der SVS aktiviert, wird das <a href="#SSCamreadings">Reading</a>
  5257. "LastLogEntry" erstellt. <br>
  5258. Im Protokoll-Setup der SVS kann man einstellen was protokolliert werden soll. Für weitere Informationen
  5259. siehe <a href="https://www.synology.com/de-de/knowledgebase/Surveillance/help/SurveillanceStation/log_advanced">Synology Online-Hlfe</a>.
  5260. </ul>
  5261. <br><br>
  5262. <ul>
  5263. <li><b> get &lt;name&gt; scanVirgin </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM/SVS)</li> <br>
  5264. Wie mit get caminfoall werden alle Informationen der SVS und Kamera abgerufen. Allerdings wird in jedem Fall eine
  5265. neue Session ID generiert (neues Login), die Kamera-ID neu ermittelt und es werden alle notwendigen API-Parameter neu
  5266. eingelesen.
  5267. </ul>
  5268. <br><br>
  5269. <ul>
  5270. <li><b> get &lt;name&gt; snapGallery [1-10] </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5271. Es wird ein Popup mit den letzten [x] Schnapschüssen erzeugt. Ist das <a href="#SSCamattr">Attribut</a> "snapGalleryBoost" gesetzt,
  5272. werden die letzten Schnappschüsse (default 3) über Polling abgefragt und im Speicher gehalten. Das Verfahren hilft die Ausgabe zu beschleunigen,
  5273. kann aber möglicherweise nicht den letzten Schnappschuß anzeigen, falls dieser NICHT über das Modul ausgelöst wurde. <br>
  5274. Diese Funktion kann ebenfalls, z.B. mit "at" oder "notify", getriggert werden. Dabei wird die Schnappschußgalerie auf allen
  5275. verbundenen FHEMWEB-Instanzen als Popup angezeigt. <br><br>
  5276. Zur weiteren Steuerung dieser Funktion stehen die <a href="#SSCamattr">Attribute</a>: <br><br>
  5277. <ul>
  5278. <li>snapGalleryBoost </li>
  5279. <li>snapGalleryColumns </li>
  5280. <li>snapGalleryHtmlAttr </li>
  5281. <li>snapGalleryNumber </li>
  5282. <li>snapGallerySize </li>
  5283. </ul> <br>
  5284. zur Verfügung.
  5285. </ul> <br>
  5286. <ul>
  5287. <b>Hinweis:</b><br>
  5288. Abhängig von der Anzahl und Auflösung (Qualität) der Schnappschuß-Images werden entsprechende ausreichende CPU und/oder
  5289. RAM-Ressourcen benötigt.
  5290. </ul>
  5291. <br><br>
  5292. <ul>
  5293. <li><b> get &lt;name&gt; snapfileinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5294. Es wird der Filename des letzten Schnapschusses ermittelt. Der Befehl wird implizit mit <b>"get &lt;name&gt; snap"</b>
  5295. ausgeführt.
  5296. </ul>
  5297. <br><br>
  5298. <ul>
  5299. <li><b> get &lt;name&gt; snapinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5300. Es werden Schnappschussinformationen gelesen. Hilfreich wenn Schnappschüsse nicht durch SSCam, sondern durch die Bewegungserkennung der Kamera
  5301. oder Surveillance Station erzeugt werden.
  5302. </ul>
  5303. <br><br>
  5304. <ul>
  5305. <li><b> get &lt;name&gt; stmUrlPath </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM)</li> <br>
  5306. Mit diesem Kommando wird der aktuelle Streamkey der Kamera abgerufen und das Reading mit dem Key-Wert gefüllt.
  5307. Dieser Streamkey kann verwendet werden um eigene Aufrufe eines Livestreams aufzubauen (siehe Beispiel).
  5308. Wenn das <a href="#SSCamattr">Attribut</a> "showStmInfoFull" gesetzt ist, werden zusaätzliche Stream-Informationen wie "StmKeyUnicst", "StmKeymjpegHttp" ausgegeben.
  5309. Diese Readings enthalten die gültigen Stream-Pfade zu einem Livestream und können z.B. versendet und von einer entsprechenden Anwendung ohne session Id geöffnet werden.
  5310. Wenn das Attribut "livestreamprefix" (Format: "http(s)://&lt;hostname&gt;&lt;port&gt;) gesetzt ist, wird der Servername und Port überschrieben soweit es sinnvoll ist.
  5311. Wird Polling der Kameraeigenschaften genutzt, wird die stmUrlPath-Funktion automatisch mit ausgeführt.
  5312. <br><br>
  5313. Beispiel für den Aufbau eines Http-Calls zu einem Livestream mit StmKey:
  5314. <pre>
  5315. http(s)://&lt;hostname&gt;&lt;port&gt;/webapi/entry.cgi?api=SYNO.SurveillanceStation.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=5&StmKey="31fd87279976d89bb98409728cced890"
  5316. </pre>
  5317. cameraId (Internal CAMID), StmKey müssen durch gültige Werte ersetzt werden. <br><br>
  5318. <b>Hinweis:</b> <br>
  5319. Falls der Stream-Aufruf versendet und von extern genutzt wird sowie hostname / port durch gültige Werte ersetzt und die
  5320. Routerports entsprechend geöffnet werden, ist darauf zu achten, dass diese sensiblen Daten nicht durch unauthorisierte Personen
  5321. für den Zugriff genutzt werden können !
  5322. </ul>
  5323. <br><br>
  5324. <ul>
  5325. <li><b> get &lt;name&gt; storedCredentials </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM/SVS)</li> <br>
  5326. Die gespeicherten Anmeldeinformationen (Credentials) werden in einem Popup als Klartext angezeigt.
  5327. </ul>
  5328. <br><br>
  5329. <ul>
  5330. <li><b> get &lt;name&gt; svsinfo </b> &nbsp;&nbsp;&nbsp;&nbsp;(gilt für CAM/SVS)</li> <br>
  5331. Ermittelt allgemeine Informationen zur installierten SVS-Version und andere Eigenschaften. <br>
  5332. </ul>
  5333. <br><br>
  5334. </ul>
  5335. <br><br>
  5336. <b>Polling der Kamera/SVS-Eigenschaften:</b><br><br>
  5337. Die Abfrage der Kameraeigenschaften erfolgt automatisch, wenn das Attribut "pollcaminfoall" (siehe Attribute) mit einem Wert &gt; 10 gesetzt wird. <br>
  5338. Per Default ist das Attribut "pollcaminfoall" nicht gesetzt und das automatische Polling nicht aktiv. <br>
  5339. Der Wert dieses Attributes legt das Intervall der Abfrage in Sekunden fest. Ist das Attribut nicht gesetzt oder &lt; 10 wird kein automatisches Polling <br>
  5340. gestartet bzw. gestoppt wenn vorher der Wert &gt; 10 gesetzt war. <br><br>
  5341. Das Attribut "pollcaminfoall" wird durch einen Watchdog-Timer überwacht. Änderungen des Attributwertes werden alle 90 Sekunden ausgewertet und entsprechend umgesetzt. <br>
  5342. Eine Änderung des Pollingstatus / Pollingintervalls wird im FHEM-Logfile protokolliert. Diese Protokollierung kann durch Setzen des Attributes "pollnologging=1" abgeschaltet werden.<br>
  5343. Dadurch kann ein unnötiges Anwachsen des Logs vermieden werden. Ab verbose=4 wird allerdings trotz gesetzten "pollnologging"-Attribut ein Log des Pollings <br>
  5344. zu Analysezwecken aktiviert. <br><br>
  5345. Wird FHEM neu gestartet, wird bei aktivierten Polling der ersten Datenabruf innerhalb 60s nach dem Start ausgeführt. <br><br>
  5346. Der Status des automatischen Pollings wird durch das Reading "PollState" signalisiert: <br><br>
  5347. <ul>
  5348. <li><b> PollState = Active </b> - automatisches Polling wird mit Intervall entsprechend "pollcaminfoall" ausgeführt </li>
  5349. <li><b> PollState = Inactive </b> - automatisches Polling wird nicht ausgeführt </li>
  5350. </ul>
  5351. <br>
  5352. Die Bedeutung der Readingwerte ist unter <a href="#SSCamreadings">Readings</a> beschrieben. <br><br>
  5353. <b>Hinweise:</b> <br><br>
  5354. Wird Polling eingesetzt, sollte das Intervall nur so kurz wie benötigt eingestellt werden da die ermittelten Werte überwiegend statisch sind. <br>
  5355. Das eingestellte Intervall sollte nicht kleiner sein als die Summe aller HTTP-Verarbeitungszeiten.
  5356. Pro Pollingaufruf und Kamera werden ca. 10 - 20 Http-Calls gegen die Surveillance Station abgesetzt.<br><br>
  5357. Bei einem eingestellten HTTP-Timeout (siehe <a href="#SSCamattr">Attribut</a>) "httptimeout") von 4 Sekunden kann die theoretische Verarbeitungszeit nicht höher als 80 Sekunden betragen. <br>
  5358. In dem Beispiel sollte man das Pollingintervall mit einem Sicherheitszuschlag auf nicht weniger 160 Sekunden setzen. <br>
  5359. Ein praktikabler Richtwert könnte zwischen 600 - 1800 (s) liegen. <br>
  5360. Sind mehrere Kameras in SSCam definiert, sollte "pollcaminfoall" nicht bei allen Kameras auf exakt den gleichen Wert gesetzt werden um Verarbeitungsengpässe <br>
  5361. und dadurch versursachte potentielle Fehlerquellen bei der Abfrage der Synology Surveillance Station zu vermeiden. <br>
  5362. Ein geringfügiger Unterschied zwischen den Pollingintervallen der definierten Kameras von z.B. 1s kann bereits als ausreichend angesehen werden. <br><br>
  5363. <a name="SSCaminternals"></a>
  5364. <b>Internals</b> <br><br>
  5365. <ul>
  5366. Die Bedeutung der verwendeten Internals stellt die nachfolgende Liste dar: <br><br>
  5367. <ul>
  5368. <li><b>CAMID</b> - die ID der Kamera in der SVS, der Wert wird automatisch anhand des SVS-Kameranamens ermittelt. </li>
  5369. <li><b>CAMNAME</b> - der Name der Kamera in der SVS </li>
  5370. <li><b>CREDENTIALS</b> - der Wert ist "Set" wenn die Credentials gesetzt wurden </li>
  5371. <li><b>MODEL</b> - Unterscheidung von Kamera-Device (CAM) und Surveillance Station Device (SVS) </li>
  5372. <li><b>NAME</b> - der Kameraname in FHEM </li>
  5373. <li><b>OPMODE</b> - die zuletzt ausgeführte Operation des Moduls </li>
  5374. <li><b>SERVERADDR</b> - IP-Adresse des SVS Hostes </li>
  5375. <li><b>SERVERPORT</b> - der SVS-Port </li>
  5376. <br><br>
  5377. </ul>
  5378. </ul>
  5379. <a name="SSCamattr"></a>
  5380. <b>Attribute</b>
  5381. <br><br>
  5382. <ul>
  5383. <ul>
  5384. <li><b>debugactivetoken</b><br>
  5385. wenn gesetzt wird der Status des Active-Tokens gelogged - nur für Debugging, nicht im
  5386. normalen Betrieb benutzen ! </li><br>
  5387. <li><b>disable</b><br>
  5388. deaktiviert das Gerätemodul bzw. die Gerätedefinition </li><br>
  5389. <li><b>httptimeout</b><br>
  5390. Timeout-Wert für HTTP-Aufrufe zur Synology Surveillance Station, Default: 4 Sekunden (wenn
  5391. httptimeout = "0" oder nicht gesetzt) </li><br>
  5392. <li><b>htmlattr</b><br>
  5393. ergänzende Angaben zur Inline-Bilddarstellung um das Verhalten wie Bildgröße zu beeinflussen. <br><br>
  5394. <ul>
  5395. <b>Beispiel:</b><br>
  5396. attr &lt;name&gt; htmlattr width="500" height="325" top="200" left="300"
  5397. </ul>
  5398. <br>
  5399. </li>
  5400. <li><b>livestreamprefix</b><br>
  5401. überschreibt die Angaben zu Protokoll, Servernamen und Port zur Weiterverwendung der
  5402. Livestreamadresse als z.B. externer Link. Anzugeben in der Form
  5403. "http(s)://&lt;servername&gt;:&lt;port&gt;" </li><br>
  5404. <li><b>loginRetries</b><br>
  5405. setzt die Anzahl der Login-Wiederholungen im Fehlerfall (default = 1) </li><br>
  5406. <li><b>noQuotesForSID</b><br>
  5407. dieses Attribut kann in bestimmten Fällen die Fehlermeldung "402 - permission denied"
  5408. vermeiden und ein login ermöglichen. </li><br>
  5409. <li><b>pollcaminfoall</b><br>
  5410. Intervall der automatischen Eigenschaftsabfrage (Polling) einer Kamera (kleiner 10: kein
  5411. Polling, größer 10: Polling mit Intervall) </li><br>
  5412. <li><b>pollnologging</b><br>
  5413. "0" bzw. nicht gesetzt = Logging Gerätepolling aktiv (default), "1" = Logging
  5414. Gerätepolling inaktiv </li><br>
  5415. <li><b>rectime</b><br>
  5416. festgelegte Aufnahmezeit wenn eine Aufnahme gestartet wird. Mit rectime = 0 wird eine
  5417. Endlosaufnahme gestartet. Ist "rectime" nicht gesetzt, wird der Defaultwert von 15s
  5418. verwendet.</li><br>
  5419. <li><b>recextend</b><br>
  5420. "rectime" einer gestarteten Aufnahme wird neu gesetzt. Dadurch verlängert sich die
  5421. Aufnahemzeit einer laufenden Aufnahme </li><br>
  5422. <li><b>session</b><br>
  5423. Auswahl der Login-Session. Nicht gesetzt oder "DSM" -> session wird mit DSM aufgebaut
  5424. (Standard). "SurveillanceStation" -> Session-Aufbau erfolgt mit SVS </li><br>
  5425. <li><b>simu_SVSversion</b><br>
  5426. Simuliert eine andere SVS-Version. (es ist nur eine niedrigere als die installierte SVS
  5427. Version möglich !) </li><br>
  5428. <li><b>snapGalleryBoost</b><br>
  5429. Wenn gesetzt, werden die letzten Schnappschüsse (default 3) über Polling im Speicher gehalten und mit "set/get snapGallery"
  5430. aufbereitet angezeigt. Dieser Modus bietet sich an wenn viele bzw. Fullsize Images angezeigt werden sollen.
  5431. Ist das Attribut eingeschaltet, können bei "set/get snapGallery" keine Argumente mehr mitgegeben werden.
  5432. (siehe Attribut "snapGalleryNumber") </li><br>
  5433. <li><b>snapGalleryColumns</b><br>
  5434. Die Anzahl der Snaps die in einer Reihe im Popup erscheinen sollen (default 3). </li><br>
  5435. <li><b>snapGalleryHtmlAttr</b><br>
  5436. hiermit kann die Bilddarstellung beeinflusst werden. <br>
  5437. Ist das Attribut nicht gesetzt, wird das Attribut "htmlattr" verwendet. <br>
  5438. Ist auch dieses nicht gesetzt, wird eine Standardvorgabe verwendet (width="500" height="325"). <br><br>
  5439. <ul>
  5440. <b>Beispiel:</b><br>
  5441. attr &lt;name&gt; snapGalleryHtmlAttr width="325" height="225"
  5442. </ul>
  5443. <br>
  5444. </li>
  5445. <li><b>snapGalleryNumber</b><br>
  5446. Die Anzahl der abzurufenden Schnappschüsse (default 3). </li><br>
  5447. <li><b>snapGallerySize</b><br>
  5448. Mit diesem Attribut kann die Qualität der Images eingestellt werden (default "Icon"). <br>
  5449. Im Modus "Full" wird die original vorhandene Auflösung der Images abgerufen. Dies erfordert mehr Ressourcen und kann die
  5450. Anzeige verlangsamen. Mit "snapGalleryBoost=1" kann die Ausgabe beschleunigt werden, da in diesem Fall die Aufnahmen über
  5451. Polling abgerufen und nur noch zur Anzeige gebracht werden. </li><br>
  5452. <li><b>showStmInfoFull</b><br>
  5453. zusaätzliche Streaminformationen wie LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp werden
  5454. ausgegeben</li><br>
  5455. <li><b>showPassInLog</b><br>
  5456. wenn gesetzt wird das verwendete Passwort im Logfile (verbose 4) angezeigt.
  5457. (default = 0) </li><br>
  5458. <li><b>videofolderMap</b><br>
  5459. ersetzt den Inhalt des Readings "VideoFolder", Verwendung z.B. bei gemounteten
  5460. Verzeichnissen </li><br>
  5461. <li><b>verbose</b> </li><br>
  5462. <ul>
  5463. Es werden verschiedene Verbose-Level unterstützt.
  5464. Dies sind im Einzelnen:
  5465. <table>
  5466. <colgroup> <col width=5%> <col width=95%> </colgroup>
  5467. <tr><td> 0 </td><td>- Start/Stop-Ereignisse werden geloggt </td></tr>
  5468. <tr><td> 1 </td><td>- Fehlermeldungen werden geloggt </td></tr>
  5469. <tr><td> 2 </td><td>- Meldungen über wichtige Ereignisse oder Alarme </td></tr>
  5470. <tr><td> 3 </td><td>- gesendete Kommandos werden geloggt </td></tr>
  5471. <tr><td> 4 </td><td>- gesendete und empfangene Daten werden geloggt </td></tr>
  5472. <tr><td> 5 </td><td>- alle Ausgaben zur Fehleranalyse werden geloggt. <b>ACHTUNG:</b> möglicherweise werden sehr viele Daten in das Logfile geschrieben! </td></tr>
  5473. </table>
  5474. </ul>
  5475. <br>
  5476. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  5477. <br><br>
  5478. </ul>
  5479. <a name="SSCamreadings"></a>
  5480. <b>Readings</b>
  5481. <ul>
  5482. <br>
  5483. Über den Pollingmechanismus bzw. durch Abfrage mit "Get" werden Readings bereitgestellt, deren Bedeutung in der nachfolgenden Tabelle dargestellt sind. <br>
  5484. Die übermittelten Readings können in Abhängigkeit des Kameratyps variieren.<br><br>
  5485. <ul>
  5486. <table>
  5487. <colgroup> <col width=5%> <col width=95%> </colgroup>
  5488. <tr><td><li>Availability</li> </td><td>- Verfügbarkeit der Kamera (disabled, enabled, disconnected, other) </td></tr>
  5489. <tr><td><li>CamEventNum</li> </td><td>- liefert die Gesamtanzahl der in SVS registrierten Events der Kamera </td></tr>
  5490. <tr><td><li>CamExposureControl</li> </td><td>- zeigt den aktuell eingestellten Typ der Belichtungssteuerung </td></tr>
  5491. <tr><td><li>CamExposureMode</li> </td><td>- aktueller Belichtungsmodus (Day, Night, Auto, Schedule, Unknown) </td></tr>
  5492. <tr><td><li>CamForceEnableMulticast</li> </td><td>- sagt aus ob die Kamera verpflichet ist Multicast einzuschalten. </td></tr>
  5493. <tr><td><li>CamIP</li> </td><td>- IP-Adresse der Kamera </td></tr>
  5494. <tr><td><li>CamLastRec</li> </td><td>- Pfad / Name der letzten Aufnahme </td></tr>
  5495. <tr><td><li>CamLastRecTime</li> </td><td>- Datum / Startzeit - Stopzeit der letzten Aufnahme </td></tr>
  5496. <tr><td><li>CamLiveMode</li> </td><td>- Quelle für Live-Ansicht (DS, Camera) </td></tr>
  5497. <tr><td><li>CamModel</li> </td><td>- Kameramodell </td></tr>
  5498. <tr><td><li>CamMotDetSc</li> </td><td>- Status der Bewegungserkennung (disabled, durch Kamera, durch SVS) und deren Parameter </td></tr>
  5499. <tr><td><li>CamNTPServer</li> </td><td>- eingestellter Zeitserver </td></tr>
  5500. <tr><td><li>CamPort</li> </td><td>- IP-Port der Kamera </td></tr>
  5501. <tr><td><li>CamPreRecTime</li> </td><td>- Dauer der der Voraufzeichnung in Sekunden (Einstellung in SVS) </td></tr>
  5502. <tr><td><li>CamRecShare</li> </td><td>- gemeinsamer Ordner auf der DS für Aufnahmen </td></tr>
  5503. <tr><td><li>CamRecVolume</li> </td><td>- Volume auf der DS für Aufnahmen </td></tr>
  5504. <tr><td><li>CamVendor</li> </td><td>- Kamerahersteller Bezeichnung </td></tr>
  5505. <tr><td><li>CamVideoFlip</li> </td><td>- Ist das Video gedreht </td></tr>
  5506. <tr><td><li>CamVideoMirror</li> </td><td>- Ist das Video gespiegelt </td></tr>
  5507. <tr><td><li>CamVideoRotate</li> </td><td>- Ist das Video gedreht </td></tr>
  5508. <tr><td><li>CapAudioOut</li> </td><td>- Fähigkeit der Kamera zur Audioausgabe über Surveillance Station (false/true) </td></tr>
  5509. <tr><td><li>CapChangeSpeed</li> </td><td>- Fähigkeit der Kamera verschiedene Bewegungsgeschwindigkeiten auszuführen </td></tr>
  5510. <tr><td><li>CapPTZAbs</li> </td><td>- Fähigkeit der Kamera für absolute PTZ-Aktionen </td></tr>
  5511. <tr><td><li>CapPTZAutoFocus</li> </td><td>- Fähigkeit der Kamera für Autofokus Aktionen </td></tr>
  5512. <tr><td><li>CapPTZDirections</li> </td><td>- die verfügbaren PTZ-Richtungen der Kamera </td></tr>
  5513. <tr><td><li>CapPTZFocus</li> </td><td>- Art der Kameraunterstützung für Fokussierung </td></tr>
  5514. <tr><td><li>CapPTZHome</li> </td><td>- Unterstützung der Kamera für Home-Position </td></tr>
  5515. <tr><td><li>CapPTZIris</li> </td><td>- Unterstützung der Kamera für Iris-Aktion </td></tr>
  5516. <tr><td><li>CapPTZPan</li> </td><td>- Unterstützung der Kamera für Pan-Aktion </td></tr>
  5517. <tr><td><li>CapPTZTilt</li> </td><td>- Unterstützung der Kamera für Tilt-Aktion </td></tr>
  5518. <tr><td><li>CapPTZZoom</li> </td><td>- Unterstützung der Kamera für Zoom-Aktion </td></tr>
  5519. <tr><td><li>DeviceType</li> </td><td>- Kameratyp (Camera, Video_Server, PTZ, Fisheye) </td></tr>
  5520. <tr><td><li>Error</li> </td><td>- Meldungstext des letzten Fehlers </td></tr>
  5521. <tr><td><li>Errorcode</li> </td><td>- Fehlercode des letzten Fehlers </td></tr>
  5522. <tr><td><li>HomeModeState</li> </td><td>- HomeMode-Status (ab SVS-Version 8.1.0) </td></tr>
  5523. <tr><td><li>LastLogEntry</li> </td><td>- der neueste Eintrag des Surveillance Station Logs (nur SVS-Device und wenn Attribut pollcaminfoall gesetzt) </td></tr>
  5524. <tr><td><li>LastSnapFilename</li> </td><td>- der Filename des letzten Schnapschusses </td></tr>
  5525. <tr><td><li>LastSnapId</li> </td><td>- die ID des letzten Schnapschusses </td></tr>
  5526. <tr><td><li>LastSnapTime</li> </td><td>- Zeitstempel des letzten Schnapschusses </td></tr>
  5527. <tr><td><li>LastUpdateTime</li> </td><td>- Datum / Zeit der letzten Aktualisierung durch "caminfoall" </td></tr>
  5528. <tr><td><li>LiveStreamUrl </li> </td><td>- die LiveStream-Url wenn der Stream gestartet ist. (<a href="#SSCamattr">Attribut</a> "showStmInfoFull" muss gesetzt sein) </td></tr>
  5529. <tr><td><li>Patrols</li> </td><td>- in Surveillance Station voreingestellte Überwachungstouren (bei PTZ-Kameras) </td></tr>
  5530. <tr><td><li>PollState</li> </td><td>- zeigt den Status des automatischen Pollings an </td></tr>
  5531. <tr><td><li>Presets</li> </td><td>- in Surveillance Station voreingestellte Positionen (bei PTZ-Kameras) </td></tr>
  5532. <tr><td><li>Record</li> </td><td>- Aufnahme läuft = Start, keine Aufnahme = Stop </td></tr>
  5533. <tr><td><li>StmKey</li> </td><td>- aktueller StreamKey. Kann zum öffnen eines Livestreams ohne Session Id genutzt werden. </td></tr>
  5534. <tr><td><li>StmKeyUnicst</li> </td><td>- Uni-cast Stream Pfad der Kamera. (<a href="#SSCamattr">Attribut</a> "showStmInfoFull" muss gesetzt sein) </td></tr>
  5535. <tr><td><li>StmKeymjpegHttp</li> </td><td>- Mjpeg Stream Pfad (über http) der Kamera. (<a href="#SSCamattr">Attribut</a> "showStmInfoFull" muss gesetzt sein) </td></tr>
  5536. <tr><td><li>SVScustomPortHttp</li> </td><td>- benutzerdefinierter Port der Surveillance Station (HTTP) im DSM-Anwendungsportal (get mit "svsinfo") </td></tr>
  5537. <tr><td><li>SVScustomPortHttps</li> </td><td>- benutzerdefinierter Port der Surveillance Station (HTTPS) im DSM-Anwendungsportal (get mit "svsinfo") </td></tr>
  5538. <tr><td><li>SVSlicenseNumber</li> </td><td>- die Anzahl der installierten Kameralizenzen (get mit "svsinfo") </td></tr>
  5539. <tr><td><li>SVSuserPriv</li> </td><td>- die effektiven Rechte des verwendeten Users nach dem Login (get mit "svsinfo") </td></tr>
  5540. <tr><td><li>SVSversion</li> </td><td>- die Paketversion der installierten Surveillance Station (get mit "svsinfo") </td></tr>
  5541. <tr><td><li>UsedSpaceMB</li> </td><td>- durch Aufnahmen der Kamera belegter Plattenplatz auf dem Volume </td></tr>
  5542. <tr><td><li>VideoFolder</li> </td><td>- Pfad zu den aufgenommenen Videos </td></tr>
  5543. </table>
  5544. </ul>
  5545. <br><br>
  5546. </ul>
  5547. </ul>
  5548. <br><br>
  5549. </ul>
  5550. =end html_DE
  5551. =cut