49_SSCam.pm 268 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456
  1. #########################################################################################################################
  2. # $Id: 49_SSCam.pm 13174 2017-01-21 20:19:36Z DS_Starter $
  3. #########################################################################################################################
  4. # 49_SSCam.pm
  5. #
  6. # (c) 2015-2016 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 it's using 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. # 1.40 21.01.2017 downgrade of API apicammaxver in SVS 8.0.0
  31. # 1.39 20.01.2017 compatibility to SVS 8.0.0, Version in Internals, execute getsvsinfo after set credentials
  32. # 1.37 10.10.2016 bugfix Experimental keys on scalar is now forbidden (Perl >= 5.23)
  33. # (Forum: #msg501709)
  34. # 1.36 18.09.2016 bugfix of get presets, get patrols of zoom-cams without pan/tilt
  35. # 1.35 17.09.2016 internal timer of start-routines optimized
  36. # 1.34 15.09.2016 simu_SVSversion changed, added 407 errorcode message, external recording changed
  37. # for SVS 7.2
  38. # 1.33 21.08.2016 function get stmUrlPath added, fit to new commandref style, attribute showStmInfoFull
  39. # added
  40. # 1.32.1 18.08.2016 empty event LastSnapId fixed
  41. # 1.32 17.08.2016 Logging of verbose 4 changed
  42. # 1.31 15.08.2016 Attr "noQuotesForSID" added, avoid possible 402 - permission denied problems
  43. # in some SVS/DS-combinations
  44. # 1.30 15.08.2016 commandref revised, more v4 logging in special case
  45. # 1.29 02.07.2016 add regex for adaption SVS version, url call for "snap" changed
  46. # 1.28 30.06.2016 Attr "showPassInLog" added, per default no password will be shown in log
  47. # 1.27 29.06.2016 Attr "simu_SVSversion" added, sub login_nonbl changed,
  48. # sub camret_nonbl changed (getlistptzpreset) due to 7.2 problem
  49. # 1.26.3 28.06.2016 Time::HiRes added
  50. # 1.26.2 05.05.2016 change: get "snapfileinfo" will get back an Infomessage if Reading "LastSnapId"
  51. # isn't available
  52. # 1.26.1 27.04.2016 bugfix module will not load due to Unknown warnings category 'experimental'
  53. # when using an older perl version
  54. # 1.26 22.04.2016 Attribute "disable" to deactivate the module added
  55. # 1.25 18.04.2016 motion detection parameters can be entered if
  56. # motion detection by camera or SVS is used
  57. # 1.24 16.04.2016 behavior of "set ... on" changed, Attr "recextend" added
  58. # please have a look at commandref and Wiki
  59. # bugfix: setstate-warning if FHEM will restarted and SVS is not reachable
  60. # (Forum: #308)
  61. # 1.23.2 12.04.2016 code review, no functional changes
  62. # 1.23.1 07.04.2016 command check for set cmd's don't work completely
  63. # 1.23 02.04.2016 change to RemoveInternalTimer for functions
  64. # 1.22 27.03.2016 bugfix "link_open" doesn't work after last update
  65. # 1.21 23.03.2016 added "lastrec"," lastrec_open" to playback last recording
  66. # 1.20.3 19.03.2016 change: delay of InternalTimer(s) changed
  67. # "ptzlistpresets" - "id" changed to "position" according to Synology-ticket
  68. # run "geteventlist" automatically after recording-stop
  69. # 1.20.2 14.03.2016 change: routine "initonboot" changed
  70. # 1.20.1 12.03.2016 bugfix: default recordtime 15 s is used if attribute "rectime" is set to "0"
  71. # 1.20 09.03.2016 command "extevent" added
  72. # 1.19.3 07.03.2016 bugfix "uninitialized value $lastrecstarttime",
  73. # "uninitialized value $lastrecstoptime",
  74. # new attribute "videofolderMap"
  75. # 1.19.2 06.03.2016 Reading "CamLastRec" added which contains Path/name
  76. # of last recording
  77. # 1.19.1 28.02.2016 enhanced command runView by option "link_open" to
  78. # open a streamlink immediately
  79. # 1.19 25.02.2016 functions for cam-livestream added
  80. # 1.18.1 21.02.2016 fixed a problem that the state is "disable" instead of
  81. # "disabled" if a camera is disabled and FHEM will be restarted
  82. # 1.18 20.02.2016 function "get ... eventlist" added,
  83. # Reading "CamEventNum" added which containes total number of
  84. # camera events,
  85. # change usage of reading "LastUpdateTime"
  86. # 1.17 19.02.2016 function "runPatrol" added that starts predefined patrols
  87. # of PTZ-cameras,
  88. # Reading "CamDetMotSc" added
  89. # 1.16.1 17.02.2016 Reading "CamExposureControl" added
  90. # 1.16 16.02.2016 set up of motion detection source now possible
  91. # 1.15 15.02.2016 control of exposure mode day, night & auto is possible now
  92. # 1.14 14.02.2016 The port in DEF-String is optional now,
  93. # if not given, default port 5000 is used
  94. # 1.13.2 13.02.2016 fixed a problem that manual updates using "getcaminfoall" are
  95. # leading to additional pollingloops if polling is used,
  96. # attribute "debugactivetoken" added for debugging-use
  97. # 1.13.1 12.02.2016 fixed a problem that a usersession won't be destroyed if a
  98. # function couldn't be executed successfully
  99. # 1.13 feature for retrieval snapfilename added
  100. # 1.12.1 09.02.2016 bugfix: "goAbsPTZ" may be unavailable on Windows-systems
  101. # 1.12 08.02.2016 added function "move" for continuous PTZ action
  102. # 1.11.1 07.02.2016 entries with loglevel "2" reviewed, changed to loglevel "3"
  103. # 1.11 05.02.2016 added function "goPreset" and "goAbsPTZ" to control the move of PTZ lense
  104. # to absolute positions
  105. # refere to commandref or have a look in forum at:
  106. # http://forum.fhem.de/index.php/topic,45671.msg404275.html#msg404275 ,
  107. # http://forum.fhem.de/index.php/topic,45671.msg404892.html#msg404892
  108. # 1.10 02.02.2016 added function "svsinfo" to get informations about installed SVS-package,
  109. # if Availability = " disconnected" then "state"-value will be "disconnected" too,
  110. # saved Credentials were deleted from file if a device will be deleted
  111. # 1.9.1 31.01.2016 a little bit code optimization
  112. # 1.9 28.01.2016 fixed the problem a recording may still stay active if fhem
  113. # will be restarted after a recording was triggered and
  114. # the recordingtime wasn't be over,
  115. # Enhancement of readings.
  116. # 1.8 25.01.2016 changed define in order to remove credentials from string,
  117. # added "set credentials" command to save username/password,
  118. # added Attribute "session" to make login-session selectable,
  119. # Note: You have to adapt your define-strings !!
  120. # Refere to commandref or look in forum at:
  121. # http://forum.fhem.de/index.php/topic,45671.msg397449.html#msg397449
  122. # 1.7 18.01.2016 Attribute "httptimeout" added
  123. # 1.6 16.01.2016 Change the define-string related to rectime.
  124. # Note: See all changes to rectime usage in commandref or here:
  125. # http://forum.fhem.de/index.php/topic,45671.msg391664.html#msg391664
  126. # 1.5.1 11.01.2016 Vars "USERNAME" and "RECTIME" removed from internals,
  127. # Var (Internals) "SERVERNAME" changed to "SERVERADDR",
  128. # minor change of Log messages,
  129. # Note: use rereadcfg in order to activate the changes
  130. # 1.5 04.01.2016 Function "Get" for creating Camera-Readings integrated,
  131. # Attributs pollcaminfoall, pollnologging added,
  132. # Function for Polling Cam-Infos added.
  133. # 1.4 23.12.2015 function "enable" and "disable" for SS-Cams added,
  134. # changed timout of Http-calls to a higher value
  135. # 1.3 19.12.2015 function "snap" for taking snapshots added,
  136. # fixed a bug that functions may impact each other
  137. # 1.2 14.12.2015 improve usage of verbose-modes
  138. # 1.1 13.12.2015 use of InternalTimer instead of fhem(sleep)
  139. # 1.0 12.12.2015 changed completly to HttpUtils_NonblockingGet for calling websites nonblocking,
  140. # LWP is not needed anymore
  141. #
  142. #
  143. # Definition: define <name> SSCam <camname> <ServerAddr> [ServerPort]
  144. #
  145. # Example: define CamCP1 SSCAM Carport 192.168.2.20 [5000]
  146. #
  147. package main;
  148. use JSON qw( decode_json ); # from CPAN, Debian: apt-get install libjson-perl
  149. use Data::Dumper; # Perl Core module
  150. use strict;
  151. use warnings;
  152. use MIME::Base64;
  153. use Time::HiRes;
  154. use HttpUtils;
  155. # no if $] >= 5.017011, warnings => 'experimental';
  156. my $SSCamVersion = "1.40";
  157. # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API)
  158. my %SSCam_errauthlist = (
  159. 100 => "Unknown error",
  160. 101 => "The account parameter is not specified",
  161. 102 => "API does not exist",
  162. 400 => "Invalid user or password",
  163. 401 => "Guest or disabled account",
  164. 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",
  165. 403 => "One time password not specified",
  166. 404 => "One time password authenticate failed",
  167. 407 => "Permission denied - make sure FHEM-Server IP won't be blocked in DSM automated blocking list",
  168. );
  169. my %SSCam_errlist = (
  170. 100 => "Unknown error",
  171. 101 => "Invalid parameters",
  172. 102 => "API does not exist",
  173. 103 => "Method does not exist",
  174. 104 => "This API version is not supported",
  175. 105 => "Insufficient user privilege",
  176. 106 => "Connection time out",
  177. 107 => "Multiple login detected",
  178. 117 => "need manager rights in SurveillanceStation for operation",
  179. 400 => "Execution failed",
  180. 401 => "Parameter invalid",
  181. 402 => "Camera disabled",
  182. 403 => "Insufficient license",
  183. 404 => "Codec activation failed",
  184. 405 => "CMS server connection failed",
  185. 407 => "CMS closed",
  186. 410 => "Service is not enabled",
  187. 412 => "Need to add license",
  188. 413 => "Reach the maximum of platform",
  189. 414 => "Some events not exist",
  190. 415 => "message connect failed",
  191. 417 => "Test Connection Error",
  192. 418 => "Object is not exist",
  193. 419 => "Visualstation name repetition",
  194. 439 => "Too many items selected",
  195. 502 => "Camera disconnected",
  196. 600 => "Presetname and PresetID not found in Hash",
  197. );
  198. sub SSCam_Initialize($) {
  199. my ($hash) = @_;
  200. $hash->{DefFn} = "SSCam_Define";
  201. $hash->{UndefFn} = "SSCam_Undef";
  202. $hash->{DeleteFn} = "SSCam_Delete";
  203. $hash->{SetFn} = "SSCam_Set";
  204. $hash->{GetFn} = "SSCam_Get";
  205. $hash->{AttrFn} = "SSCam_Attr";
  206. # Aufrufe aus FHEMWEB
  207. $hash->{FW_summaryFn} = "SSCam_liveview";
  208. $hash->{FW_detailFn} = "SSCam_liveview";
  209. $hash->{AttrList} =
  210. "disable:1,0 ".
  211. "httptimeout ".
  212. "htmlattr ".
  213. "livestreamprefix ".
  214. "videofolderMap ".
  215. "pollcaminfoall ".
  216. "pollnologging:1,0 ".
  217. "debugactivetoken:1 ".
  218. "rectime ".
  219. "recextend:1,0 ".
  220. "noQuotesForSID:1,0 ".
  221. "session:SurveillanceStation,DSM ".
  222. "showPassInLog:1,0 ".
  223. "showStmInfoFull:1,0 ".
  224. "simu_SVSversion:7.2-xxxx,7.1-xxxx ".
  225. "webCmd ".
  226. $readingFnAttributes;
  227. return undef;
  228. }
  229. sub SSCam_Define {
  230. # Die Define-Funktion eines Moduls wird von Fhem aufgerufen wenn der Define-Befehl für ein Gerät ausgeführt wird
  231. # Welche und wie viele Parameter akzeptiert werden ist Sache dieser Funktion. Die Werte werden nach dem übergebenen Hash in ein Array aufgeteilt
  232. # define CamCP1 SSCAM Carport 192.168.2.20 [5000]
  233. # ($hash) [1] [2] [3] [4]
  234. #
  235. my ($hash, $def) = @_;
  236. my $name = $hash->{NAME};
  237. my @a = split("[ \t][ \t]*", $def);
  238. if(int(@a) < 4) {
  239. return "You need to specify more parameters.\n". "Format: define <name> SSCAM <Cameraname> <ServerAddress> [Port]";
  240. }
  241. my $camname = $a[2];
  242. my $serveraddr = $a[3];
  243. my $serverport = $a[4] ? $a[4] : 5000;
  244. $hash->{SERVERADDR} = $serveraddr;
  245. $hash->{SERVERPORT} = $serverport;
  246. $hash->{CAMNAME} = $camname;
  247. $hash->{VERSION} = $SSCamVersion;
  248. # benötigte API's in $hash einfügen
  249. $hash->{HELPER}{APIINFO} = "SYNO.API.Info"; # Info-Seite für alle API's, einzige statische Seite !
  250. $hash->{HELPER}{APIAUTH} = "SYNO.API.Auth";
  251. $hash->{HELPER}{APISVSINFO} = "SYNO.SurveillanceStation.Info";
  252. $hash->{HELPER}{APIEVENT} = "SYNO.SurveillanceStation.Event";
  253. $hash->{HELPER}{APIEXTREC} = "SYNO.SurveillanceStation.ExternalRecording";
  254. $hash->{HELPER}{APIEXTEVT} = "SYNO.SurveillanceStation.ExternalEvent";
  255. $hash->{HELPER}{APICAM} = "SYNO.SurveillanceStation.Camera";
  256. $hash->{HELPER}{APISNAPSHOT} = "SYNO.SurveillanceStation.SnapShot";
  257. $hash->{HELPER}{APIPTZ} = "SYNO.SurveillanceStation.PTZ";
  258. $hash->{HELPER}{APICAMEVENT} = "SYNO.SurveillanceStation.Camera.Event";
  259. $hash->{HELPER}{APIVIDEOSTM} = "SYNO.SurveillanceStation.VideoStreaming";
  260. $hash->{HELPER}{APISTM} = "SYNO.SurveillanceStation.Streaming";
  261. # Startwerte setzen
  262. $attr{$name}{webCmd} = "on:off:snap:enable:disable"; # initiale Webkommandos setzen
  263. $hash->{HELPER}{ACTIVE} = "off"; # Funktionstoken "off", Funktionen können sofort starten
  264. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0"; # Loggingfunktion für Polling ist an
  265. $hash->{HELPER}{RECTIME_DEF} = "15"; # Standard für rectime setzen, überschreibbar durch Attribut "rectime" bzw. beim "set .. on-for-time"
  266. readingsBeginUpdate($hash);
  267. readingsBulkUpdate($hash,"Availability", "???"); # Verfügbarkeit ist unbekannt
  268. readingsBulkUpdate($hash,"PollState","Inactive"); # es ist keine Gerätepolling aktiv
  269. readingsBulkUpdate($hash,"state", "off"); # Init für "state" , Problemlösung für setstate, Forum #308
  270. readingsEndUpdate($hash,1);
  271. getcredentials($hash,1); # Credentials lesen und in RAM laden ($boot=1)
  272. # initiale Routinen nach Restart ausführen , verzögerter zufälliger Start
  273. RemoveInternalTimer($hash, "initonboot");
  274. InternalTimer(gettimeofday()+int(rand(30)), "initonboot", $hash, 0);
  275. return undef;
  276. }
  277. sub SSCam_Undef {
  278. my ($hash, $arg) = @_;
  279. RemoveInternalTimer($hash);
  280. return undef;
  281. }
  282. sub SSCam_Delete {
  283. my ($hash, $arg) = @_;
  284. my $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  285. # gespeicherte Credentials löschen
  286. setKeyValue($index, undef);
  287. return undef;
  288. }
  289. sub SSCam_Attr {
  290. my ($cmd,$name,$aName,$aVal) = @_;
  291. my $hash = $defs{$name};
  292. my $do;
  293. # $cmd can be "del" or "set"
  294. # $name is device name
  295. # aName and aVal are Attribute name and value
  296. if ($aName eq "disable") {
  297. if($cmd eq "set") {
  298. $do = ($aVal) ? 1 : 0;
  299. }
  300. $do = 0 if($cmd eq "del");
  301. my $val = ($do == 1 ? "inactive" : "off");
  302. readingsSingleUpdate($hash, "state", $val, 1);
  303. readingsSingleUpdate($hash, "PollState", "Inactive", 1) if($do == 1);
  304. readingsSingleUpdate($hash, "Availability", "???", 1) if($do == 1);
  305. }
  306. if ($aName eq "showStmInfoFull") {
  307. if($cmd eq "set") {
  308. $do = ($aVal) ? 1 : 0;
  309. }
  310. $do = 0 if($cmd eq "del");
  311. if ($do == 0) {
  312. delete($defs{$name}{READINGS}{StmKeymjpegHttp}) if ($defs{$name}{READINGS}{StmKeymjpegHttp});
  313. delete($defs{$name}{READINGS}{StmKeyUnicst}) if ($defs{$name}{READINGS}{StmKeyUnicst});
  314. delete($defs{$name}{READINGS}{LiveStreamUrl}) if ($defs{$name}{READINGS}{LiveStreamUrl});
  315. }
  316. }
  317. if ($aName eq "simu_SVSversion") {
  318. getsvsinfo($hash);
  319. }
  320. if ($cmd eq "set") {
  321. if ($aName eq "pollcaminfoall") {
  322. unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 0-9 without decimal places !";}
  323. }
  324. if ($aName eq "rectime") {
  325. unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 0-9 without decimal places !";}
  326. }
  327. if ($aName eq "httptimeout") {
  328. unless ($aVal =~ /^[0-9]+$/) { return " The Value for $aName is not valid. Use only figures 1-9 !";}
  329. }
  330. }
  331. return undef;
  332. }
  333. sub SSCam_Set {
  334. my ($hash, @a) = @_;
  335. return "\"set X\" needs at least an argument" if ( @a < 2 );
  336. my $name = $a[0];
  337. my $opt = $a[1];
  338. my $prop = $a[2];
  339. my $prop1 = $a[3];
  340. my $prop2 = $a[4];
  341. my $prop3 = $a[5];
  342. my $camname = $hash->{CAMNAME};
  343. my $success;
  344. my $setlist;
  345. my @prop;
  346. $setlist = "Unknown argument $opt, choose one of ".
  347. "credentials ".
  348. "expmode:auto,day,night ".
  349. "on ".
  350. "off ".
  351. "motdetsc:disable,camera,SVS ".
  352. "snap ".
  353. "enable ".
  354. "disable ".
  355. "runView:image,lastrec,lastrec_open,link,link_open ".
  356. "stopView:noArg ".
  357. "extevent:1,2,3,4,5,6,7,8,9,10 ".
  358. ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : "").
  359. ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "goPreset:".ReadingsVal("$name", "Presets", "")." " : "").
  360. ((ReadingsVal("$name", "CapPTZAbs", "false")) ? "goAbsPTZ"." " : "").
  361. ((ReadingsVal("$name", "CapPTZDirections", "0") > 0) ? "move"." " : "");
  362. if ($opt eq "on") {
  363. return "module is deactivated" if(IsDisabled($name));
  364. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  365. if (defined($prop)) {
  366. unless ($prop =~ /^\d+$/) { return " The Value for \"$opt\" is not valid. Use only figures 0-9 without decimal places !";}
  367. $hash->{HELPER}{RECTIME_TEMP} = $prop;
  368. }
  369. camstartrec($hash);
  370. }
  371. elsif ($opt eq "off")
  372. {
  373. return "module is deactivated" if(IsDisabled($name));
  374. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  375. camstoprec($hash);
  376. }
  377. elsif ($opt eq "snap")
  378. {
  379. return "module is deactivated" if(IsDisabled($name));
  380. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  381. camsnap($hash);
  382. }
  383. elsif ($opt eq "enable")
  384. {
  385. return "module is deactivated" if(IsDisabled($name));
  386. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  387. camenable($hash);
  388. }
  389. elsif ($opt eq "disable")
  390. {
  391. return "module is deactivated" if(IsDisabled($name));
  392. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  393. camdisable($hash);
  394. }
  395. elsif ($opt eq "motdetsc")
  396. {
  397. return "module is deactivated" if(IsDisabled($name));
  398. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  399. if (!$prop || $prop !~ /^(disable|camera|SVS)$/) { return " \"$opt\" needs one of those arguments: disable, camera, SVS !";}
  400. $hash->{HELPER}{MOTDETSC} = $prop;
  401. if ($prop1) {
  402. # check ob Zahl zwischen 1 und 99
  403. return "invalid value for sensitivity (SVS or camera) - use number between 1 - 99" if ($prop1 !~ /^([1-9]|[1-9][0-9])*$/);
  404. $hash->{HELPER}{MOTDETSC_PROP1} = $prop1;
  405. }
  406. if ($prop2) {
  407. # check ob Zahl zwischen 1 und 99
  408. return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop2 !~ /^([1-9]|[1-9][0-9])*$/);
  409. $hash->{HELPER}{MOTDETSC_PROP2} = $prop2;
  410. }
  411. if ($prop3) {
  412. # check ob Zahl zwischen 1 und 99
  413. return "invalid value for threshold (SVS) / object size (camera) - use number between 1 - 99" if ($prop3 !~ /^([1-9]|[1-9][0-9])*$/);
  414. $hash->{HELPER}{MOTDETSC_PROP3} = $prop3;
  415. }
  416. cammotdetsc($hash);
  417. }
  418. elsif ($opt eq "credentials")
  419. {
  420. return "module is deactivated" if(IsDisabled($name));
  421. return "Credentials are incomplete, use username password" if (!$prop || !$prop1);
  422. ($success) = setcredentials($hash,$prop,$prop1);
  423. getsvsinfo($hash) if($hash->{CREDENTIALS});
  424. return $success ? "Username and Password saved successfully" : "Error while saving Username / Password - see logfile for details";
  425. }
  426. elsif ($opt eq "expmode")
  427. {
  428. return "module is deactivated" if(IsDisabled($name));
  429. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  430. unless ($prop) { return " \"$opt\" needs one of those arguments: auto, day, night !";}
  431. $hash->{HELPER}{EXPMODE} = $prop;
  432. camexpmode($hash);
  433. }
  434. elsif ($opt eq "goPreset")
  435. {
  436. return "module is deactivated" if(IsDisabled($name));
  437. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  438. if (!$prop) {return "Function \"goPreset\" needs a \"Presetname\" as an argument";}
  439. @prop = split(/;/, $prop);
  440. $prop = $prop[0];
  441. @prop = split(/,/, $prop);
  442. $prop = $prop[0];
  443. $hash->{HELPER}{GOPRESETNAME} = $prop;
  444. $hash->{HELPER}{PTZACTION} = "gopreset";
  445. doptzaction($hash);
  446. }
  447. elsif ($opt eq "runPatrol")
  448. {
  449. return "module is deactivated" if(IsDisabled($name));
  450. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  451. if (!$prop) {return "Function \"runPatrol\" needs a \"Patrolname\" as an argument";}
  452. @prop = split(/;/, $prop);
  453. $prop = $prop[0];
  454. @prop = split(/,/, $prop);
  455. $prop = $prop[0];
  456. $hash->{HELPER}{GOPATROLNAME} = $prop;
  457. $hash->{HELPER}{PTZACTION} = "runpatrol";
  458. doptzaction($hash);
  459. }
  460. elsif ($opt eq "goAbsPTZ")
  461. {
  462. return "module is deactivated" if(IsDisabled($name));
  463. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  464. if ($prop eq "up" || $prop eq "down" || $prop eq "left" || $prop eq "right") {
  465. if ($prop eq "up") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 480;}
  466. if ($prop eq "down") {$hash->{HELPER}{GOPTZPOSX} = 320; $hash->{HELPER}{GOPTZPOSY} = 0;}
  467. if ($prop eq "left") {$hash->{HELPER}{GOPTZPOSX} = 0; $hash->{HELPER}{GOPTZPOSY} = 240;}
  468. if ($prop eq "right") {$hash->{HELPER}{GOPTZPOSX} = 640; $hash->{HELPER}{GOPTZPOSY} = 240;}
  469. $hash->{HELPER}{PTZACTION} = "goabsptz";
  470. doptzaction($hash);
  471. return undef;
  472. }
  473. else
  474. {
  475. if ($prop !~ /\d+/ || $prop1 !~ /\d+/ || abs($prop) > 640 || abs($prop1) > 480) {
  476. return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead";
  477. }
  478. $hash->{HELPER}{GOPTZPOSX} = abs($prop);
  479. $hash->{HELPER}{GOPTZPOSY} = abs($prop1);
  480. $hash->{HELPER}{PTZACTION} = "goabsptz";
  481. doptzaction($hash);
  482. return undef;
  483. }
  484. return "Function \"goAbsPTZ\" needs two coordinates, posX=0-640 and posY=0-480, as arguments or use up, down, left, right instead";
  485. }
  486. elsif ($opt eq "move")
  487. {
  488. return "module is deactivated" if(IsDisabled($name));
  489. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  490. if (!defined($prop) || ($prop ne "up" && $prop ne "down" && $prop ne "left" && $prop ne "right" && $prop !~ m/dir_\d/)) {return "Function \"move\" needs an argument like up, down, left, right or dir_X (X = 0 to CapPTZDirections-1)";}
  491. $hash->{HELPER}{GOMOVEDIR} = $prop;
  492. $hash->{HELPER}{GOMOVETIME} = defined($prop1) ? $prop1 : 1;
  493. $hash->{HELPER}{PTZACTION} = "movestart";
  494. doptzaction($hash);
  495. }
  496. elsif ($opt eq "runView")
  497. {
  498. return "module is deactivated" if(IsDisabled($name));
  499. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  500. if ($prop eq "link_open") {
  501. $prop = "link";
  502. if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};}
  503. $hash->{HELPER}{OPENWINDOW} = 1;
  504. $hash->{HELPER}{WLTYPE} = $prop;
  505. } elsif ($prop eq "lastrec_open") {
  506. $prop = "lastrec";
  507. if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};}
  508. $hash->{HELPER}{OPENWINDOW} = 1;
  509. $hash->{HELPER}{WLTYPE} = $prop;
  510. } else {
  511. $hash->{HELPER}{OPENWINDOW} = 0;
  512. $hash->{HELPER}{WLTYPE} = $prop;
  513. }
  514. runliveview($hash);
  515. }
  516. elsif ($opt eq "extevent")
  517. {
  518. return "module is deactivated" if(IsDisabled($name));
  519. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  520. $hash->{HELPER}{EVENTID} = $prop;
  521. extevent($hash);
  522. }
  523. elsif ($opt eq "stopView")
  524. {
  525. return "module is deactivated" if(IsDisabled($name));
  526. stopliveview($hash);
  527. }
  528. else
  529. {
  530. return "$setlist";
  531. }
  532. return;
  533. }
  534. sub SSCam_Get {
  535. my ($hash, @a) = @_;
  536. return "\"get X\" needs at least an argument" if ( @a < 2 );
  537. my $name = shift @a;
  538. my $opt = shift @a;
  539. my %SSCam_gets = (
  540. caminfoall => "caminfoall",
  541. svsinfo => "svsinfo",
  542. snapfileinfo => "snapfileinfo",
  543. eventlist => "eventlist",
  544. stmUrlPath => "stmUrlPath",
  545. );
  546. my @cList;
  547. # ist die angegebene Option verfügbar ?
  548. if(!defined($SSCam_gets{$opt}))
  549. {
  550. @cList = keys %SSCam_gets;
  551. return "Unknown argument $opt, choose one of " . join(" ", @cList);
  552. }
  553. else
  554. {
  555. return "module is deactivated" if(IsDisabled($name));
  556. # sind die Credentials gesetzt ?
  557. if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
  558. if ($opt eq "caminfoall")
  559. {
  560. # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine
  561. getcaminfoall($hash,1);
  562. } elsif ($opt eq "svsinfo") {
  563. getsvsinfo($hash);
  564. } elsif ($opt eq "snapfileinfo") {
  565. if (!ReadingsVal("$name", "LastSnapId", undef)) {return "Reading LastSnapId is empty - please take a snapshot before !"}
  566. getsnapfilename($hash);
  567. } elsif ($opt eq "eventlist") {
  568. geteventlist ($hash);
  569. } elsif ($opt eq "stmUrlPath") {
  570. getStmUrlPath ($hash);
  571. }
  572. }
  573. return undef;
  574. }
  575. ######################################################################################
  576. ### Kamera Liveview Anzeige in FHEMWEB
  577. sub SSCam_liveview ($$$$) {
  578. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash für summaryFn in FHEMWEB
  579. my $hash = $defs{$d};
  580. my $name = $hash->{NAME};
  581. my $link = $hash->{HELPER}{LINK};
  582. my $wltype = $hash->{HELPER}{WLTYPE};
  583. my $ret;
  584. my $alias;
  585. return if(!$hash->{HELPER}{LINK} || ReadingsVal("$name", "state", "") =~ /^dis.*/ || IsDisabled($name));
  586. my $attr = AttrVal($d, "htmlattr", "");
  587. if($wltype eq "image") {
  588. $ret = "<img src=$link $attr><br>";
  589. } elsif($wltype eq "iframe") {
  590. $ret = "<iframe src=$link $attr>Iframes disabled</iframe>";
  591. } elsif($wltype eq "link") {
  592. # $alias = AttrVal($d, "alias", $d)."_liveview";
  593. $alias = "LiveCam";
  594. $ret = "<a href=$link $attr>$alias</a><br>"; # wenn attr target=_blank neuer Browsertab
  595. } elsif($wltype eq "lastrec") {
  596. $alias = "LastRecording";
  597. $ret = "<a href=$link $attr>$alias</a><br>"; # wenn attr target=_blank neuer Browsertab
  598. }
  599. return $ret;
  600. }
  601. ######################################################################################
  602. ### initiale Startroutinen nach Restart FHEM
  603. sub initonboot ($) {
  604. my ($hash) = @_;
  605. my $name = $hash->{NAME};
  606. if ($init_done == 1) {
  607. RemoveInternalTimer($hash); # alle Timer löschen
  608. delete($defs{$name}{READINGS}{LiveStreamUrl}) if($defs{$name}{READINGS}{LiveStreamUrl}); # LiveStream URL zurücksetzen
  609. # check ob alle Recordings = "Stop" nach Reboot -> sonst stoppen
  610. if (ReadingsVal($hash->{NAME}, "Record", "Stop") eq "Start") {
  611. Log3($name, 1, "$name - Recording of $hash->{CAMNAME} seems to be still active after FHEM restart - try to stop it now");
  612. &camstoprec($hash);
  613. }
  614. # Konfiguration der Synology Surveillance Station abrufen
  615. if (!$hash->{CREDENTIALS}) {
  616. Log3($name, 1, "$name - Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"");
  617. }
  618. else {
  619. # allg. SVS-Eigenschaften abrufen
  620. getsvsinfo($hash);
  621. # Kameraspezifische Infos holen
  622. getcaminfo($hash);
  623. getcapabilities($hash);
  624. # Preset/Patrollisten in Hash einlesen zur PTZ-Steuerung
  625. getptzlistpreset($hash);
  626. getptzlistpatrol($hash);
  627. }
  628. # Subroutine Watchdog-Timer starten (sollen Cam-Infos regelmäßig abgerufen werden ?), verzögerter zufälliger Start 0-30s
  629. RemoveInternalTimer($hash, "watchdogpollcaminfo");
  630. InternalTimer(gettimeofday()+int(rand(30)), "watchdogpollcaminfo", $hash, 0);
  631. }
  632. else
  633. {
  634. RemoveInternalTimer($hash, "initonboot");
  635. InternalTimer(gettimeofday()+1, "initonboot", $hash, 0);
  636. }
  637. return;
  638. }
  639. ######################################################################################
  640. ### Username / Paßwort speichern
  641. sub setcredentials ($@) {
  642. my ($hash, @credentials) = @_;
  643. my $name = $hash->{NAME};
  644. my $success;
  645. my $credstr;
  646. my $index;
  647. my $retcode;
  648. my (@key,$len,$i);
  649. $credstr = encode_base64(join(':', @credentials));
  650. # Beginn Scramble-Routine
  651. @key = qw(1 3 4 5 6 3 2 1 9);
  652. $len = scalar @key;
  653. $i = 0;
  654. $credstr = join "",
  655. map { $i = ($i + 1) % $len;
  656. chr((ord($_) + $key[$i]) % 256) } split //, $credstr;
  657. # End Scramble-Routine
  658. $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  659. $retcode = setKeyValue($index, $credstr);
  660. if ($retcode) {
  661. Log3($name, 1, "$name - Error while saving the Credentials - $retcode");
  662. $success = 0;
  663. }
  664. else
  665. {
  666. getcredentials($hash,1); # Credentials nach Speicherung lesen und in RAM laden ($boot=1)
  667. $success = 1;
  668. }
  669. return ($success);
  670. }
  671. ######################################################################################
  672. ### Username / Paßwort abrufen
  673. sub getcredentials ($$) {
  674. my ($hash,$boot) = @_;
  675. my $name = $hash->{NAME};
  676. my $success;
  677. my $username;
  678. my $passwd;
  679. my $index;
  680. my ($retcode, $credstr);
  681. my (@key,$len,$i);
  682. if ($boot eq 1) {
  683. # mit $boot=1 Credentials von Platte lesen und als scrambled-String in RAM legen
  684. $index = $hash->{TYPE}."_".$hash->{NAME}."_credentials";
  685. ($retcode, $credstr) = getKeyValue($index);
  686. if ($retcode) {
  687. Log3($name, 1, "$name - Unable to read password from file: $retcode");
  688. $success = 0;
  689. }
  690. if ($credstr) {
  691. # beim Boot scrambled Credentials in den RAM laden
  692. $hash->{HELPER}{CREDENTIALS} = $credstr;
  693. # "Credentials" wird als Statusbit ausgewertet. Wenn nicht gesetzt -> Warnmeldung und keine weitere Verarbeitung
  694. $hash->{CREDENTIALS} = "Set";
  695. $success = 1;
  696. }
  697. }
  698. else
  699. {
  700. # boot = 0 -> Credentials aus RAM lesen, decoden und zurückgeben
  701. $credstr = $hash->{HELPER}{CREDENTIALS};
  702. # Beginn Descramble-Routine
  703. @key = qw(1 3 4 5 6 3 2 1 9);
  704. $len = scalar @key;
  705. $i = 0;
  706. $credstr = join "",
  707. map { $i = ($i + 1) % $len;
  708. chr((ord($_) - $key[$i] + 256) % 256) }
  709. split //, $credstr;
  710. # Ende Descramble-Routine
  711. ($username, $passwd) = split(":",decode_base64($credstr));
  712. my $logpw = AttrVal($name, "showPassInLog", "0") == 1 ? $passwd : "********";
  713. Log3($name, 4, "$name - Credentials read from RAM: $username $logpw");
  714. $success = (defined($passwd)) ? 1 : 0;
  715. }
  716. return ($success, $username, $passwd);
  717. }
  718. ######################################################################################
  719. ### Polling Überwachung
  720. sub watchdogpollcaminfo ($) {
  721. # Überwacht die Wert von Attribut "pollcaminfoall" und Reading "PollState"
  722. # wenn Attribut "pollcaminfoall" > 10 und "PollState"=Inactive -> start Polling
  723. my ($hash) = @_;
  724. my $name = $hash->{NAME};
  725. my $camname = $hash->{CAMNAME};
  726. my $watchdogtimer = 90;
  727. if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10 and ReadingsVal("$name", "PollState", "Active") eq "Inactive" and !IsDisabled($name)) {
  728. # Polling ist jetzt aktiv
  729. readingsSingleUpdate($hash,"PollState","Active",0);
  730. Log3($name, 3, "$name - Polling Camera $camname is currently activated - Pollinginterval: ".$attr{$name}{pollcaminfoall}."s");
  731. # in $hash eintragen für späteren Vergleich (Changes von pollcaminfoall)
  732. $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall};
  733. &getcaminfoall($hash);
  734. }
  735. if (defined($hash->{HELPER}{OLDVALPOLL}) and defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) {
  736. if ($hash->{HELPER}{OLDVALPOLL} != $attr{$name}{pollcaminfoall}) {
  737. Log3($name, 3, "$name - Polling Camera $camname was changed to new Pollinginterval: ".$attr{$name}{pollcaminfoall}."s");
  738. $hash->{HELPER}{OLDVALPOLL} = $attr{$name}{pollcaminfoall};
  739. }
  740. }
  741. if (defined($attr{$name}{pollnologging})) {
  742. if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} ne $attr{$name}{pollnologging}) {
  743. if ($attr{$name}{pollnologging} == "1") {
  744. Log3($name, 3, "$name - Log of Polling Camera $camname is currently deactivated");
  745. # in $hash eintragen für späteren Vergleich (Changes von pollnologging)
  746. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging};
  747. } else {
  748. Log3($name, 3, "$name - Log of Polling Camera $camname is currently activated");
  749. # in $hash eintragen für späteren Vergleich (Changes von pollnologging)
  750. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = $attr{$name}{pollnologging};
  751. }
  752. }
  753. } else {
  754. # alter Wert von "pollnologging" war 1 -> Logging war deaktiviert
  755. if ($hash->{HELPER}{OLDVALPOLLNOLOGGING} == "1") {
  756. Log3($name, 3, "$name - Log of Polling Camera $camname is currently activated");
  757. $hash->{HELPER}{OLDVALPOLLNOLOGGING} = "0";
  758. }
  759. }
  760. RemoveInternalTimer($hash, "watchdogpollcaminfo");
  761. InternalTimer(gettimeofday()+$watchdogtimer, "watchdogpollcaminfo", $hash, 0);
  762. return undef;
  763. }
  764. #############################################################################################################################
  765. ######### OpMode-Startroutinen #############
  766. ######### $hash->{HELPER}{ACTIVE} = Funktionstoken #############
  767. ######### $hash->{HELPER}{ACTIVE} = "on" -> eine Routine läuft, Start anderer Routine erst wenn "off". #############
  768. ######### $hash->{HELPER}{ACTIVE} = "off" -> keine andere Routine läuft, sofortiger Start möglich #############
  769. #############################################################################################################################
  770. ###############################################################################
  771. ### Kamera Aufnahme starten
  772. sub camstartrec ($) {
  773. my ($hash) = @_;
  774. my $camname = $hash->{CAMNAME};
  775. my $name = $hash->{NAME};
  776. my $errorcode;
  777. my $error;
  778. return if(IsDisabled($name));
  779. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  780. if (ReadingsVal("$name", "state", "") eq "disabled") {
  781. $errorcode = "402";
  782. }
  783. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  784. $errorcode = "502";
  785. }
  786. # Fehlertext zum Errorcode ermitteln
  787. $error = &experror($hash,$errorcode);
  788. # Setreading
  789. readingsBeginUpdate($hash);
  790. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  791. readingsBulkUpdate($hash,"Error",$error);
  792. readingsEndUpdate($hash, 1);
  793. Log3($name, 1, "$name - ERROR - Start Recording of Camera $camname can't be executed - $error");
  794. return;
  795. }
  796. if (ReadingsVal("$name", "Record", undef) eq "Start" and !AttrVal($name, "recextend", undef)) {
  797. Log3($name, 3, "$name - another recording is already running - new start-command will be ignored");
  798. return;
  799. }
  800. if ($hash->{HELPER}{ACTIVE} eq "off") {
  801. # Aufnahme starten
  802. Log3($name, 4, "$name - Recording of Camera $camname will be started now");
  803. $hash->{OPMODE} = "Start";
  804. $hash->{HELPER}{ACTIVE} = "on";
  805. if ($attr{$name}{debugactivetoken}) {
  806. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  807. }
  808. getapisites_nonbl($hash);
  809. }
  810. else
  811. {
  812. RemoveInternalTimer($hash, "camstartrec");
  813. InternalTimer(gettimeofday()+0.3, "camstartrec", $hash);
  814. }
  815. }
  816. ###############################################################################
  817. ### Kamera Aufnahme stoppen
  818. sub camstoprec ($) {
  819. my ($hash) = @_;
  820. my $camname = $hash->{CAMNAME};
  821. my $name = $hash->{NAME};
  822. my $errorcode;
  823. my $error;
  824. return if(IsDisabled($name));
  825. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  826. if (ReadingsVal("$name", "state", "") eq "disabled") {
  827. $errorcode = "402";
  828. }
  829. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  830. $errorcode = "502";
  831. }
  832. # Fehlertext zum Errorcode ermitteln
  833. $error = &experror($hash,$errorcode);
  834. # Setreading
  835. readingsBeginUpdate($hash);
  836. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  837. readingsBulkUpdate($hash,"Error",$error);
  838. readingsEndUpdate($hash, 1);
  839. Log3($name, 1, "$name - ERROR - Stop Recording of Camera $camname can't be executed - $error");
  840. return;
  841. }
  842. if (ReadingsVal("$name", "Record", undef) eq "Stop") {
  843. Log3($name, 3, "$name - recording is already stopped - new stop-command will be ignored");
  844. return;
  845. }
  846. if ($hash->{HELPER}{ACTIVE} eq "off") {
  847. # Aufnahme stoppen
  848. Log3($name, 4, "$name - Recording of Camera $camname will be stopped now");
  849. $hash->{OPMODE} = "Stop";
  850. $hash->{HELPER}{ACTIVE} = "on";
  851. if ($attr{$name}{debugactivetoken}) {
  852. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  853. }
  854. getapisites_nonbl($hash);
  855. }
  856. else
  857. {
  858. RemoveInternalTimer($hash, "camstoprec");
  859. InternalTimer(gettimeofday()+0.3, "camstoprec", $hash, 0);
  860. }
  861. }
  862. ###############################################################################
  863. ### Kamera Auto / Day / Nightmode setzen
  864. sub camexpmode ($) {
  865. my ($hash) = @_;
  866. my $camname = $hash->{CAMNAME};
  867. my $name = $hash->{NAME};
  868. my $errorcode;
  869. my $error;
  870. return if(IsDisabled($name));
  871. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  872. if (ReadingsVal("$name", "state", "") eq "disabled") {
  873. $errorcode = "402";
  874. }
  875. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  876. $errorcode = "502";
  877. }
  878. # Fehlertext zum Errorcode ermitteln
  879. $error = &experror($hash,$errorcode);
  880. # Setreading
  881. readingsBeginUpdate($hash);
  882. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  883. readingsBulkUpdate($hash,"Error",$error);
  884. readingsEndUpdate($hash, 1);
  885. Log3($name, 1, "$name - ERROR - Setting exposure mode of Camera $camname can't be executed - $error");
  886. return;
  887. }
  888. if ($hash->{HELPER}{ACTIVE} eq "off") {
  889. Log3($name, 4, "$name - Setting of exposure mode of Camera $camname will be started now");
  890. $hash->{OPMODE} = "ExpMode";
  891. $hash->{HELPER}{ACTIVE} = "on";
  892. if ($attr{$name}{debugactivetoken}) {
  893. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  894. }
  895. getapisites_nonbl($hash);
  896. }
  897. else
  898. {
  899. RemoveInternalTimer($hash, "camexpmode");
  900. InternalTimer(gettimeofday()+0.5, "camexpmode", $hash, 0);
  901. }
  902. }
  903. ###############################################################################
  904. ### Art der Bewegungserkennung setzen
  905. sub cammotdetsc ($) {
  906. my ($hash) = @_;
  907. my $camname = $hash->{CAMNAME};
  908. my $name = $hash->{NAME};
  909. my $errorcode;
  910. my $error;
  911. return if(IsDisabled($name));
  912. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  913. if (ReadingsVal("$name", "state", "") eq "disabled") {
  914. $errorcode = "402";
  915. }
  916. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  917. $errorcode = "502";
  918. }
  919. # Fehlertext zum Errorcode ermitteln
  920. $error = &experror($hash,$errorcode);
  921. # Setreading
  922. readingsBeginUpdate($hash);
  923. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  924. readingsBulkUpdate($hash,"Error",$error);
  925. readingsEndUpdate($hash, 1);
  926. Log3($name, 1, "$name - ERROR - Setting of motion detection source of Camera $camname can't be executed - $error");
  927. return;
  928. }
  929. if ($hash->{HELPER}{ACTIVE} eq "off") {
  930. Log3($name, 4, "$name - Setting of motion detection source of Camera $camname will be started now");
  931. $hash->{OPMODE} = "MotDetSc";
  932. $hash->{HELPER}{ACTIVE} = "on";
  933. if ($attr{$name}{debugactivetoken}) {
  934. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  935. }
  936. getapisites_nonbl($hash);
  937. }
  938. else
  939. {
  940. RemoveInternalTimer($hash, "cammotdetsc");
  941. InternalTimer(gettimeofday()+0.5, "cammotdetsc", $hash, 0);
  942. }
  943. }
  944. ###############################################################################
  945. ### Kamera Schappschuß aufnehmen
  946. sub camsnap ($) {
  947. my ($hash) = @_;
  948. my $camname = $hash->{CAMNAME};
  949. my $name = $hash->{NAME};
  950. my $errorcode;
  951. my $error;
  952. return if(IsDisabled($name));
  953. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  954. if (ReadingsVal("$name", "state", "") eq "disabled") {
  955. $errorcode = "402";
  956. }
  957. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  958. $errorcode = "502";
  959. }
  960. # Fehlertext zum Errorcode ermitteln
  961. $error = &experror($hash,$errorcode);
  962. # Setreading
  963. readingsBeginUpdate($hash);
  964. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  965. readingsBulkUpdate($hash,"Error",$error);
  966. readingsEndUpdate($hash, 1);
  967. Log3($name, 1, "$name - ERROR - Snapshot of Camera $camname can't be executed - $error");
  968. return;
  969. }
  970. if ($hash->{HELPER}{ACTIVE} eq "off") {
  971. # einen Schnappschuß aufnehmen
  972. Log3($name, 4, "$name - Take Snapshot of Camera $camname");
  973. $hash->{OPMODE} = "Snap";
  974. $hash->{HELPER}{ACTIVE} = "on";
  975. if ($attr{$name}{debugactivetoken}) {
  976. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  977. }
  978. getapisites_nonbl($hash);
  979. }
  980. else
  981. {
  982. RemoveInternalTimer($hash, "camsnap");
  983. InternalTimer(gettimeofday()+0.3, "camsnap", $hash, 0);
  984. }
  985. }
  986. ###############################################################################
  987. ### Kamera Liveview starten
  988. sub runliveview ($) {
  989. my ($hash) = @_;
  990. my $camname = $hash->{CAMNAME};
  991. my $name = $hash->{NAME};
  992. my $errorcode;
  993. my $error;
  994. return if(IsDisabled($name));
  995. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  996. if (ReadingsVal("$name", "state", "") eq "disabled") {
  997. $errorcode = "402";
  998. }
  999. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1000. $errorcode = "502";
  1001. }
  1002. # Fehlertext zum Errorcode ermitteln
  1003. $error = &experror($hash,$errorcode);
  1004. # Setreading
  1005. readingsBeginUpdate($hash);
  1006. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1007. readingsBulkUpdate($hash,"Error",$error);
  1008. readingsEndUpdate($hash, 1);
  1009. Log3($name, 1, "$name - ERROR - Liveview of Camera $camname can't be started - $error");
  1010. return;
  1011. }
  1012. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1013. # Liveview starten
  1014. Log3($name, 4, "$name - Start Liveview of Camera $camname");
  1015. $hash->{OPMODE} = "runliveview";
  1016. $hash->{HELPER}{ACTIVE} = "on";
  1017. if ($attr{$name}{debugactivetoken}) {
  1018. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1019. }
  1020. readingsSingleUpdate($hash,"state","startview",1);
  1021. getapisites_nonbl($hash);
  1022. }
  1023. else
  1024. {
  1025. RemoveInternalTimer($hash, "runliveview");
  1026. InternalTimer(gettimeofday()+0.5, "runliveview", $hash, 0);
  1027. }
  1028. }
  1029. ###############################################################################
  1030. ### Kamera Liveview stoppen
  1031. sub stopliveview ($) {
  1032. my ($hash) = @_;
  1033. my $camname = $hash->{CAMNAME};
  1034. my $name = $hash->{NAME};
  1035. my $errorcode;
  1036. my $error;
  1037. return if(IsDisabled($name));
  1038. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1039. return if (!$hash->{HELPER}{SID_STRM}); # runView ist nicht ausgeführt
  1040. # kurzer state-switch -> Browser aktualisieren
  1041. readingsSingleUpdate($hash,"state","stopview",1);
  1042. # Liveview stoppen
  1043. Log3($name, 4, "$name - Stop Liveview of Camera $camname now");
  1044. $hash->{OPMODE} = "stopliveview";
  1045. $hash->{HELPER}{ACTIVE} = "on";
  1046. if ($attr{$name}{debugactivetoken}) {
  1047. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1048. }
  1049. $hash->{HELPER}{SID} = $hash->{HELPER}{SID_STRM};
  1050. # Liveview-SID und Link aus Helper-hash löschen
  1051. delete $hash->{HELPER}{SID_STRM};
  1052. delete $hash->{HELPER}{LINK};
  1053. # Reading LiveStreamUrl löschen
  1054. delete($defs{$name}{READINGS}{LiveStreamUrl}) if ($defs{$name}{READINGS}{LiveStreamUrl});
  1055. if (ReadingsVal("$name", "Record", "") eq "Start") {
  1056. readingsSingleUpdate( $hash,"state", "on", 1);
  1057. }
  1058. else
  1059. {
  1060. readingsSingleUpdate($hash,"state", "off", 1);
  1061. }
  1062. logout_nonbl($hash);
  1063. }
  1064. else
  1065. {
  1066. RemoveInternalTimer($hash, "stopliveview");
  1067. InternalTimer(gettimeofday()+0.5, "stopliveview", $hash, 0);
  1068. }
  1069. }
  1070. ###############################################################################
  1071. ### Filename zu Schappschuß ermitteln
  1072. sub getsnapfilename ($) {
  1073. my ($hash) = @_;
  1074. my $name = $hash->{NAME};
  1075. my $snapid = ReadingsVal("$name", "LastSnapId", " ");
  1076. return if(IsDisabled($name));
  1077. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1078. # den Filenamen zu einem Schnappschuß ermitteln
  1079. Log3($name, 4, "$name - Get filename of present Snap-ID $snapid");
  1080. $hash->{OPMODE} = "getsnapfilename";
  1081. $hash->{HELPER}{ACTIVE} = "on";
  1082. if ($attr{$name}{debugactivetoken}) {
  1083. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1084. }
  1085. getapisites_nonbl($hash);
  1086. }
  1087. else
  1088. {
  1089. RemoveInternalTimer($hash, "getsnapfilename");
  1090. InternalTimer(gettimeofday()+0.5, "getsnapfilename", $hash, 0);
  1091. }
  1092. }
  1093. ###############################################################################
  1094. ### external Event 1-10 auslösen
  1095. sub extevent ($) {
  1096. my ($hash) = @_;
  1097. my $name = $hash->{NAME};
  1098. return if(IsDisabled($name));
  1099. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1100. Log3($name, 4, "$name - trigger external event \"$hash->{HELPER}{EVENTID}\"");
  1101. $hash->{OPMODE} = "extevent";
  1102. $hash->{HELPER}{ACTIVE} = "on";
  1103. if ($attr{$name}{debugactivetoken}) {
  1104. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1105. }
  1106. getapisites_nonbl($hash);
  1107. }
  1108. else
  1109. {
  1110. RemoveInternalTimer($hash, "extevent");
  1111. InternalTimer(gettimeofday()+0.5, "extevent", $hash, 0);
  1112. }
  1113. }
  1114. ###############################################################################
  1115. ### PTZ-Kamera auf Position fahren
  1116. sub doptzaction ($) {
  1117. my ($hash) = @_;
  1118. my $camname = $hash->{CAMNAME};
  1119. my $name = $hash->{NAME};
  1120. my $errorcode;
  1121. my $error;
  1122. return if(IsDisabled($name));
  1123. if (ReadingsVal("$name", "DeviceType", "Camera") ne "PTZ") {
  1124. Log3($name, 1, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible for cameras of DeviceType \"PTZ\" - please compare with device Readings");
  1125. return;
  1126. }
  1127. if ($hash->{HELPER}{PTZACTION} eq "goabsptz" && !ReadingsVal("$name", "CapPTZAbs", "false")) {
  1128. Log3($name, 1, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports absolute PTZ action - please compare with device Reading \"CapPTZAbs\"");
  1129. return;
  1130. }
  1131. if ( $hash->{HELPER}{PTZACTION} eq "movestart" && ReadingsVal("$name", "CapPTZDirections", "0") < 1) {
  1132. Log3($name, 1, "$name - ERROR - Operation \"$hash->{HELPER}{PTZACTION}\" is only possible if camera supports \"Tilt\" and \"Pan\" operations - please compare with device Reading \"CapPTZDirections\"");
  1133. return;
  1134. }
  1135. if ($hash->{HELPER}{PTZACTION} eq "gopreset") {
  1136. if (!defined($hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}})) {
  1137. $errorcode = "600";
  1138. # Fehlertext zum Errorcode ermitteln
  1139. $error = &experror($hash,$errorcode);
  1140. # Setreading
  1141. readingsBeginUpdate($hash);
  1142. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1143. readingsBulkUpdate($hash,"Error",$error);
  1144. readingsEndUpdate($hash, 1);
  1145. Log3($name, 1, "$name - ERROR - goPreset to position \"$hash->{HELPER}{GOPRESETNAME}\" of Camera $camname can't be executed - $error");
  1146. return;
  1147. }
  1148. }
  1149. if ($hash->{HELPER}{PTZACTION} eq "runpatrol") {
  1150. if (!defined($hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}})) {
  1151. $errorcode = "600";
  1152. # Fehlertext zum Errorcode ermitteln
  1153. $error = &experror($hash,$errorcode);
  1154. # Setreading
  1155. readingsBeginUpdate($hash);
  1156. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1157. readingsBulkUpdate($hash,"Error",$error);
  1158. readingsEndUpdate($hash, 1);
  1159. Log3($name, 1, "$name - ERROR - runPatrol to patrol \"$hash->{HELPER}{GOPATROLNAME}\" of Camera $camname can't be executed - $error");
  1160. return;
  1161. }
  1162. }
  1163. if (ReadingsVal("$name", "state", "") =~ /^dis.*/) {
  1164. if (ReadingsVal("$name", "state", "") eq "disabled") {
  1165. $errorcode = "402";
  1166. }
  1167. elsif (ReadingsVal("$name", "state", "") eq "disconnected") {
  1168. $errorcode = "502";
  1169. }
  1170. # Fehlertext zum Errorcode ermitteln
  1171. $error = &experror($hash,$errorcode);
  1172. # Setreading
  1173. readingsBeginUpdate($hash);
  1174. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1175. readingsBulkUpdate($hash,"Error",$error);
  1176. readingsEndUpdate($hash, 1);
  1177. Log3($name, 1, "$name - ERROR - $hash->{HELPER}{PTZACTION} of Camera $camname can't be executed - $error");
  1178. return;
  1179. }
  1180. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1181. if ($hash->{HELPER}{PTZACTION} eq "gopreset") {
  1182. Log3($name, 4, "$name - Move Camera $camname to position \"$hash->{HELPER}{GOPRESETNAME}\" with ID \"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\" now");
  1183. }
  1184. elsif ($hash->{HELPER}{PTZACTION} eq "runpatrol") {
  1185. Log3($name, 4, "$name - Start patrol \"$hash->{HELPER}{GOPATROLNAME}\" with ID \"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\" of Camera $camname now");
  1186. }
  1187. elsif ($hash->{HELPER}{PTZACTION} eq "goabsptz") {
  1188. Log3($name, 4, "$name - Start move Camera $camname to position posX=\"$hash->{HELPER}{GOPTZPOSX}\" and posY=\"$hash->{HELPER}{GOPTZPOSY}\" now");
  1189. }
  1190. elsif ($hash->{HELPER}{PTZACTION} eq "movestart") {
  1191. Log3($name, 4, "$name - Start move Camera $camname to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s");
  1192. }
  1193. if ($attr{$name}{debugactivetoken}) {
  1194. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1195. }
  1196. $hash->{OPMODE} = $hash->{HELPER}{PTZACTION};
  1197. $hash->{HELPER}{ACTIVE} = "on";
  1198. getapisites_nonbl($hash);
  1199. }
  1200. else
  1201. {
  1202. RemoveInternalTimer($hash, "doptzaction");
  1203. InternalTimer(gettimeofday()+0.5, "doptzaction", $hash, 0);
  1204. }
  1205. }
  1206. ###############################################################################
  1207. ### stoppen continues move
  1208. sub movestop ($) {
  1209. my ($hash) = @_;
  1210. my $camname = $hash->{CAMNAME};
  1211. my $name = $hash->{NAME};
  1212. return if(IsDisabled($name));
  1213. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1214. Log3($name, 4, "$name - Stop Camera $camname moving to direction \"$hash->{HELPER}{GOMOVEDIR}\" now");
  1215. $hash->{OPMODE} = "movestop";
  1216. $hash->{HELPER}{ACTIVE} = "on";
  1217. if ($attr{$name}{debugactivetoken}) {
  1218. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");;
  1219. }
  1220. getapisites_nonbl($hash);
  1221. }
  1222. else
  1223. {
  1224. RemoveInternalTimer($hash, "movestop");
  1225. InternalTimer(gettimeofday()+0.3, "movestop", $hash, 0);
  1226. }
  1227. }
  1228. ###############################################################################
  1229. ### Kamera aktivieren
  1230. sub camenable ($) {
  1231. my ($hash) = @_;
  1232. my $camname = $hash->{CAMNAME};
  1233. my $name = $hash->{NAME};
  1234. return if(IsDisabled($name));
  1235. if (ReadingsVal("$name", "Availability", "disabled") eq "enabled") {return;} # Kamera ist bereits enabled
  1236. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1237. # eine Kamera aktivieren
  1238. Log3($name, 4, "$name - Enable Camera $camname");
  1239. $hash->{OPMODE} = "Enable";
  1240. $hash->{HELPER}{ACTIVE} = "on";
  1241. if ($attr{$name}{debugactivetoken}) {
  1242. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1243. }
  1244. getapisites_nonbl($hash);
  1245. }
  1246. else
  1247. {
  1248. RemoveInternalTimer($hash, "camenable");
  1249. InternalTimer(gettimeofday()+0.5, "camenable", $hash, 0);
  1250. }
  1251. }
  1252. ###############################################################################
  1253. ### Kamera deaktivieren
  1254. sub camdisable ($) {
  1255. my ($hash) = @_;
  1256. my $camname = $hash->{CAMNAME};
  1257. my $name = $hash->{NAME};
  1258. return if(IsDisabled($name));
  1259. if (ReadingsVal("$name", "Availability", "enabled") eq "disabled") {return;} # Kamera ist bereits disabled
  1260. if ($hash->{HELPER}{ACTIVE} eq "off" and ReadingsVal("$name", "Record", "Start") ne "Start") {
  1261. # eine Kamera deaktivieren
  1262. Log3($name, 4, "$name - Disable Camera $camname");
  1263. $hash->{OPMODE} = "Disable";
  1264. $hash->{HELPER}{ACTIVE} = "on";
  1265. if ($attr{$name}{debugactivetoken}) {
  1266. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1267. }
  1268. getapisites_nonbl($hash);
  1269. }
  1270. else
  1271. {
  1272. RemoveInternalTimer($hash, "camdisable");
  1273. InternalTimer(gettimeofday()+0.5, "camdisable", $hash, 0);
  1274. }
  1275. }
  1276. ###############################################################################
  1277. ### Kamera alle Informationen abrufen (Get) bzw. Einstieg Polling
  1278. sub getcaminfoall {
  1279. my ($hash,$mode) = @_;
  1280. my $camname = $hash->{CAMNAME};
  1281. my $name = $hash->{NAME};
  1282. my ($now,$new);
  1283. return if(IsDisabled($name));
  1284. geteventlist($hash);
  1285. RemoveInternalTimer($hash, "getcaminfo");
  1286. InternalTimer(gettimeofday()+0.5, "getcaminfo", $hash, 0);
  1287. RemoveInternalTimer($hash, "getmotionenum");
  1288. InternalTimer(gettimeofday()+0.8, "getmotionenum", $hash, 0);
  1289. RemoveInternalTimer($hash, "getcapabilities");
  1290. InternalTimer(gettimeofday()+1.3, "getcapabilities", $hash, 0);
  1291. RemoveInternalTimer($hash, "getptzlistpreset");
  1292. InternalTimer(gettimeofday()+1.6, "getptzlistpreset", $hash, 0);
  1293. RemoveInternalTimer($hash, "getptzlistpatrol");
  1294. InternalTimer(gettimeofday()+1.9, "getptzlistpatrol", $hash, 0);
  1295. RemoveInternalTimer($hash, "getStmUrlPath");
  1296. InternalTimer(gettimeofday()+2.1, "getStmUrlPath", $hash, 0);
  1297. # wenn gesetzt = manuelle Abfrage,
  1298. if ($mode) {
  1299. getsvsinfo($hash);
  1300. return;
  1301. }
  1302. if (defined($attr{$name}{pollcaminfoall}) and $attr{$name}{pollcaminfoall} > 10) {
  1303. # Pollen wenn pollcaminfo > 10, sonst kein Polling
  1304. $new = gettimeofday()+$attr{$name}{pollcaminfoall};
  1305. InternalTimer($new, "getcaminfoall", $hash, 0);
  1306. if (!$attr{$name}{pollnologging}) {
  1307. $now = FmtTime(gettimeofday());
  1308. $new = FmtTime(gettimeofday()+$attr{$name}{pollcaminfoall});
  1309. Log3($name, 3, "$name - Polling now: $now , next Polling: $new");
  1310. }
  1311. }
  1312. else
  1313. {
  1314. # Beenden Polling aller Caminfos
  1315. readingsSingleUpdate($hash,"PollState","Inactive",0);
  1316. Log3($name, 3, "$name - Polling of Camera $camname is currently deactivated");
  1317. }
  1318. return;
  1319. }
  1320. ###########################################################################
  1321. ### allgemeine Infos über Synology Surveillance Station
  1322. sub getsvsinfo ($) {
  1323. my ($hash) = @_;
  1324. my $camname = $hash->{CAMNAME};
  1325. my $name = $hash->{NAME};
  1326. return if(IsDisabled($name));
  1327. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1328. # Kamerainfos abrufen
  1329. Log3($name, 4, "$name - Retrieval of Surveillance Station related informations starts now");
  1330. $hash->{OPMODE} = "Getsvsinfo";
  1331. $hash->{HELPER}{ACTIVE} = "on";
  1332. if ($attr{$name}{debugactivetoken}) {
  1333. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1334. }
  1335. getapisites_nonbl($hash);
  1336. }
  1337. else
  1338. {
  1339. RemoveInternalTimer($hash, "getsvsinfo");
  1340. InternalTimer(gettimeofday()+1, "getsvsinfo", $hash, 0);
  1341. }
  1342. }
  1343. ###########################################################################
  1344. ### Kamera allgemeine Informationen abrufen (Get), sub von getcaminfoall
  1345. sub getcaminfo ($) {
  1346. my ($hash) = @_;
  1347. my $camname = $hash->{CAMNAME};
  1348. my $name = $hash->{NAME};
  1349. return if(IsDisabled($name));
  1350. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1351. # Kamerainfos abrufen
  1352. Log3($name, 4, "$name - Retrieval Camera-Informations of $camname starts now");
  1353. $hash->{OPMODE} = "Getcaminfo";
  1354. $hash->{HELPER}{ACTIVE} = "on";
  1355. if ($attr{$name}{debugactivetoken}) {
  1356. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1357. }
  1358. getapisites_nonbl($hash);
  1359. }
  1360. else
  1361. {
  1362. RemoveInternalTimer($hash, "getcaminfo");
  1363. InternalTimer(gettimeofday()+2, "getcaminfo", $hash, 0);
  1364. }
  1365. }
  1366. ################################################################################
  1367. ### Kamera Stream Urls abrufen (Get), Aufruf aus getcaminfoall
  1368. sub getStmUrlPath ($) {
  1369. my ($hash) = @_;
  1370. my $camname = $hash->{CAMNAME};
  1371. my $name = $hash->{NAME};
  1372. return if(IsDisabled($name));
  1373. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1374. # Stream-Urls abrufen
  1375. Log3($name, 4, "$name - Retrieval Stream-URLs of $camname starts now");
  1376. $hash->{OPMODE} = "getStmUrlPath";
  1377. $hash->{HELPER}{ACTIVE} = "on";
  1378. if ($attr{$name}{debugactivetoken}) {
  1379. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1380. }
  1381. getapisites_nonbl($hash);
  1382. }
  1383. else
  1384. {
  1385. RemoveInternalTimer($hash, "getStmUrlPath");
  1386. InternalTimer(gettimeofday()+2, "getStmUrlPath", $hash, 0);
  1387. }
  1388. }
  1389. ###########################################################################
  1390. ### query SVS-Event information , sub von getcaminfoall
  1391. sub geteventlist ($) {
  1392. my ($hash) = @_;
  1393. my $camname = $hash->{CAMNAME};
  1394. my $name = $hash->{NAME};
  1395. return if(IsDisabled($name));
  1396. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1397. # Kamerainfos abrufen
  1398. Log3($name, 4, "$name - Query event informations of $camname starts now");
  1399. $hash->{OPMODE} = "geteventlist";
  1400. $hash->{HELPER}{ACTIVE} = "on";
  1401. if ($attr{$name}{debugactivetoken}) {
  1402. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1403. }
  1404. getapisites_nonbl($hash);
  1405. }
  1406. else
  1407. {
  1408. RemoveInternalTimer($hash, "geteventlist");
  1409. InternalTimer(gettimeofday()+2, "geteventlist", $hash, 0);
  1410. }
  1411. }
  1412. ###########################################################################
  1413. ### Enumerate motion detection parameters, sub von getcaminfoall
  1414. sub getmotionenum ($) {
  1415. my ($hash) = @_;
  1416. my $camname = $hash->{CAMNAME};
  1417. my $name = $hash->{NAME};
  1418. return if(IsDisabled($name));
  1419. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1420. Log3($name, 4, "$name - Enumerate motion detection parameters of $camname starts now");
  1421. $hash->{OPMODE} = "getmotionenum";
  1422. $hash->{HELPER}{ACTIVE} = "on";
  1423. if ($attr{$name}{debugactivetoken}) {
  1424. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1425. }
  1426. getapisites_nonbl($hash);
  1427. }
  1428. else
  1429. {
  1430. RemoveInternalTimer($hash, "getmotionenum");
  1431. InternalTimer(gettimeofday()+2, "getmotionenum", $hash, 0);
  1432. }
  1433. }
  1434. ##########################################################################
  1435. ### Capabilities von Kamera abrufen (Get), sub von getcaminfoall
  1436. sub getcapabilities ($) {
  1437. my ($hash) = @_;
  1438. my $camname = $hash->{CAMNAME};
  1439. my $name = $hash->{NAME};
  1440. return if(IsDisabled($name));
  1441. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1442. # PTZ-ListPresets abrufen
  1443. Log3($name, 4, "$name - Retrieval Capabilities of Camera $camname starts now");
  1444. $hash->{OPMODE} = "Getcapabilities";
  1445. $hash->{HELPER}{ACTIVE} = "on";
  1446. if ($attr{$name}{debugactivetoken}) {
  1447. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1448. }
  1449. getapisites_nonbl($hash);
  1450. }
  1451. else
  1452. {
  1453. RemoveInternalTimer($hash, "getcapabilities");
  1454. InternalTimer(gettimeofday()+2, "getcapabilities", $hash, 0);
  1455. }
  1456. }
  1457. ##########################################################################
  1458. ### PTZ Presets abrufen (Get), sub von getcaminfoall
  1459. sub getptzlistpreset ($) {
  1460. my ($hash) = @_;
  1461. my $camname = $hash->{CAMNAME};
  1462. my $name = $hash->{NAME};
  1463. return if(IsDisabled($name));
  1464. if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") {
  1465. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname is not a PTZ-Camera");
  1466. return;
  1467. }
  1468. if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") {
  1469. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname has no capability to tilt/pan");
  1470. return;
  1471. }
  1472. if ($hash->{HELPER}{ACTIVE} eq "off") {
  1473. # PTZ-ListPresets abrufen
  1474. Log3($name, 4, "$name - Retrieval PTZ-ListPresets of $camname starts now");
  1475. $hash->{OPMODE} = "Getptzlistpreset";
  1476. $hash->{HELPER}{ACTIVE} = "on";
  1477. if ($attr{$name}{debugactivetoken}) {
  1478. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1479. }
  1480. getapisites_nonbl($hash);
  1481. }
  1482. else
  1483. {
  1484. RemoveInternalTimer($hash, "getptzlistpreset");
  1485. InternalTimer(gettimeofday()+2, "getptzlistpreset", $hash, 0);
  1486. }
  1487. }
  1488. ##########################################################################
  1489. ### PTZ Patrols abrufen (Get), sub von getcaminfoall
  1490. sub getptzlistpatrol ($) {
  1491. my ($hash) = @_;
  1492. my $camname = $hash->{CAMNAME};
  1493. my $name = $hash->{NAME};
  1494. return if(IsDisabled($name));
  1495. if (ReadingsVal("$name", "DeviceType", "") ne "PTZ") {
  1496. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname is not a PTZ-Camera");
  1497. return;
  1498. }
  1499. if (ReadingsVal("$name", "CapPTZTilt", "") eq "false" | ReadingsVal("$name", "CapPTZPan", "") eq "false") {
  1500. Log3($name, 4, "$name - Retrieval of Presets for $camname can't be executed - $camname has no capability to tilt/pan");
  1501. return;
  1502. }
  1503. if ($hash->{HELPER}{ACTIVE} ne "on") {
  1504. # PTZ-ListPatrols abrufen
  1505. Log3($name, 4, "$name - Retrieval PTZ-ListPatrols of $camname starts now");
  1506. $hash->{OPMODE} = "Getptzlistpatrol";
  1507. $hash->{HELPER}{ACTIVE} = "on";
  1508. if ($attr{$name}{debugactivetoken}) {
  1509. Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}");
  1510. }
  1511. getapisites_nonbl($hash);
  1512. }
  1513. else
  1514. {
  1515. RemoveInternalTimer($hash, "getptzlistpatrol");
  1516. InternalTimer(gettimeofday()+2, "getptzlistpatrol", $hash, 0);
  1517. }
  1518. }
  1519. #############################################################################################################################
  1520. ####### Begin Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) #######
  1521. ####### #######
  1522. ####### Ablauflogik: #######
  1523. ####### #######
  1524. ####### #######
  1525. ####### OpMode-Startroutine #######
  1526. ####### | #######
  1527. ####### getapisites_nonbl -> login_nonbl -> getcamid_nonbl -> camop_nonbl -> camret_nonbl -> logout_nonbl #######
  1528. ####### | #######
  1529. ####### OpMode #######
  1530. ####### #######
  1531. #############################################################################################################################
  1532. sub getapisites_nonbl {
  1533. my ($hash) = @_;
  1534. my $serveraddr = $hash->{SERVERADDR};
  1535. my $serverport = $hash->{SERVERPORT};
  1536. my $name = $hash->{NAME};
  1537. my $apiinfo = $hash->{HELPER}{APIINFO}; # Info-Seite für alle API's, einzige statische Seite !
  1538. my $apiauth = $hash->{HELPER}{APIAUTH}; # benötigte API-Pfade für Funktionen,
  1539. my $apiextrec = $hash->{HELPER}{APIEXTREC}; # in der Abfrage-Url an Parameter "&query="
  1540. my $apiextevt = $hash->{HELPER}{APIEXTEVT}; # mit Komma getrennt angeben
  1541. my $apicam = $hash->{HELPER}{APICAM};
  1542. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  1543. my $apiptz = $hash->{HELPER}{APIPTZ};
  1544. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  1545. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  1546. my $apievent = $hash->{HELPER}{APIEVENT};
  1547. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  1548. my $apistm = $hash->{HELPER}{APISTM};
  1549. my $url;
  1550. my $param;
  1551. my $httptimeout;
  1552. #### API-Pfade und MaxVersions ermitteln #####
  1553. Log3($name, 4, "$name - --- Begin Function getapisites nonblocking ---");
  1554. $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  1555. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  1556. # URL zur Abfrage der Eigenschaften der API's
  1557. $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";
  1558. Log3($name, 4, "$name - Call-Out now: $url");
  1559. $param = {
  1560. url => $url,
  1561. timeout => $httptimeout,
  1562. hash => $hash,
  1563. method => "GET",
  1564. header => "Accept: application/json",
  1565. callback => \&login_nonbl
  1566. };
  1567. HttpUtils_NonblockingGet ($param);
  1568. }
  1569. ####################################################################################
  1570. #### Rückkehr aus Funktion API-Pfade und MaxVersions ermitteln,
  1571. #### nach erfolgreicher Verarbeitung wird login ausgeführt und $sid ermittelt
  1572. sub login_nonbl ($) {
  1573. my ($param, $err, $myjson) = @_;
  1574. my $hash = $param->{hash};
  1575. my $name = $hash->{NAME};
  1576. my $serveraddr = $hash->{SERVERADDR};
  1577. my $serverport = $hash->{SERVERPORT};
  1578. my $username = $hash->{HELPER}{USERNAME};
  1579. my $password = $hash->{HELPER}{PASSWORD};
  1580. my $apiauth = $hash->{HELPER}{APIAUTH};
  1581. my $apiextrec = $hash->{HELPER}{APIEXTREC};
  1582. my $apiextevt = $hash->{HELPER}{APIEXTEVT};
  1583. my $apicam = $hash->{HELPER}{APICAM};
  1584. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  1585. my $apiptz = $hash->{HELPER}{APIPTZ};
  1586. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  1587. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  1588. my $apievent = $hash->{HELPER}{APIEVENT};
  1589. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  1590. my $apistm = $hash->{HELPER}{APISTM};
  1591. # Verarbeitung der asynchronen Rückkehrdaten aus sub "getapisites_nonbl"
  1592. if ($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  1593. {
  1594. Log3($name, 1, "$name - error while requesting ".$param->{url}." - $err");
  1595. Log3($name, 4, "$name - --- End Function getapisites nonblocking with error ---");
  1596. readingsSingleUpdate($hash, "Error", $err, 1); # Readings erzeugen
  1597. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  1598. $hash->{HELPER}{ACTIVE} = "off";
  1599. if ($attr{$name}{debugactivetoken}) {
  1600. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1601. }
  1602. return;
  1603. }
  1604. elsif ($myjson ne "") # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  1605. {
  1606. # Evaluiere ob Daten im JSON-Format empfangen wurden
  1607. ($hash, my $success) = &evaljson($hash,$myjson,$param->{url});
  1608. unless ($success) {
  1609. Log3($name, 4, "$name - Data returned: $myjson");
  1610. $hash->{HELPER}{ACTIVE} = "off";
  1611. if ($attr{$name}{debugactivetoken}) {
  1612. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1613. }
  1614. return;
  1615. }
  1616. my $data = decode_json($myjson);
  1617. # Logausgabe decodierte JSON Daten
  1618. Log3($name, 4, "$name - JSON returned: ". Dumper $data);
  1619. $success = $data->{'success'};
  1620. if ($success)
  1621. {
  1622. my $logstr;
  1623. # Pfad und Maxversion von "SYNO.API.Auth" ermitteln
  1624. my $apiauthpath = $data->{'data'}->{$apiauth}->{'path'};
  1625. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1626. $apiauthpath =~ tr/_//d if (defined($apiauthpath));
  1627. my $apiauthmaxver = $data->{'data'}->{$apiauth}->{'maxVersion'};
  1628. $logstr = defined($apiauthpath) ? "Path of $apiauth selected: $apiauthpath" : "Path of $apiauth undefined - Surveillance Station may be stopped";
  1629. Log3($name, 4, "$name - $logstr");
  1630. $logstr = defined($apiauthmaxver) ? "MaxVersion of $apiauth selected: $apiauthmaxver" : "MaxVersion of $apiauth undefined - Surveillance Station may be stopped";
  1631. Log3($name, 4, "$name - $logstr");
  1632. # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalRecording" ermitteln
  1633. my $apiextrecpath = $data->{'data'}->{$apiextrec}->{'path'};
  1634. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1635. $apiextrecpath =~ tr/_//d if (defined($apiextrecpath));
  1636. my $apiextrecmaxver = $data->{'data'}->{$apiextrec}->{'maxVersion'};
  1637. $logstr = defined($apiextrecpath) ? "Path of $apiextrec selected: $apiextrecpath" : "Path of $apiextrec undefined - Surveillance Station may be stopped";
  1638. Log3($name, 4, "$name - $logstr");
  1639. $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apiextrec selected: $apiextrecmaxver" : "MaxVersion of $apiextrec undefined - Surveillance Station may be stopped";
  1640. Log3($name, 4, "$name - $logstr");
  1641. # Pfad und Maxversion von "SYNO.SurveillanceStation.Camera" ermitteln
  1642. my $apicampath = $data->{'data'}->{$apicam}->{'path'};
  1643. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1644. $apicampath =~ tr/_//d if (defined($apicampath));
  1645. my $apicammaxver = $data->{'data'}->{$apicam}->{'maxVersion'};
  1646. $logstr = defined($apicampath) ? "Path of $apicam selected: $apicampath" : "Path of $apicam undefined - Surveillance Station may be stopped";
  1647. Log3($name, 4, "$name - $logstr");
  1648. $logstr = defined($apiextrecmaxver) ? "MaxVersion of $apicam: $apicammaxver" : "MaxVersion of $apicam undefined - Surveillance Station may be stopped";
  1649. Log3($name, 4, "$name - $logstr");
  1650. # Pfad und Maxversion von "SYNO.SurveillanceStation.SnapShot" ermitteln
  1651. my $apitakesnappath = $data->{'data'}->{$apitakesnap}->{'path'};
  1652. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1653. $apitakesnappath =~ tr/_//d if (defined($apitakesnappath));
  1654. my $apitakesnapmaxver = $data->{'data'}->{$apitakesnap}->{'maxVersion'};
  1655. $logstr = defined($apitakesnappath) ? "Path of $apitakesnap selected: $apitakesnappath" : "Path of $apitakesnap undefined - Surveillance Station may be stopped";
  1656. Log3($name, 4, "$name - $logstr");
  1657. $logstr = defined($apitakesnapmaxver) ? "MaxVersion of $apitakesnap: $apitakesnapmaxver" : "MaxVersion of $apitakesnap undefined - Surveillance Station may be stopped";
  1658. Log3($name, 4, "$name - $logstr");
  1659. # Pfad und Maxversion von "SYNO.SurveillanceStation.PTZ" ermitteln
  1660. my $apiptzpath = $data->{'data'}->{$apiptz}->{'path'};
  1661. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1662. $apiptzpath =~ tr/_//d if (defined($apiptzpath));
  1663. my $apiptzmaxver = $data->{'data'}->{$apiptz}->{'maxVersion'};
  1664. $logstr = defined($apiptzpath) ? "Path of $apiptz selected: $apiptzpath" : "Path of $apiptz undefined - Surveillance Station may be stopped";
  1665. Log3($name, 4, "$name - $logstr");
  1666. $logstr = defined($apiptzmaxver) ? "MaxVersion of $apiptz: $apiptzmaxver" : "MaxVersion of $apiptz undefined - Surveillance Station may be stopped";
  1667. Log3($name, 4, "$name - $logstr");
  1668. # Pfad und Maxversion von "SYNO.SurveillanceStation.Info" ermitteln
  1669. my $apisvsinfopath = $data->{'data'}->{$apisvsinfo}->{'path'};
  1670. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1671. $apisvsinfopath =~ tr/_//d if (defined($apisvsinfopath));
  1672. my $apisvsinfomaxver = $data->{'data'}->{$apisvsinfo}->{'maxVersion'};
  1673. $logstr = defined($apisvsinfopath) ? "Path of $apisvsinfo selected: $apisvsinfopath" : "Path of $apisvsinfo undefined - Surveillance Station may be stopped";
  1674. Log3($name, 4, "$name - $logstr");
  1675. $logstr = defined($apisvsinfomaxver) ? "MaxVersion of $apisvsinfo: $apisvsinfomaxver" : "MaxVersion of $apisvsinfo undefined - Surveillance Station may be stopped";
  1676. Log3($name, 4, "$name - $logstr");
  1677. # Pfad und Maxversion von "SYNO.Surveillance.Camera.Event" ermitteln
  1678. my $apicameventpath = $data->{'data'}->{$apicamevent}->{'path'};
  1679. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1680. $apicameventpath =~ tr/_//d if (defined($apicameventpath));
  1681. my $apicameventmaxver = $data->{'data'}->{$apicamevent}->{'maxVersion'};
  1682. $logstr = defined($apicameventpath) ? "Path of $apicamevent selected: $apicameventpath" : "Path of $apicamevent undefined - Surveillance Station may be stopped";
  1683. Log3($name, 4, "$name - $logstr");
  1684. $logstr = defined($apicameventmaxver) ? "MaxVersion of $apicamevent: $apicameventmaxver" : "MaxVersion of $apicamevent undefined - Surveillance Station may be stopped";
  1685. Log3($name, 4, "$name - $logstr");
  1686. # Pfad und Maxversion von "SYNO.Surveillance.Event" ermitteln
  1687. my $apieventpath = $data->{'data'}->{$apievent}->{'path'};
  1688. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1689. $apieventpath =~ tr/_//d if (defined($apieventpath));
  1690. my $apieventmaxver = $data->{'data'}->{$apievent}->{'maxVersion'};
  1691. $logstr = defined($apieventpath) ? "Path of $apievent selected: $apieventpath" : "Path of $apievent undefined - Surveillance Station may be stopped";
  1692. Log3($name, 4, "$name - $logstr");
  1693. $logstr = defined($apieventmaxver) ? "MaxVersion of $apievent: $apieventmaxver" : "MaxVersion of $apievent undefined - Surveillance Station may be stopped";
  1694. Log3($name, 4, "$name - $logstr");
  1695. # Pfad und Maxversion von "SYNO.Surveillance.VideoStream" ermitteln
  1696. my $apivideostmpath = $data->{'data'}->{$apivideostm}->{'path'};
  1697. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1698. $apivideostmpath =~ tr/_//d if (defined($apivideostmpath));
  1699. my $apivideostmmaxver = $data->{'data'}->{$apivideostm}->{'maxVersion'};
  1700. $logstr = defined($apivideostmpath) ? "Path of $apivideostm selected: $apivideostmpath" : "Path of $apivideostm undefined - Surveillance Station may be stopped";
  1701. Log3($name, 4, "$name - $logstr");
  1702. $logstr = defined($apivideostmmaxver) ? "MaxVersion of $apivideostm: $apivideostmmaxver" : "MaxVersion of $apivideostm undefined - Surveillance Station may be stopped";
  1703. Log3($name, 4, "$name - $logstr");
  1704. # Pfad und Maxversion von "SYNO.SurveillanceStation.ExternalEvent" ermitteln
  1705. my $apiextevtpath = $data->{'data'}->{$apiextevt}->{'path'};
  1706. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1707. $apiextevtpath =~ tr/_//d if (defined($apiextevtpath));
  1708. my $apiextevtmaxver = $data->{'data'}->{$apiextevt}->{'maxVersion'};
  1709. $logstr = defined($apiextevtpath) ? "Path of $apiextevt selected: $apiextevtpath" : "Path of $apiextevt undefined - Surveillance Station may be stopped";
  1710. Log3($name, 4, "$name - $logstr");
  1711. $logstr = defined($apiextevtmaxver) ? "MaxVersion of $apiextevt selected: $apiextevtmaxver" : "MaxVersion of $apiextevt undefined - Surveillance Station may be stopped";
  1712. Log3($name, 4, "$name - $logstr");
  1713. # Pfad und Maxversion von "SYNO.SurveillanceStation.Streaming" ermitteln
  1714. my $apistmpath = $data->{'data'}->{$apistm}->{'path'};
  1715. # Unterstriche im Ergebnis z.B. "_______entry.cgi" eleminieren
  1716. $apistmpath =~ tr/_//d if (defined($apistmpath));
  1717. my $apistmmaxver = $data->{'data'}->{$apistm}->{'maxVersion'};
  1718. $logstr = defined($apistmpath) ? "Path of $apistm selected: $apistmpath" : "Path of $apistm undefined - Surveillance Station may be stopped";
  1719. Log3($name, 4, "$name - $logstr");
  1720. $logstr = defined($apistmmaxver) ? "MaxVersion of $apistm selected: $apistmmaxver" : "MaxVersion of $apistm undefined - Surveillance Station may be stopped";
  1721. Log3($name, 4, "$name - $logstr");
  1722. # aktuelle oder simulierte SVS-Version für Fallentscheidung setzen
  1723. no warnings 'uninitialized';
  1724. my $major = $hash->{HELPER}{SVSVERSION}{MAJOR};
  1725. my $minor = $hash->{HELPER}{SVSVERSION}{MINOR};
  1726. my $build = $hash->{HELPER}{SVSVERSION}{BUILD};
  1727. my $actvs = $major.$minor.$build;
  1728. Log3($name, 4, "$name - saved SVS version is: $actvs");
  1729. use warnings;
  1730. if(!$actvs and AttrVal($name, "simu_SVSversion", undef)) {
  1731. my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", ""));
  1732. $actvs = $vl[0];
  1733. $actvs .= $vl[1];
  1734. $actvs .= $vl[2]."-simu" if($vl[2]);
  1735. }
  1736. # Simulation anderer SVS-Versionen
  1737. Log3($name, 4, "$name - ------- Begin of simulation section -------");
  1738. if (AttrVal($name, "simu_SVSversion", undef)) {
  1739. Log3($name, 4, "$name - SVS version $actvs will be simulated");
  1740. if ($actvs =~ /^71/) {
  1741. $apicammaxver = 8;
  1742. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  1743. $apiauthmaxver = 4;
  1744. Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver");
  1745. $apiextrecmaxver = 2;
  1746. Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver");
  1747. $apiptzmaxver = 4;
  1748. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  1749. } elsif ($actvs =~ /^72/) {
  1750. $apicammaxver = 8;
  1751. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  1752. $apiauthmaxver = 6;
  1753. Log3($name, 4, "$name - MaxVersion of $apiauth adapted to: $apiauthmaxver");
  1754. $apiextrecmaxver = 3;
  1755. Log3($name, 4, "$name - MaxVersion of $apiextrec adapted to: $apiextrecmaxver");
  1756. $apiptzmaxver = 5;
  1757. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  1758. }
  1759. } else {
  1760. Log3($name, 4, "$name - no simulations done !");
  1761. }
  1762. Log3($name, 4, "$name - ------- End of simulation section -------");
  1763. # Downgrades für nicht kompatible API-Versionen
  1764. Log3($name, 4, "$name - ------- Begin of adaption section -------");
  1765. $apiptzmaxver = 4;
  1766. Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver");
  1767. $apicammaxver = 8;
  1768. Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver");
  1769. Log3($name, 4, "$name - ------- End of adaption section -------");
  1770. # ermittelte Werte in $hash einfügen
  1771. $hash->{HELPER}{APIAUTHPATH} = $apiauthpath;
  1772. $hash->{HELPER}{APIAUTHMAXVER} = $apiauthmaxver;
  1773. $hash->{HELPER}{APIEXTRECPATH} = $apiextrecpath;
  1774. $hash->{HELPER}{APIEXTRECMAXVER} = $apiextrecmaxver;
  1775. $hash->{HELPER}{APICAMPATH} = $apicampath;
  1776. $hash->{HELPER}{APICAMMAXVER} = $apicammaxver;
  1777. $hash->{HELPER}{APITAKESNAPPATH} = $apitakesnappath;
  1778. $hash->{HELPER}{APITAKESNAPMAXVER} = $apitakesnapmaxver;
  1779. $hash->{HELPER}{APIPTZPATH} = $apiptzpath;
  1780. $hash->{HELPER}{APIPTZMAXVER} = $apiptzmaxver;
  1781. $hash->{HELPER}{APISVSINFOPATH} = $apisvsinfopath;
  1782. $hash->{HELPER}{APISVSINFOMAXVER} = $apisvsinfomaxver;
  1783. $hash->{HELPER}{APICAMEVENTPATH} = $apicameventpath;
  1784. $hash->{HELPER}{APICAMEVENTMAXVER} = $apicameventmaxver;
  1785. $hash->{HELPER}{APIEVENTPATH} = $apieventpath;
  1786. $hash->{HELPER}{APIEVENTMAXVER} = $apieventmaxver;
  1787. $hash->{HELPER}{APIVIDEOSTMPATH} = $apivideostmpath;
  1788. $hash->{HELPER}{APIVIDEOSTMMAXVER} = $apivideostmmaxver;
  1789. $hash->{HELPER}{APIEXTEVTPATH} = $apiextevtpath;
  1790. $hash->{HELPER}{APIEXTEVTMAXVER} = $apiextevtmaxver;
  1791. $hash->{HELPER}{APISTMPATH} = $apistmpath;
  1792. $hash->{HELPER}{APISTMMAXVER} = $apistmmaxver;
  1793. # Setreading
  1794. readingsBeginUpdate($hash);
  1795. readingsBulkUpdate($hash,"Errorcode","none");
  1796. readingsBulkUpdate($hash,"Error","none");
  1797. readingsEndUpdate($hash,1);
  1798. # Logausgabe
  1799. Log3($name, 4, "$name - --- End Function getapisites nonblocking ---");
  1800. }
  1801. else
  1802. {
  1803. # Fehlertext setzen
  1804. my $error = "couldn't call API-Infosite";
  1805. # Setreading
  1806. readingsBeginUpdate($hash);
  1807. readingsBulkUpdate($hash,"Errorcode","none");
  1808. readingsBulkUpdate($hash,"Error",$error);
  1809. readingsEndUpdate($hash, 1);
  1810. # Logausgabe
  1811. Log3($name, 1, "$name - ERROR - the API-Query couldn't be executed successfully");
  1812. Log3($name, 4, "$name - --- End Function getapisites nonblocking with error ---");
  1813. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  1814. $hash->{HELPER}{ACTIVE} = "off";
  1815. if ($attr{$name}{debugactivetoken}) {
  1816. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1817. }
  1818. return;
  1819. }
  1820. }
  1821. # Login und SID ermitteln
  1822. Log3($name, 4, "$name - --- Begin Function serverlogin nonblocking ---");
  1823. # Credentials abrufen
  1824. (my $success, $username, $password) = getcredentials($hash,0);
  1825. unless ($success) {
  1826. Log3($name, 1, "$name - Credentials couldn't be retrieved successfully - make sure you've set it with \"set $name credentials <username> <password>\"");
  1827. $hash->{HELPER}{ACTIVE} = "off";
  1828. if ($attr{$name}{debugactivetoken}) {
  1829. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1830. }
  1831. return;
  1832. }
  1833. my $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  1834. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  1835. my $url;
  1836. my $urlwopw; # nur zur Anzeige bei verbose >=4 und "showPassInLog" == 0
  1837. my $apiauthpath = $hash->{HELPER}{APIAUTHPATH};
  1838. my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER};
  1839. # sid in Quotes einschliessen oder nicht -> bei Problemen mit 402 - Permission denied
  1840. my $sid = AttrVal($name, "noQuotesForSID", "0") == 1 ? "sid" : "\"sid\"";
  1841. if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") {
  1842. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&session=SurveillanceStation&format=$sid";
  1843. $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&session=SurveillanceStation&format=$sid";
  1844. } else {
  1845. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=$password&format=$sid";
  1846. $urlwopw = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Login&account=$username&passwd=*****&format=$sid";
  1847. }
  1848. AttrVal($name, "showPassInLog", "0") == 1 ? Log3($name, 4, "$name - Call-Out now: $url") : Log3($name, 4, "$name - Call-Out now: $urlwopw");
  1849. $param = {
  1850. url => $url,
  1851. timeout => $httptimeout,
  1852. hash => $hash,
  1853. method => "GET",
  1854. header => "Accept: application/json",
  1855. callback => \&getcamid_nonbl
  1856. };
  1857. HttpUtils_NonblockingGet ($param);
  1858. }
  1859. ###############################################################################
  1860. #### Rückkehr aus Funktion login und $sid ermitteln,
  1861. #### nach erfolgreicher Verarbeitung wird Kamera-ID ermittelt
  1862. sub getcamid_nonbl ($) {
  1863. my ($param, $err, $myjson) = @_;
  1864. my $hash = $param->{hash};
  1865. my $name = $hash->{NAME};
  1866. my $serveraddr = $hash->{SERVERADDR};
  1867. my $serverport = $hash->{SERVERPORT};
  1868. my $apicam = $hash->{HELPER}{APICAM};
  1869. my $apicampath = $hash->{HELPER}{APICAMPATH};
  1870. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  1871. my ($success, $username) = getcredentials($hash,0);
  1872. my $url;
  1873. my $data;
  1874. my $sid;
  1875. my $error;
  1876. my $errorcode;
  1877. my $httptimeout;
  1878. # Verarbeitung der asynchronen Rückkehrdaten aus sub "login_nonbl"
  1879. if ($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  1880. {
  1881. Log3($name, 1, "$name - error while requesting ".$param->{url}." - $err");
  1882. Log3($name, 4, "$name - --- End Function serverlogin nonblocking with error ---");
  1883. readingsSingleUpdate($hash, "Error", $err, 1);
  1884. # ausgeführte Funktion ist abgebrochen, Freigabe Funktionstoken
  1885. $hash->{HELPER}{ACTIVE} = "off";
  1886. if ($attr{$name}{debugactivetoken}) {
  1887. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1888. }
  1889. return;
  1890. }
  1891. elsif ($myjson ne "") # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  1892. {
  1893. # Evaluiere ob Daten im JSON-Format empfangen wurden
  1894. ($hash, $success) = &evaljson($hash,$myjson,$param->{url});
  1895. unless ($success) {
  1896. Log3($name, 4, "$name - Data returned: ".$myjson);
  1897. $hash->{HELPER}{ACTIVE} = "off";
  1898. if ($attr{$name}{debugactivetoken}) {
  1899. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1900. }
  1901. return;
  1902. }
  1903. Log3($name, 5, "$name - Data returned: ".$myjson);
  1904. $data = decode_json($myjson);
  1905. # Logausgabe decodierte JSON Daten
  1906. Log3($name, 4, "$name - JSON decoded: ". Dumper $data);
  1907. $success = $data->{'success'};
  1908. # login war erfolgreich
  1909. if ($success)
  1910. {
  1911. $sid = $data->{'data'}->{'sid'};
  1912. # Session ID in hash eintragen
  1913. $hash->{HELPER}{SID} = $sid;
  1914. # Setreading
  1915. readingsBeginUpdate($hash);
  1916. readingsBulkUpdate($hash,"Errorcode","none");
  1917. readingsBulkUpdate($hash,"Error","none");
  1918. readingsEndUpdate($hash, 1);
  1919. # Logausgabe
  1920. Log3($name, 4, "$name - Login of User $username successful - SID: $sid");
  1921. Log3($name, 4, "$name - --- End Function serverlogin nonblocking ---");
  1922. }
  1923. else
  1924. {
  1925. # Errorcode aus JSON ermitteln
  1926. $errorcode = $data->{'error'}->{'code'};
  1927. # Fehlertext zum Errorcode ermitteln
  1928. $error = &experrorauth($hash,$errorcode);
  1929. # Setreading
  1930. readingsBeginUpdate($hash);
  1931. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  1932. readingsBulkUpdate($hash,"Error",$error);
  1933. readingsEndUpdate($hash, 1);
  1934. # Logausgabe
  1935. Log3($name, 1, "$name - ERROR - Login of User $username unsuccessful. Errorcode: $errorcode - $error");
  1936. Log3($name, 4, "$name - --- End Function serverlogin nonblocking with error ---");
  1937. # ausgeführte Funktion nicht erfolgreich, Freigabe Funktionstoken
  1938. $hash->{HELPER}{ACTIVE} = "off";
  1939. if ($attr{$name}{debugactivetoken}) {
  1940. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  1941. }
  1942. return;
  1943. }
  1944. }
  1945. # die Kamera-Id wird aus dem Kameranamen (Surveillance Station) ermittelt und mit Routine "camop_nonbl" verarbeitet
  1946. Log3($name, 4, "$name - --- Begin Function getcamid nonblocking ---");
  1947. $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  1948. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  1949. # einlesen aller Kameras - Auswertung in Rückkehrfunktion "camop_nonbl"
  1950. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=List&basic=true&streamInfo=true&camStm=true&_sid=\"$sid\"";
  1951. Log3($name, 4, "$name - Call-Out now: $url");
  1952. $param = {
  1953. url => $url,
  1954. timeout => $httptimeout,
  1955. hash => $hash,
  1956. method => "GET",
  1957. header => "Accept: application/json",
  1958. callback => \&camop_nonbl
  1959. };
  1960. HttpUtils_NonblockingGet ($param);
  1961. }
  1962. #############################################################################################
  1963. #### Rückkehr aus Funktion Kamera-ID ermitteln (getcamid_nonbl),
  1964. #### nach erfolgreicher Verarbeitung wird Kameraoperation entspr. "OpMode" ausgeführt
  1965. sub camop_nonbl ($) {
  1966. my ($param, $err, $myjson) = @_;
  1967. my $hash = $param->{hash};
  1968. my $name = $hash->{NAME};
  1969. my $serveraddr = $hash->{SERVERADDR};
  1970. my $serverport = $hash->{SERVERPORT};
  1971. my $camname = $hash->{CAMNAME};
  1972. my $apicam = $hash->{HELPER}{APICAM};
  1973. my $apicampath = $hash->{HELPER}{APICAMPATH};
  1974. my $apicammaxver = $hash->{HELPER}{APICAMMAXVER};
  1975. my $apiextrec = $hash->{HELPER}{APIEXTREC};
  1976. my $apiextrecpath = $hash->{HELPER}{APIEXTRECPATH};
  1977. my $apiextrecmaxver = $hash->{HELPER}{APIEXTRECMAXVER};
  1978. my $apiextevt = $hash->{HELPER}{APIEXTEVT};
  1979. my $apiextevtpath = $hash->{HELPER}{APIEXTEVTPATH};
  1980. my $apiextevtmaxver = $hash->{HELPER}{APIEXTEVTMAXVER};
  1981. my $apitakesnap = $hash->{HELPER}{APISNAPSHOT};
  1982. my $apitakesnappath = $hash->{HELPER}{APITAKESNAPPATH};
  1983. my $apitakesnapmaxver = $hash->{HELPER}{APITAKESNAPMAXVER};
  1984. my $apiptz = $hash->{HELPER}{APIPTZ};
  1985. my $apiptzpath = $hash->{HELPER}{APIPTZPATH};
  1986. my $apiptzmaxver = $hash->{HELPER}{APIPTZMAXVER};
  1987. my $apisvsinfo = $hash->{HELPER}{APISVSINFO};
  1988. my $apisvsinfopath = $hash->{HELPER}{APISVSINFOPATH};
  1989. my $apisvsinfomaxver = $hash->{HELPER}{APISVSINFOMAXVER};
  1990. my $apicamevent = $hash->{HELPER}{APICAMEVENT};
  1991. my $apicameventpath = $hash->{HELPER}{APICAMEVENTPATH};
  1992. my $apicameventmaxver = $hash->{HELPER}{APICAMEVENTMAXVER};
  1993. my $apievent = $hash->{HELPER}{APIEVENT};
  1994. my $apieventpath = $hash->{HELPER}{APIEVENTPATH};
  1995. my $apieventmaxver = $hash->{HELPER}{APIEVENTMAXVER};
  1996. my $apivideostm = $hash->{HELPER}{APIVIDEOSTM};
  1997. my $apivideostmpath = $hash->{HELPER}{APIVIDEOSTMPATH};
  1998. my $apivideostmmaxver = $hash->{HELPER}{APIVIDEOSTMMAXVER};
  1999. my $apistm = $hash->{HELPER}{APISTM};
  2000. my $apistmpath = $hash->{HELPER}{APISTMPATH};
  2001. my $apistmmaxver = $hash->{HELPER}{APISTMMAXVER};
  2002. my $sid = $hash->{HELPER}{SID};
  2003. my $OpMode = $hash->{OPMODE};
  2004. my ($livestream,$winname,$attr,$room);
  2005. my $url;
  2006. my $camid;
  2007. my $snapid;
  2008. my $data;
  2009. my $success;
  2010. my $error;
  2011. my $errorcode;
  2012. my $camcount;
  2013. my $i;
  2014. my %allcams;
  2015. my $n;
  2016. my $id;
  2017. my $httptimeout;
  2018. my $expmode;
  2019. my $motdetsc;
  2020. # Verarbeitung der asynchronen Rückkehrdaten aus sub "getcamid_nonbl"
  2021. if ($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  2022. {
  2023. Log3($name, 1, "$name - error while requesting ".$param->{url}." - $err");
  2024. Log3($name, 4, "$name - --- End Function getcamid nonblocking with error ---");
  2025. readingsSingleUpdate($hash, "Error", $err, 1); # Readings erzeugen
  2026. return (logout_nonbl($hash));
  2027. }
  2028. elsif ($myjson ne "") # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  2029. {
  2030. # Evaluiere ob Daten im JSON-Format empfangen wurden, Achtung: sehr viele Daten mit verbose=5
  2031. ($hash, $success) = &evaljson($hash,$myjson,$param->{url});
  2032. unless ($success) {
  2033. Log3($name, 4, "$name - Data returned: ".$myjson);
  2034. return (logout_nonbl($hash));
  2035. }
  2036. $data = decode_json($myjson);
  2037. # lesbare Ausgabe der decodierten JSON-Daten
  2038. Log3($name, 5, "$name - JSON returned: ". Dumper $data);
  2039. $success = $data->{'success'};
  2040. if ($success) # die Liste aller Kameras konnte ausgelesen werden, Anzahl der definierten Kameras ist in Var "total"
  2041. {
  2042. $camcount = $data->{'data'}->{'total'};
  2043. $i = 0;
  2044. # Namen aller installierten Kameras mit Id's in Assoziatives Array einlesen
  2045. %allcams = ();
  2046. while ($i < $camcount)
  2047. {
  2048. if ($apicammaxver <= 8) {
  2049. $n = $data->{'data'}->{'cameras'}->[$i]->{'name'};
  2050. } else {
  2051. $n = $data->{'data'}->{'cameras'}->[$i]->{'newName'}; # Änderung ab SVS 8.0.0
  2052. }
  2053. $id = $data->{'data'}->{'cameras'}->[$i]->{'id'};
  2054. $allcams{"$n"} = "$id";
  2055. $i += 1;
  2056. }
  2057. # Ist der gesuchte Kameraname im Hash enhalten (in SVS eingerichtet ?)
  2058. if (exists($allcams{$camname}))
  2059. {
  2060. $camid = $allcams{$camname};
  2061. # in hash eintragen
  2062. $hash->{CAMID} = $camid;
  2063. # Logausgabe
  2064. Log3($name, 4, "$name - Detection Camid successful - $camname ID: $camid");
  2065. Log3($name, 4, "$name - --- End Function getcamid nonblocking ---");
  2066. }
  2067. else
  2068. {
  2069. # Kameraname nicht gefunden, id = ""
  2070. # Setreading
  2071. readingsBeginUpdate($hash);
  2072. readingsBulkUpdate($hash,"Errorcode","none");
  2073. readingsBulkUpdate($hash,"Error","Camera(ID) not found in Surveillance Station");
  2074. readingsEndUpdate($hash, 1);
  2075. # Logausgabe
  2076. Log3($name, 1, "$name - ERROR - Cameraname $camname wasn't found in Surveillance Station. Check Userrights, Cameraname and Spelling");
  2077. Log3($name, 4, "$name - --- End Function getcamid nonblocking with error ---");
  2078. return (logout_nonbl($hash));
  2079. }
  2080. }
  2081. else
  2082. {
  2083. # Errorcode aus JSON ermitteln
  2084. $errorcode = $data->{'error'}->{'code'};
  2085. # Fehlertext zum Errorcode ermitteln
  2086. $error = &experror($hash,$errorcode);
  2087. # Setreading
  2088. readingsBeginUpdate($hash);
  2089. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  2090. readingsBulkUpdate($hash,"Error",$error);
  2091. readingsEndUpdate($hash, 1);
  2092. Log3($name, 1, "$name - ERROR - ID of Camera $camname couldn't be selected. Errorcode: $errorcode - $error");
  2093. Log3($name, 4, "$name - --- End Function getcamid nonblocking with error ---");
  2094. return (logout_nonbl($hash));
  2095. }
  2096. Log3($name, 4, "$name - --- Begin Function $OpMode nonblocking ---");
  2097. $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  2098. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  2099. if ($OpMode eq "Start")
  2100. {
  2101. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=start&_sid=\"$sid\"";
  2102. if($apiextrecmaxver >= 3) {
  2103. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=start&_sid=\"$sid\"";
  2104. }
  2105. }
  2106. elsif ($OpMode eq "Stop")
  2107. {
  2108. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraId=$camid&action=stop&_sid=\"$sid\"";
  2109. if($apiextrecmaxver >= 3) {
  2110. $url = "http://$serveraddr:$serverport/webapi/$apiextrecpath?api=$apiextrec&method=Record&version=$apiextrecmaxver&cameraIds=$camid&action=stop&_sid=\"$sid\"";
  2111. }
  2112. }
  2113. elsif ($OpMode eq "Snap")
  2114. {
  2115. # ein Schnappschuß wird ausgelöst
  2116. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&dsId=\"0\"&method=\"TakeSnapshot\"&version=\"$apitakesnapmaxver\"&camId=\"$camid\"&blSave=\"true\"&_sid=\"$sid\"";
  2117. readingsSingleUpdate($hash,"state", "snap", 0);
  2118. readingsSingleUpdate($hash, "LastSnapId", "", 0);
  2119. }
  2120. elsif ($OpMode eq "getsnapfilename")
  2121. {
  2122. # der Filename der aktuellen Schnappschuß-ID wird ermittelt
  2123. $snapid = ReadingsVal("$name", "LastSnapId", " ");
  2124. $url = "http://$serveraddr:$serverport/webapi/$apitakesnappath?api=\"$apitakesnap\"&method=\"List\"&version=\"$apitakesnapmaxver\"&imgSize=\"0\"&idList=\"$snapid\"&_sid=\"$sid\"";
  2125. }
  2126. elsif ($OpMode eq "gopreset")
  2127. {
  2128. # Preset wird angefahren
  2129. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"GoPreset\"&position=\"$hash->{HELPER}{ALLPRESETS}{$hash->{HELPER}{GOPRESETNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\"";
  2130. readingsSingleUpdate($hash,"state", "moving", 0);
  2131. }
  2132. elsif ($OpMode eq "runpatrol")
  2133. {
  2134. # eine Überwachungstour starten
  2135. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"RunPatrol\"&patrolId=\"$hash->{HELPER}{ALLPATROLS}{$hash->{HELPER}{GOPATROLNAME}}\"&cameraId=\"$camid\"&_sid=\"$sid\"";
  2136. readingsSingleUpdate($hash,"state", "moving", 0);
  2137. }
  2138. elsif ($OpMode eq "goabsptz")
  2139. {
  2140. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"AbsPtz\"&cameraId=\"$camid\"&posX=\"$hash->{HELPER}{GOPTZPOSX}\"&posY=\"$hash->{HELPER}{GOPTZPOSY}\"&_sid=\"$sid\"";
  2141. readingsSingleUpdate($hash,"state", "moving", 0);
  2142. }
  2143. elsif ($OpMode eq "movestart")
  2144. {
  2145. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&speed=\"3\"&moveType=\"Start\"&_sid=\"$sid\"";
  2146. }
  2147. elsif ($OpMode eq "movestop")
  2148. {
  2149. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=\"$apiptz\"&version=\"$apiptzmaxver\"&method=\"Move\"&cameraId=\"$camid\"&direction=\"$hash->{HELPER}{GOMOVEDIR}\"&moveType=\"Stop\"&_sid=\"$sid\"";
  2150. }
  2151. elsif ($OpMode eq "Enable")
  2152. {
  2153. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Enable&cameraIds=$camid&_sid=\"$sid\"";
  2154. }
  2155. elsif ($OpMode eq "Disable")
  2156. {
  2157. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=Disable&cameraIds=$camid&_sid=\"$sid\"";
  2158. }
  2159. elsif ($OpMode eq "Getsvsinfo")
  2160. {
  2161. $url = "http://$serveraddr:$serverport/webapi/$apisvsinfopath?api=\"$apisvsinfo\"&version=\"$apisvsinfomaxver\"&method=\"GetInfo\"&_sid=\"$sid\"";
  2162. }
  2163. elsif ($OpMode eq "Getcaminfo")
  2164. {
  2165. $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\"";
  2166. }
  2167. elsif ($OpMode eq "getStmUrlPath")
  2168. {
  2169. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetStmUrlPath\"&cameraIds=\"$camid\"&_sid=\"$sid\"";
  2170. }
  2171. elsif ($OpMode eq "geteventlist")
  2172. {
  2173. # Abruf der Events einer Kamera
  2174. $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\"";
  2175. }
  2176. elsif ($OpMode eq "Getptzlistpreset")
  2177. {
  2178. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPreset&cameraId=$camid&_sid=\"$sid\"";
  2179. }
  2180. elsif ($OpMode eq "Getcapabilities")
  2181. {
  2182. # Capabilities einer Cam werden abgerufen
  2183. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=$apicam&version=$apicammaxver&method=GetCapabilityByCamId&cameraId=$camid&_sid=\"$sid\"";
  2184. }
  2185. elsif ($OpMode eq "Getptzlistpatrol")
  2186. {
  2187. # PTZ-ListPatrol werden abgerufen
  2188. $url = "http://$serveraddr:$serverport/webapi/$apiptzpath?api=$apiptz&version=$apiptzmaxver&method=ListPatrol&cameraId=$camid&_sid=\"$sid\"";
  2189. }
  2190. elsif ($OpMode eq "ExpMode")
  2191. {
  2192. if ($hash->{HELPER}{EXPMODE} eq "auto") {
  2193. $expmode = "0";
  2194. }
  2195. elsif ($hash->{HELPER}{EXPMODE} eq "day") {
  2196. $expmode = "1";
  2197. }
  2198. elsif ($hash->{HELPER}{EXPMODE} eq "night") {
  2199. $expmode = "2";
  2200. }
  2201. $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&cameraIds=\"$camid\"&expMode=\"$expmode\"&camParamChkList=32&_sid=\"$sid\"";
  2202. }
  2203. elsif ($OpMode eq "MotDetSc")
  2204. {
  2205. # Hash für Optionswerte sichern für Logausgabe in Befehlsauswertung
  2206. my %motdetoptions = ();
  2207. if ($hash->{HELPER}{MOTDETSC} eq "disable") {
  2208. $motdetsc = "-1";
  2209. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\"";
  2210. }
  2211. elsif ($hash->{HELPER}{MOTDETSC} eq "camera") {
  2212. $motdetsc = "0";
  2213. $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'});
  2214. $motdetoptions{OBJECTSIZE} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'});
  2215. $motdetoptions{PERCENTAGE} = $hash->{'HELPER'}{'MOTDETSC_PROP3'} if ($hash->{'HELPER'}{'MOTDETSC_PROP3'});
  2216. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&_sid=\"$sid\"";
  2217. if ($hash->{HELPER}{MOTDETSC_PROP1} || $hash->{HELPER}{MOTDETSC_PROP2} || $hash->{HELPER}{MOTDETSC_PROP13}) {
  2218. # umschalten und neue Werte setzen
  2219. $url .= "&keep=false";
  2220. } else {
  2221. # nur Umschaltung, alte Werte beibehalten
  2222. $url .= "&keep=true";
  2223. }
  2224. if ($hash->{HELPER}{MOTDETSC_PROP1}) {
  2225. # der Wert für Bewegungserkennung Kamera -> Empfindlichkeit ist gesetzt
  2226. my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1};
  2227. $url .= "&sensitivity=\"$sensitivity\"";
  2228. }
  2229. if ($hash->{HELPER}{MOTDETSC_PROP2}) {
  2230. # der Wert für Bewegungserkennung Kamera -> Objektgröße ist gesetzt
  2231. my $objectsize = delete $hash->{HELPER}{MOTDETSC_PROP2};
  2232. $url .= "&objectSize=\"$objectsize\"";
  2233. }
  2234. if ($hash->{HELPER}{MOTDETSC_PROP3}) {
  2235. # der Wert für Bewegungserkennung Kamera -> Prozentsatz für Auslösung ist gesetzt
  2236. my $percentage = delete $hash->{HELPER}{MOTDETSC_PROP3};
  2237. $url .= "&percentage=\"$percentage\"";
  2238. }
  2239. }
  2240. elsif ($hash->{HELPER}{MOTDETSC} eq "SVS") {
  2241. $motdetsc = "1";
  2242. $motdetoptions{SENSITIVITY} = $hash->{'HELPER'}{'MOTDETSC_PROP1'} if ($hash->{'HELPER'}{'MOTDETSC_PROP1'});
  2243. $motdetoptions{THRESHOLD} = $hash->{'HELPER'}{'MOTDETSC_PROP2'} if ($hash->{'HELPER'}{'MOTDETSC_PROP2'});
  2244. # nur Umschaltung, alte Werte beibehalten
  2245. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MDParamSave\"&camId=\"$camid\"&source=$motdetsc&keep=true&_sid=\"$sid\"";
  2246. if ($hash->{HELPER}{MOTDETSC_PROP1}) {
  2247. # der Wert für Bewegungserkennung SVS -> Empfindlichkeit ist gesetzt
  2248. my $sensitivity = delete $hash->{HELPER}{MOTDETSC_PROP1};
  2249. $url .= "&sensitivity=\"$sensitivity\"";
  2250. }
  2251. if ($hash->{HELPER}{MOTDETSC_PROP2}) {
  2252. # der Wert für Bewegungserkennung SVS -> Schwellwert ist gesetzt
  2253. my $threshold = delete $hash->{HELPER}{MOTDETSC_PROP2};
  2254. $url .= "&threshold=\"$threshold\"";
  2255. }
  2256. }
  2257. # Optionswerte in Hash sichern für Logausgabe in Befehlsauswertung
  2258. $hash->{HELPER}{MOTDETOPTIONS} = \%motdetoptions;
  2259. }
  2260. elsif ($OpMode eq "getmotionenum")
  2261. {
  2262. $url = "http://$serveraddr:$serverport/webapi/$apicameventpath?api=\"$apicamevent\"&version=\"$apicameventmaxver\"&method=\"MotionEnum\"&camId=\"$camid\"&_sid=\"$sid\"";
  2263. }
  2264. elsif ($OpMode eq "extevent")
  2265. {
  2266. $url = "http://$serveraddr:$serverport/webapi/$apiextevtpath?api=$apiextevt&version=$apiextevtmaxver&method=Trigger&eventId=$hash->{HELPER}{EVENTID}&eventName=$hash->{HELPER}{EVENTID}&_sid=\"$sid\"";
  2267. }
  2268. elsif ($OpMode eq "runliveview")
  2269. {
  2270. # SID nach SID_STRM sichern und nutzen (für stopLiveview-Routine)
  2271. $hash->{HELPER}{SID_STRM} = $sid;
  2272. if ($hash->{HELPER}{WLTYPE} ne "lastrec") {
  2273. # externe URL
  2274. $livestream = !AttrVal($name, "livestreamprefix", undef) ? "http://$serveraddr:$serverport" : AttrVal($name, "livestreamprefix", undef);
  2275. $livestream .= "/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\"";
  2276. # interne URL
  2277. $url = "http://$serveraddr:$serverport/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\"";
  2278. readingsSingleUpdate($hash,"LiveStreamUrl", $livestream, 1) if(AttrVal($name, "showStmInfoFull", undef));
  2279. }
  2280. else
  2281. {
  2282. # Abspielen der letzten Aufnahme (EventId)
  2283. $url = "http://$serveraddr:$serverport/webapi/$apistmpath?api=$apistm&version=$apistmmaxver&method=EventStream&eventId=$hash->{HELPER}{CAMLASTRECID}&_sid=$sid";
  2284. }
  2285. # Liveview-Link in Hash speichern -> Anzeige über SSCam_liveview, in Reading setzen für Linkversand
  2286. $hash->{HELPER}{LINK} = $url;
  2287. Log3($name, 4, "$name - Set Streaming-URL: $url");
  2288. # livestream sofort in neuem Browsertab öffnen
  2289. if ($hash->{HELPER}{OPENWINDOW}) {
  2290. $winname = $name."_view";
  2291. $attr = AttrVal($name, "htmlattr", "");
  2292. # öffnen streamwindow für die Instanz die "VIEWOPENROOM" oder Attr "room" aktuell geöffnet hat
  2293. if ($hash->{HELPER}{VIEWOPENROOM}) {
  2294. $room = $hash->{HELPER}{VIEWOPENROOM};
  2295. map {FW_directNotify("FILTER=room=$room", "#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*");
  2296. } else {
  2297. map {FW_directNotify("#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*");
  2298. }
  2299. }
  2300. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2301. if (ReadingsVal("$name", "Record", "") eq "Start") {
  2302. readingsSingleUpdate( $hash,"state", "on", 1);
  2303. }
  2304. else
  2305. {
  2306. readingsSingleUpdate($hash,"state", "off", 1);
  2307. }
  2308. $hash->{HELPER}{ACTIVE} = "off";
  2309. return;
  2310. }
  2311. Log3($name, 4, "$name - Call-Out now: $url");
  2312. $param = {
  2313. url => $url,
  2314. timeout => $httptimeout,
  2315. hash => $hash,
  2316. method => "GET",
  2317. header => "Accept: application/json",
  2318. callback => \&camret_nonbl
  2319. };
  2320. HttpUtils_NonblockingGet ($param);
  2321. }
  2322. }
  2323. ###################################################################################
  2324. #### Rückkehr aus Funktion camop_nonbl,
  2325. #### Check ob Kameraoperation erfolgreich wie in "OpMOde" definiert
  2326. #### danach Verarbeitung Nutzdaten und weiter zum Logout
  2327. sub camret_nonbl ($) {
  2328. my ($param, $err, $myjson) = @_;
  2329. my $hash = $param->{hash};
  2330. my $name = $hash->{NAME};
  2331. my $serveraddr = $hash->{SERVERADDR};
  2332. my $serverport = $hash->{SERVERPORT};
  2333. my $camname = $hash->{CAMNAME};
  2334. my $apiauth = $hash->{HELPER}{APIAUTH};
  2335. my $apiauthpath = $hash->{HELPER}{APIAUTHPATH};
  2336. my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER};
  2337. my $sid = $hash->{HELPER}{SID};
  2338. my $OpMode = $hash->{OPMODE};
  2339. my $rectime;
  2340. my $logstr;
  2341. my $data;
  2342. my $success;
  2343. my ($error,$errorcode);
  2344. my $snapid;
  2345. my $camLiveMode;
  2346. my $update_time;
  2347. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
  2348. my $deviceType;
  2349. my $camStatus;
  2350. my ($patrolcnt,$patrolid,$patrolname,@patrolkeys,$patrollist);
  2351. my ($recStatus,$exposuremode,$exposurecontrol);
  2352. my $userPriv;
  2353. my $verbose;
  2354. my $httptimeout;
  2355. my $motdetsc;
  2356. my ($sensitivity_camCap,$sensitivity_value,$sensitivity_ssCap);
  2357. my ($threshold_camCap,$threshold_value,$threshold_ssCap);
  2358. my ($percentage_camCap,$percentage_value,$percentage_ssCap);
  2359. my ($objectSize_camCap,$objectSize_value,$objectSize_ssCap);
  2360. if ($err ne "")
  2361. {
  2362. # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  2363. Log3($name, 1, "$name - error while requesting ".$param->{url}." - $err");
  2364. Log3($name, 4, "$name - --- End Function $OpMode nonblocking with error ---");
  2365. readingsSingleUpdate($hash, "Error", $err, 1);
  2366. return (logout_nonbl($hash));
  2367. }
  2368. elsif ($myjson ne "")
  2369. {
  2370. # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  2371. # Evaluiere ob Daten im JSON-Format empfangen wurden
  2372. ($hash, $success) = &evaljson($hash,$myjson,$param->{url});
  2373. unless ($success) {
  2374. Log3($name, 4, "$name - Data returned: ".$myjson);
  2375. return (logout_nonbl($hash));
  2376. }
  2377. $data = decode_json($myjson);
  2378. # Logausgabe decodierte JSON Daten
  2379. Log3($name, 4, "$name - JSON returned: ". Dumper $data);
  2380. $success = $data->{'success'};
  2381. if ($success) {
  2382. # Kameraoperation entsprechend "OpMode" war erfolgreich
  2383. if ($OpMode eq "Start") {
  2384. # Die Aufnahmezeit setzen
  2385. # wird "set <name> on [rectime]" verwendet -> dann [rectime] nutzen,
  2386. # sonst Attribut "rectime" wenn es gesetzt ist, falls nicht -> "RECTIME_DEF"
  2387. if (defined($hash->{HELPER}{RECTIME_TEMP})) {
  2388. $rectime = delete $hash->{HELPER}{RECTIME_TEMP};
  2389. } else {
  2390. if (defined($attr{$name}{rectime}) && AttrVal($name,"rectime", undef) == 0) {
  2391. $rectime = 0;
  2392. } else {
  2393. $rectime = AttrVal($name, "rectime", undef) ? AttrVal($name, "rectime", undef) : $hash->{HELPER}{RECTIME_DEF};
  2394. }
  2395. }
  2396. if ($rectime == "0") {
  2397. $logstr = "Camera $camname endless Recording started - stop it by stop-command !";
  2398. } else {
  2399. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2400. # Aufnahme läuft schon und wird verlängert
  2401. Log3($name, 3, "$name - running recording renewed to $rectime s");
  2402. } else {
  2403. Log3($name, 3, "$name - Camera $camname Recording with Recordtime $rectime s started");
  2404. }
  2405. }
  2406. # Setreading
  2407. readingsBeginUpdate($hash);
  2408. readingsBulkUpdate($hash,"Record","Start");
  2409. readingsBulkUpdate($hash,"state","on");
  2410. readingsBulkUpdate($hash,"Errorcode","none");
  2411. readingsBulkUpdate($hash,"Error","none");
  2412. readingsEndUpdate($hash, 1);
  2413. if ($rectime != 0) {
  2414. # Stop der Aufnahme nach Ablauf $rectime, wenn rectime = 0 -> endlose Aufnahme
  2415. RemoveInternalTimer($hash, "camstoprec");
  2416. InternalTimer(gettimeofday()+$rectime, "camstoprec", $hash);
  2417. }
  2418. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2419. }
  2420. elsif ($OpMode eq "Stop")
  2421. {
  2422. # Setreading
  2423. readingsBeginUpdate($hash);
  2424. readingsBulkUpdate($hash,"Record","Stop");
  2425. readingsBulkUpdate($hash,"state","off");
  2426. readingsBulkUpdate($hash,"Errorcode","none");
  2427. readingsBulkUpdate($hash,"Error","none");
  2428. readingsEndUpdate($hash, 1);
  2429. # Logausgabe
  2430. Log3($name, 3, "$name - Camera $camname Recording stopped");
  2431. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2432. # Aktualisierung Eventlist der letzten Aufnahme
  2433. geteventlist($hash);
  2434. }
  2435. elsif ($OpMode eq "ExpMode")
  2436. {
  2437. # Setreading
  2438. readingsBeginUpdate($hash);
  2439. readingsBulkUpdate($hash,"Errorcode","none");
  2440. readingsBulkUpdate($hash,"Error","none");
  2441. readingsEndUpdate($hash, 1);
  2442. # Logausgabe
  2443. Log3($name, 3, "$name - Camera $camname exposure mode was set to \"$hash->{HELPER}{EXPMODE}\"");
  2444. Log3($name, 4, "$name - --- End Function $OpMode nonblocking --");
  2445. }
  2446. elsif ($OpMode eq "MotDetSc")
  2447. {
  2448. # Setreading
  2449. readingsBeginUpdate($hash);
  2450. readingsBulkUpdate($hash,"Errorcode","none");
  2451. readingsBulkUpdate($hash,"Error","none");
  2452. readingsEndUpdate($hash, 1);
  2453. # Logausgabe
  2454. my $sensitivity;
  2455. if ($hash->{HELPER}{MOTDETSC} eq "SVS" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) {
  2456. # Optionen für "SVS" sind gesetzt
  2457. $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-";
  2458. my $threshold = ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) ? ($hash->{HELPER}{MOTDETOPTIONS}{THRESHOLD}) : "-";
  2459. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, threshold: $threshold");
  2460. } elsif ($hash->{HELPER}{MOTDETSC} eq "camera" && keys %{$hash->{HELPER}{MOTDETOPTIONS}}) {
  2461. # Optionen für "camera" sind gesetzt
  2462. $sensitivity = ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) ? ($hash->{HELPER}{MOTDETOPTIONS}{SENSITIVITY}) : "-";
  2463. my $objectSize = ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{OBJECTSIZE}) : "-";
  2464. my $percentage = ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) ? ($hash->{HELPER}{MOTDETOPTIONS}{PERCENTAGE}) : "-";
  2465. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" with options sensitivity: $sensitivity, objectSize: $objectSize, percentage: $percentage");
  2466. } else {
  2467. # keine Optionen Bewegungserkennung wurden gesetzt
  2468. Log3($name, 3, "$name - Camera $camname motion detection source set to \"$hash->{HELPER}{MOTDETSC}\" ");
  2469. }
  2470. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2471. }
  2472. elsif ($OpMode eq "Snap")
  2473. {
  2474. # ein Schnapschuß wurde aufgenommen
  2475. # falls Aufnahme noch läuft -> state = on setzen
  2476. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2477. readingsSingleUpdate( $hash,"state", "on", 0);
  2478. }
  2479. else
  2480. {
  2481. readingsSingleUpdate($hash,"state", "off", 0);
  2482. }
  2483. $snapid = $data->{data}{'id'};
  2484. # Setreading
  2485. readingsBeginUpdate($hash);
  2486. readingsBulkUpdate($hash,"Errorcode","none");
  2487. readingsBulkUpdate($hash,"Error","none");
  2488. readingsBulkUpdate($hash,"LastSnapId",$snapid);
  2489. readingsEndUpdate($hash, 1);
  2490. # Logausgabe
  2491. Log3($name, 3, "$name - Snapshot of Camera $camname has been done successfully");
  2492. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2493. # nach Snap Aufnahme Filename des Snaps ermitteln
  2494. getsnapfilename($hash);
  2495. }
  2496. elsif ($OpMode eq "getsnapfilename")
  2497. {
  2498. # den Filenamen eines Schnapschusses ermitteln
  2499. $snapid = ReadingsVal("$name", "LastSnapId", " ");
  2500. # Setreading
  2501. readingsBeginUpdate($hash);
  2502. readingsBulkUpdate($hash,"Errorcode","none");
  2503. readingsBulkUpdate($hash,"Error","none");
  2504. readingsBulkUpdate($hash,"LastSnapFilename", $data->{'data'}{'data'}[0]{'fileName'});
  2505. readingsEndUpdate($hash, 1);
  2506. # Logausgabe
  2507. Log3($name, 4, "$name - Filename of Snap-ID $snapid is \"$data->{'data'}{'data'}[0]{'fileName'}\"");
  2508. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2509. }
  2510. elsif ($OpMode eq "gopreset")
  2511. {
  2512. # eine Presetposition wurde angefahren
  2513. # falls Aufnahme noch läuft -> state = on setzen
  2514. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2515. readingsSingleUpdate($hash,"state", "on", 0);
  2516. }
  2517. else
  2518. {
  2519. readingsSingleUpdate($hash,"state", "off", 0);
  2520. }
  2521. # Setreading
  2522. readingsBeginUpdate($hash);
  2523. readingsBulkUpdate($hash,"Errorcode","none");
  2524. readingsBulkUpdate($hash,"Error","none");
  2525. readingsEndUpdate($hash, 1);
  2526. # Logausgabe
  2527. Log3($name, 3, "$name - Camera $camname has been moved to position \"$hash->{HELPER}{GOPRESETNAME}\"");
  2528. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2529. }
  2530. elsif ($OpMode eq "runpatrol")
  2531. {
  2532. # eine Tour wurde gestartet
  2533. # falls Aufnahme noch läuft -> state = on setzen
  2534. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2535. readingsSingleUpdate($hash,"state", "on", 0);
  2536. }
  2537. else
  2538. {
  2539. readingsSingleUpdate($hash,"state", "off", 0);
  2540. }
  2541. # Setreading
  2542. readingsBeginUpdate($hash);
  2543. readingsBulkUpdate($hash,"Errorcode","none");
  2544. readingsBulkUpdate($hash,"Error","none");
  2545. readingsEndUpdate($hash, 1);
  2546. # Logausgabe
  2547. Log3($name, 3, "$name - Patrol \"$hash->{HELPER}{GOPATROLNAME}\" of camera $camname has been started successfully");
  2548. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2549. }
  2550. elsif ($OpMode eq "goabsptz")
  2551. {
  2552. # eine absolute PTZ-Position wurde angefahren
  2553. # falls Aufnahme noch läuft -> state = on setzen
  2554. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2555. readingsSingleUpdate($hash,"state", "on", 0);
  2556. }
  2557. else
  2558. {
  2559. readingsSingleUpdate($hash,"state", "off", 0);
  2560. }
  2561. # Setreading
  2562. readingsBeginUpdate($hash);
  2563. readingsBulkUpdate($hash,"Errorcode","none");
  2564. readingsBulkUpdate($hash,"Error","none");
  2565. readingsEndUpdate($hash, 1);
  2566. # Logausgabe
  2567. Log3($name, 3, "$name - Camera $camname has been moved to absolute position \"posX=$hash->{HELPER}{GOPTZPOSX}\" and \"posY=$hash->{HELPER}{GOPTZPOSY}\"");
  2568. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2569. }
  2570. elsif ($OpMode eq "movestart")
  2571. {
  2572. # ein "Move" in eine bestimmte Richtung wird durchgeführt
  2573. # Setreading
  2574. readingsBeginUpdate($hash);
  2575. readingsBulkUpdate($hash,"state","moving");
  2576. readingsBulkUpdate($hash,"Errorcode","none");
  2577. readingsBulkUpdate($hash,"Error","none");
  2578. readingsEndUpdate($hash, 1);
  2579. # Logausgabe
  2580. Log3($name, 3, "$name - Camera $camname started move to direction \"$hash->{HELPER}{GOMOVEDIR}\" with duration of $hash->{HELPER}{GOMOVETIME} s");
  2581. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2582. RemoveInternalTimer($hash, "movestop");
  2583. InternalTimer(gettimeofday()+($hash->{HELPER}{GOMOVETIME}), "movestop", $hash);
  2584. }
  2585. elsif ($OpMode eq "movestop")
  2586. {
  2587. # ein "Move" in eine bestimmte Richtung wurde durchgeführt
  2588. # falls Aufnahme noch läuft -> state = on setzen
  2589. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2590. readingsSingleUpdate($hash,"state", "on", 0);
  2591. }
  2592. else
  2593. {
  2594. readingsSingleUpdate($hash,"state", "off", 0);
  2595. }
  2596. # Setreading
  2597. readingsBeginUpdate($hash);
  2598. readingsBulkUpdate($hash,"Errorcode","none");
  2599. readingsBulkUpdate($hash,"Error","none");
  2600. readingsEndUpdate($hash, 1);
  2601. # Logausgabe
  2602. Log3($name, 3, "$name - Camera $camname stopped move to direction \"$hash->{HELPER}{GOMOVEDIR}\"");
  2603. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2604. }
  2605. elsif ($OpMode eq "Enable")
  2606. {
  2607. # Kamera wurde aktiviert, sonst kann nichts laufen -> "off"
  2608. # Setreading
  2609. readingsBeginUpdate($hash);
  2610. readingsBulkUpdate($hash,"Availability","enabled");
  2611. readingsBulkUpdate($hash,"state","off");
  2612. readingsBulkUpdate($hash,"Errorcode","none");
  2613. readingsBulkUpdate($hash,"Error","none");
  2614. readingsEndUpdate($hash, 1);
  2615. # Logausgabe
  2616. Log3($name, 3, "$name - Camera $camname has been enabled successfully");
  2617. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2618. }
  2619. elsif ($OpMode eq "Disable")
  2620. {
  2621. # Kamera wurde deaktiviert
  2622. # Setreading
  2623. readingsBeginUpdate($hash);
  2624. readingsBulkUpdate($hash,"Availability","disabled");
  2625. readingsBulkUpdate($hash,"state","disabled");
  2626. readingsBulkUpdate($hash,"Errorcode","none");
  2627. readingsBulkUpdate($hash,"Error","none");
  2628. readingsEndUpdate($hash, 1);
  2629. # Logausgabe
  2630. Log3($name, 3, "$name - Camera $camname has been disabled successfully");
  2631. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2632. }
  2633. elsif ($OpMode eq "Getsvsinfo")
  2634. {
  2635. # Parse SVS-Infos
  2636. $userPriv = $data->{'data'}{'userPriv'};
  2637. if (defined($userPriv)) {
  2638. if ($userPriv eq "0") {
  2639. $userPriv = "No Access";
  2640. }
  2641. elsif ($userPriv eq "1") {
  2642. $userPriv = "Admin";
  2643. }
  2644. elsif ($userPriv eq "2") {
  2645. $userPriv = "Manager";
  2646. }
  2647. elsif ($userPriv eq "4") {
  2648. $userPriv = "Viewer";
  2649. }
  2650. }
  2651. # "my" nicht am Anfang deklarieren, sonst wird Hash %version wieder geleert !
  2652. my %version = (
  2653. MAJOR => $data->{'data'}{'version'}{'major'},
  2654. MINOR => $data->{'data'}{'version'}{'minor'},
  2655. BUILD => $data->{'data'}{'version'}{'build'}
  2656. );
  2657. # simulieren einer anderen SVS-Version
  2658. if (AttrVal($name, "simu_SVSversion", undef)) {
  2659. Log3($name, 4, "$name - another SVS-version ".AttrVal($name, "simu_SVSversion", undef)." will be simulated");
  2660. my @vl = split (/\.|-/,AttrVal($name, "simu_SVSversion", ""));
  2661. $version {"MAJOR"} = $vl[0];
  2662. $version {"MINOR"} = $vl[1];
  2663. $version {"BUILD"} = $vl[2]."-simu" if($vl[2]);
  2664. }
  2665. # Werte in $hash zur späteren Auswertung einfügen
  2666. $hash->{HELPER}{SVSVERSION} = \%version;
  2667. if (!exists($data->{'data'}{'customizedPortHttp'})) {
  2668. delete $defs{$name}{READINGS}{SVScustomPortHttp};
  2669. }
  2670. if (!exists($data->{'data'}{'customizedPortHttps'})) {
  2671. delete $defs{$name}{READINGS}{SVScustomPortHttps};
  2672. }
  2673. # Setreading
  2674. readingsBeginUpdate($hash);
  2675. readingsBulkUpdate($hash,"SVScustomPortHttp",$data->{'data'}{'customizedPortHttp'});
  2676. readingsBulkUpdate($hash,"SVScustomPortHttps",$data->{'data'}{'customizedPortHttps'});
  2677. readingsBulkUpdate($hash,"SVSlicenseNumber",$data->{'data'}{'liscenseNumber'});
  2678. readingsBulkUpdate($hash,"SVSuserPriv",$userPriv);
  2679. # readingsBulkUpdate($hash,"SVSversion",$data->{'data'}{'version'}{'major'}.".".$data->{'data'}{'version'}{'minor'}."-".$data->{'data'}{'version'}{'build'});
  2680. readingsBulkUpdate($hash,"SVSversion",$version {"MAJOR"}.".".$version {"MINOR"}."-".$version {"BUILD"});
  2681. readingsBulkUpdate($hash,"Errorcode","none");
  2682. readingsBulkUpdate($hash,"Error","none");
  2683. readingsEndUpdate($hash, 1);
  2684. # Logausgabe
  2685. Log3($name, 3, "$name - Informations related to Surveillance Station retrieved successfully");
  2686. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2687. }
  2688. elsif ($OpMode eq "getStmUrlPath")
  2689. {
  2690. # Parse SVS-Infos
  2691. my $camforcemcast = $data->{'data'}{'pathInfos'}[0]{'forceEnableMulticast'};
  2692. my $mjpegHttp = $data->{'data'}{'pathInfos'}[0]{'mjpegHttpPath'};
  2693. my $multicst = $data->{'data'}{'pathInfos'}[0]{'multicstPath'};
  2694. my $mxpegHttp = $data->{'data'}{'pathInfos'}[0]{'mxpegHttpPath'};
  2695. my $unicastOverHttp = $data->{'data'}{'pathInfos'}[0]{'unicastOverHttpPath'};
  2696. my $unicastPath = $data->{'data'}{'pathInfos'}[0]{'unicastPath'};
  2697. # Rewrite Url's falls livestreamprefix ist gesetzt
  2698. if (AttrVal($name, "livestreamprefix", undef)) {
  2699. my @mjh = split(/\//, $mjpegHttp, 4);
  2700. $mjpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mjh[3];
  2701. my @mxh = split(/\//, $mxpegHttp, 4);
  2702. $mxpegHttp = AttrVal($name, "livestreamprefix", undef)."/".$mxh[3];
  2703. my @ucp = split(/[@\|:]/, $unicastPath);
  2704. my @lspf = split(/[\/\/\|:]/, AttrVal($name, "livestreamprefix", undef));
  2705. $unicastPath = $ucp[0].":".$ucp[1].":".$ucp[2]."@".$lspf[3].":".$ucp[4];
  2706. }
  2707. # StmKey extrahieren
  2708. my @sk = split(/&StmKey=/, $mjpegHttp);
  2709. my $stmkey = $sk[1];
  2710. $stmkey =~ tr/"//d;
  2711. # Readings löschen falls sie nicht angezeigt werden sollen (showStmInfoFull)
  2712. if (!AttrVal($name, "showStmInfoFull", undef)) {
  2713. delete($defs{$name}{READINGS}{StmKeymjpegHttp}) if ($defs{$name}{READINGS}{StmKeymjpegHttp});
  2714. delete($defs{$name}{READINGS}{StmKeyUnicst}) if ($defs{$name}{READINGS}{StmKeyUnicst});
  2715. }
  2716. # Setreading
  2717. readingsBeginUpdate($hash);
  2718. readingsBulkUpdate($hash,"CamForceEnableMulticast",$camforcemcast);
  2719. readingsBulkUpdate($hash,"StmKey",$stmkey);
  2720. readingsBulkUpdate($hash,"StmKeymjpegHttp",$mjpegHttp) if (AttrVal($name, "showStmInfoFull", undef));
  2721. # readingsBulkUpdate($hash,"StmKeymxpegHttp",$mxpegHttp);
  2722. readingsBulkUpdate($hash,"StmKeyUnicst",$unicastPath) if (AttrVal($name, "showStmInfoFull", undef));
  2723. readingsBulkUpdate($hash,"Errorcode","none");
  2724. readingsBulkUpdate($hash,"Error","none");
  2725. readingsEndUpdate($hash, 1);
  2726. # Logausgabe
  2727. Log3($name, 4, "$name - Stream-URLs of $camname retrieved successfully");
  2728. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2729. }
  2730. elsif ($OpMode eq "Getcaminfo")
  2731. {
  2732. # Parse Caminfos
  2733. $camLiveMode = $data->{'data'}->{'cameras'}->[0]->{'camLiveMode'};
  2734. if ($camLiveMode eq "0") {$camLiveMode = "Liveview from DS";}elsif ($camLiveMode eq "1") {$camLiveMode = "Liveview from Camera";}
  2735. # $update_time = $data->{'data'}->{'cameras'}->[0]->{'update_time'};
  2736. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  2737. $update_time = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ;
  2738. $deviceType = $data->{'data'}->{'cameras'}->[0]->{'deviceType'};
  2739. if ($deviceType eq "1") {
  2740. $deviceType = "Camera";
  2741. }
  2742. elsif ($deviceType eq "2") {
  2743. $deviceType = "Video_Server";
  2744. }
  2745. elsif ($deviceType eq "4") {
  2746. $deviceType = "PTZ";
  2747. }
  2748. elsif ($deviceType eq "8") {
  2749. $deviceType = "Fisheye";
  2750. }
  2751. $camStatus = $data->{'data'}->{'cameras'}->[0]->{'camStatus'};
  2752. if ($camStatus eq "1") {
  2753. $camStatus = "enabled";
  2754. # falls Aufnahme noch läuft -> STATE = on setzen
  2755. if (ReadingsVal("$name", "Record", "Stop") eq "Start") {
  2756. readingsSingleUpdate($hash,"state", "on", 0);
  2757. }
  2758. else
  2759. {
  2760. readingsSingleUpdate($hash,"state", "off", 0);
  2761. }
  2762. }
  2763. elsif ($camStatus eq "3") {
  2764. $camStatus = "disconnected";
  2765. readingsSingleUpdate($hash,"state", "disconnected", 0);
  2766. }
  2767. elsif ($camStatus eq "7") {
  2768. $camStatus = "disabled";
  2769. readingsSingleUpdate($hash,"state", "disabled ", 0);
  2770. }
  2771. else {
  2772. $camStatus = "other";
  2773. }
  2774. $recStatus = $data->{'data'}->{'cameras'}->[0]->{'recStatus'};
  2775. if ($recStatus ne "0") {
  2776. $recStatus = "Start";
  2777. }
  2778. else {
  2779. $recStatus = "Stop";
  2780. }
  2781. $exposuremode = $data->{'data'}->{'cameras'}->[0]->{'exposure_mode'};
  2782. if ($exposuremode == 0) {
  2783. $exposuremode = "Auto";
  2784. }
  2785. elsif ($exposuremode == 1) {
  2786. $exposuremode = "Day";
  2787. }
  2788. elsif ($exposuremode == 2) {
  2789. $exposuremode = "Night";
  2790. }
  2791. elsif ($exposuremode == 3) {
  2792. $exposuremode = "Schedule";
  2793. }
  2794. elsif ($exposuremode == 4) {
  2795. $exposuremode = "Unknown";
  2796. }
  2797. $exposurecontrol = $data->{'data'}->{'cameras'}->[0]->{'exposure_control'};
  2798. if ($exposurecontrol == 0) {
  2799. $exposurecontrol = "Auto";
  2800. }
  2801. elsif ($exposurecontrol == 1) {
  2802. $exposurecontrol = "50HZ";
  2803. }
  2804. elsif ($exposurecontrol == 2) {
  2805. $exposurecontrol = "60HZ";
  2806. }
  2807. elsif ($exposurecontrol == 3) {
  2808. $exposurecontrol = "Hold";
  2809. }
  2810. elsif ($exposurecontrol == 4) {
  2811. $exposurecontrol = "Outdoor";
  2812. }
  2813. elsif ($exposurecontrol == 5) {
  2814. $exposurecontrol = "None";
  2815. }
  2816. elsif ($exposurecontrol == 6) {
  2817. $exposurecontrol = "Unknown";
  2818. }
  2819. # Setreading
  2820. readingsBeginUpdate($hash);
  2821. readingsBulkUpdate($hash,"CamLiveMode",$camLiveMode);
  2822. readingsBulkUpdate($hash,"CamExposureMode",$exposuremode);
  2823. readingsBulkUpdate($hash,"CamExposureControl",$exposurecontrol);
  2824. readingsBulkUpdate($hash,"CamModel",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camModel'});
  2825. readingsBulkUpdate($hash,"CamRecShare",$data->{'data'}->{'cameras'}->[0]->{'camRecShare'});
  2826. readingsBulkUpdate($hash,"CamRecVolume",$data->{'data'}->{'cameras'}->[0]->{'camRecVolume'});
  2827. readingsBulkUpdate($hash,"CamIP",$data->{'data'}->{'cameras'}->[0]->{'host'});
  2828. readingsBulkUpdate($hash,"CamVendor",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'});
  2829. readingsBulkUpdate($hash,"CamPreRecTime",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'});
  2830. readingsBulkUpdate($hash,"CamPort",$data->{'data'}->{'cameras'}->[0]->{'port'});
  2831. readingsBulkUpdate($hash,"CamPtSpeed",$data->{'data'}->{'cameras'}->[0]->{'ptSpeed'});
  2832. readingsBulkUpdate($hash,"CamblPresetSpeed",$data->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'});
  2833. readingsBulkUpdate($hash,"CamVideoMirror",$data->{'data'}->{'cameras'}->[0]->{'video_mirror'});
  2834. readingsBulkUpdate($hash,"CamVideoFlip",$data->{'data'}->{'cameras'}->[0]->{'video_flip'});
  2835. readingsBulkUpdate($hash,"Availability",$camStatus);
  2836. readingsBulkUpdate($hash,"DeviceType",$deviceType);
  2837. readingsBulkUpdate($hash,"LastUpdateTime",$update_time);
  2838. readingsBulkUpdate($hash,"Record",$recStatus);
  2839. readingsBulkUpdate($hash,"UsedSpaceMB",$data->{'data'}->{'cameras'}->[0]->{'volume_space'});
  2840. readingsBulkUpdate($hash,"VideoFolder",AttrVal($name, "videofolderMap", undef) ? AttrVal($name, "videofolderMap", undef) : $data->{'data'}->{'cameras'}->[0]->{'folder'});
  2841. readingsBulkUpdate($hash,"Errorcode","none");
  2842. readingsBulkUpdate($hash,"Error","none");
  2843. readingsEndUpdate($hash, 1);
  2844. # Logausgabe
  2845. $logstr = "Camera-Informations of $camname retrieved";
  2846. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3
  2847. if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") {
  2848. $verbose = 4;
  2849. }
  2850. else
  2851. {
  2852. $verbose = 3;
  2853. }
  2854. Log3($name, $verbose, "$name - $logstr");
  2855. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2856. }
  2857. elsif ($OpMode eq "geteventlist")
  2858. {
  2859. my $eventnum = $data->{'data'}{'total'};
  2860. my $lastrecord = $data->{'data'}{'events'}[0]{name};
  2861. $hash->{HELPER}{CAMLASTRECID} = $data->{'data'}{'events'}[0]{'eventId'};
  2862. my ($lastrecstarttime,$lastrecstoptime);
  2863. if ($eventnum > 0) {
  2864. $lastrecstarttime = $data->{'data'}{'events'}[0]{startTime};
  2865. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstarttime);
  2866. $lastrecstarttime = sprintf "%02d.%02d.%04d / %02d:%02d:%02d" , $mday , $mon+=1 ,$year+=1900 , $hour , $min , $sec ;
  2867. $lastrecstoptime = $data->{'data'}{'events'}[0]{stopTime};
  2868. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($lastrecstoptime);
  2869. $lastrecstoptime = sprintf "%02d:%02d:%02d" , $hour , $min , $sec ;
  2870. }
  2871. # Setreading
  2872. readingsBeginUpdate($hash);
  2873. readingsBulkUpdate($hash,"CamEventNum",$eventnum);
  2874. readingsBulkUpdate($hash,"CamLastRec",$lastrecord);
  2875. if ($lastrecstarttime) {readingsBulkUpdate($hash,"CamLastRecTime",$lastrecstarttime." - ". $lastrecstoptime);}
  2876. readingsBulkUpdate($hash,"Errorcode","none");
  2877. readingsBulkUpdate($hash,"Error","none");
  2878. readingsEndUpdate($hash, 1);
  2879. # Logausgabe
  2880. $logstr = "Query event list of $camname successfully done";
  2881. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3
  2882. if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") {
  2883. $verbose = 4;
  2884. }
  2885. else
  2886. {
  2887. $verbose = 3;
  2888. }
  2889. Log3($name, $verbose, "$name - $logstr");
  2890. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2891. }
  2892. elsif ($OpMode eq "getmotionenum")
  2893. {
  2894. $motdetsc = $data->{'data'}{'MDParam'}{'source'};
  2895. $sensitivity_camCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'camCap'};
  2896. $sensitivity_value = $data->{'data'}{'MDParam'}{'sensitivity'}{'value'};
  2897. $sensitivity_ssCap = $data->{'data'}{'MDParam'}{'sensitivity'}{'ssCap'};
  2898. $threshold_camCap = $data->{'data'}{'MDParam'}{'threshold'}{'camCap'};
  2899. $threshold_value = $data->{'data'}{'MDParam'}{'threshold'}{'value'};
  2900. $threshold_ssCap = $data->{'data'}{'MDParam'}{'threshold'}{'ssCap'};
  2901. $percentage_camCap = $data->{'data'}{'MDParam'}{'percentage'}{'camCap'};
  2902. $percentage_value = $data->{'data'}{'MDParam'}{'percentage'}{'value'};
  2903. $percentage_ssCap = $data->{'data'}{'MDParam'}{'percentage'}{'ssCap'};
  2904. $objectSize_camCap = $data->{'data'}{'MDParam'}{'objectSize'}{'camCap'};
  2905. $objectSize_value = $data->{'data'}{'MDParam'}{'objectSize'}{'value'};
  2906. $objectSize_ssCap = $data->{'data'}{'MDParam'}{'objectSize'}{'ssCap'};
  2907. if ($motdetsc == -1) {
  2908. $motdetsc = "disabled";
  2909. }
  2910. elsif ($motdetsc == 0) {
  2911. $motdetsc = "Camera";
  2912. if ($sensitivity_camCap) {
  2913. $motdetsc .= ", sensitivity: $sensitivity_value";
  2914. }
  2915. if ($threshold_camCap) {
  2916. $motdetsc .= ", threshold: $threshold_value";
  2917. }
  2918. if ($percentage_camCap) {
  2919. $motdetsc .= ", percentage: $percentage_value";
  2920. }
  2921. if ($objectSize_camCap) {
  2922. $motdetsc .= ", objectSize: $objectSize_value";
  2923. }
  2924. }
  2925. elsif ($motdetsc == 1) {
  2926. $motdetsc = "SVS";
  2927. if ($sensitivity_ssCap) {
  2928. $motdetsc .= ", sensitivity: $sensitivity_value";
  2929. }
  2930. if ($threshold_ssCap) {
  2931. $motdetsc .= ", threshold: $threshold_value";
  2932. }
  2933. if ($percentage_ssCap) {
  2934. $motdetsc .= ", percentage: $percentage_value";
  2935. }
  2936. if ($objectSize_ssCap) {
  2937. $motdetsc .= ", objectSize: $objectSize_value";
  2938. }
  2939. }
  2940. # Setreading
  2941. readingsBeginUpdate($hash);
  2942. readingsBulkUpdate($hash,"CamMotDetSc",$motdetsc);
  2943. readingsBulkUpdate($hash,"Errorcode","none");
  2944. readingsBulkUpdate($hash,"Error","none");
  2945. readingsEndUpdate($hash, 1);
  2946. # Logausgabe
  2947. $logstr = "Enumerate motion detection parameters of $camname successfully done";
  2948. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2
  2949. if (defined($attr{$name}{pollnologging}) and $attr{$name}{pollnologging} eq "1") {
  2950. $verbose = 4;
  2951. }
  2952. else
  2953. {
  2954. $verbose = 3;
  2955. }
  2956. Log3($name, $verbose, "$name - $logstr");
  2957. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  2958. }
  2959. elsif ($OpMode eq "Getcapabilities")
  2960. {
  2961. # Parse Infos
  2962. my $ptzfocus = $data->{'data'}{'ptzFocus'};
  2963. if ($ptzfocus eq "0") {
  2964. $ptzfocus = "false";
  2965. }
  2966. elsif ($ptzfocus eq "1") {
  2967. $ptzfocus = "support step operation";
  2968. }
  2969. elsif ($ptzfocus eq "2") {
  2970. $ptzfocus = "support continuous operation";
  2971. }
  2972. my $ptztilt = $data->{'data'}{'ptzTilt'};
  2973. if ($ptztilt eq "0") {
  2974. $ptztilt = "false";
  2975. }
  2976. elsif ($ptztilt eq "1") {
  2977. $ptztilt = "support step operation";
  2978. }
  2979. elsif ($ptztilt eq "2") {
  2980. $ptztilt = "support continuous operation";
  2981. }
  2982. my $ptzzoom = $data->{'data'}{'ptzZoom'};
  2983. if ($ptzzoom eq "0") {
  2984. $ptzzoom = "false";
  2985. }
  2986. elsif ($ptzzoom eq "1") {
  2987. $ptzzoom = "support step operation";
  2988. }
  2989. elsif ($ptzzoom eq "2") {
  2990. $ptzzoom = "support continuous operation";
  2991. }
  2992. my $ptzpan = $data->{'data'}{'ptzPan'};
  2993. if ($ptzpan eq "0") {
  2994. $ptzpan = "false";
  2995. }
  2996. elsif ($ptzpan eq "1") {
  2997. $ptzpan = "support step operation";
  2998. }
  2999. elsif ($ptzpan eq "2") {
  3000. $ptzpan = "support continuous operation";
  3001. }
  3002. my $ptziris = $data->{'data'}{'ptzIris'};
  3003. if ($ptziris eq "0") {
  3004. $ptziris = "false";
  3005. }
  3006. elsif ($ptziris eq "1") {
  3007. $ptziris = "support step operation";
  3008. }
  3009. elsif ($ptziris eq "2") {
  3010. $ptziris = "support continuous operation";
  3011. }
  3012. # Setreading
  3013. readingsBeginUpdate($hash);
  3014. readingsBulkUpdate($hash,"CapPTZAutoFocus",$data->{'data'}{'ptzAutoFocus'});
  3015. readingsBulkUpdate($hash,"CapAudioOut",$data->{'data'}{'audioOut'});
  3016. readingsBulkUpdate($hash,"CapChangeSpeed",$data->{'data'}{'ptzSpeed'});
  3017. readingsBulkUpdate($hash,"CapPTZHome",$data->{'data'}{'ptzHome'});
  3018. readingsBulkUpdate($hash,"CapPTZAbs",$data->{'data'}{'ptzAbs'});
  3019. readingsBulkUpdate($hash,"CapPTZDirections",$data->{'data'}{'ptzDirection'});
  3020. readingsBulkUpdate($hash,"CapPTZFocus",$ptzfocus);
  3021. readingsBulkUpdate($hash,"CapPTZIris",$ptziris);
  3022. readingsBulkUpdate($hash,"CapPTZPan",$ptzpan);
  3023. readingsBulkUpdate($hash,"CapPTZTilt",$ptztilt);
  3024. readingsBulkUpdate($hash,"CapPTZZoom",$ptzzoom);
  3025. readingsBulkUpdate($hash,"Errorcode","none");
  3026. readingsBulkUpdate($hash,"Error","none");
  3027. readingsEndUpdate($hash, 1);
  3028. # Logausgabe
  3029. $logstr = "Capabilities of Camera $camname retrieved";
  3030. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2
  3031. if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") {
  3032. $verbose = 4;
  3033. }
  3034. else
  3035. {
  3036. $verbose = 3;
  3037. }
  3038. Log3($name, $verbose, "$name - $logstr");
  3039. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  3040. }
  3041. elsif ($OpMode eq "Getptzlistpreset")
  3042. {
  3043. # Parse PTZ-ListPresets
  3044. my $presetcnt = $data->{'data'}->{'total'};
  3045. my $cnt = 0;
  3046. # alle Presets der Kamera mit Id's in Assoziatives Array einlesen
  3047. # "my" nicht am Anfang deklarieren, sonst wird Hash %allpresets wieder geleert !
  3048. my %allpresets;
  3049. while ($cnt < $presetcnt)
  3050. {
  3051. # my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'id'};
  3052. my $presid = $data->{'data'}->{'presets'}->[$cnt]->{'position'};
  3053. my $presname = $data->{'data'}->{'presets'}->[$cnt]->{'name'};
  3054. $allpresets{$presname} = "$presid";
  3055. $cnt += 1;
  3056. }
  3057. # Presethash in $hash einfügen
  3058. $hash->{HELPER}{ALLPRESETS} = \%allpresets;
  3059. my @preskeys = sort(keys(%allpresets));
  3060. my $presetlist = join(",",@preskeys);
  3061. # Setreading
  3062. readingsBeginUpdate($hash);
  3063. readingsBulkUpdate($hash,"Presets",$presetlist);
  3064. readingsBulkUpdate($hash,"Errorcode","none");
  3065. readingsBulkUpdate($hash,"Error","none");
  3066. readingsEndUpdate($hash, 1);
  3067. # Logausgabe
  3068. $logstr = "PTZ Presets of $camname retrieved";
  3069. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2
  3070. if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") {
  3071. $verbose = 4;
  3072. }
  3073. else
  3074. {
  3075. $verbose = 3;
  3076. }
  3077. Log3($name, $verbose, "$name - $logstr");
  3078. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  3079. }
  3080. elsif ($OpMode eq "Getptzlistpatrol")
  3081. {
  3082. # Parse PTZ-ListPatrols
  3083. $patrolcnt = $data->{'data'}->{'total'};
  3084. my $cnt = 0;
  3085. # alle Patrols der Kamera mit Id's in Assoziatives Array einlesen
  3086. # "my" nicht am Anfang deklarieren, sonst wird Hash %allpatrols wieder geleert !
  3087. my %allpatrols = ();
  3088. while ($cnt < $patrolcnt)
  3089. {
  3090. $patrolid = $data->{'data'}->{'patrols'}->[$cnt]->{'id'};
  3091. $patrolname = $data->{'data'}->{'patrols'}->[$cnt]->{'name'};
  3092. $allpatrols{$patrolname} = $patrolid;
  3093. $cnt += 1;
  3094. }
  3095. # Presethash in $hash einfügen
  3096. $hash->{HELPER}{ALLPATROLS} = \%allpatrols;
  3097. @patrolkeys = sort(keys(%allpatrols));
  3098. $patrollist = join(",",@patrolkeys);
  3099. # print "ID von Tour1 ist : ". %allpatrols->{Tour1};
  3100. # print "aus Hash: ".$hash->{HELPER}{ALLPRESETS}{Tour1};
  3101. # Setreading
  3102. readingsBeginUpdate($hash);
  3103. readingsBulkUpdate($hash,"Patrols",$patrollist);
  3104. readingsBulkUpdate($hash,"Errorcode","none");
  3105. readingsBulkUpdate($hash,"Error","none");
  3106. readingsEndUpdate($hash, 1);
  3107. # Logausgabe
  3108. $logstr = "PTZ Patrols of $camname retrieved";
  3109. # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 2
  3110. if (defined(AttrVal($name, "pollnologging", undef)) and AttrVal($name, "pollnologging", undef) eq "1") {
  3111. $verbose = 4;
  3112. }
  3113. else
  3114. {
  3115. $verbose = 3;
  3116. }
  3117. Log3($name, $verbose, "$name - $logstr");
  3118. Log3($name, 4, "$name - --- End Function $OpMode nonblocking ---");
  3119. }
  3120. }
  3121. else
  3122. {
  3123. # die API-Operation war fehlerhaft
  3124. # Errorcode aus JSON ermitteln
  3125. $errorcode = $data->{'error'}->{'code'};
  3126. # Fehlertext zum Errorcode ermitteln
  3127. $error = &experror($hash,$errorcode);
  3128. # Setreading
  3129. readingsBeginUpdate($hash);
  3130. readingsBulkUpdate($hash,"Errorcode",$errorcode);
  3131. readingsBulkUpdate($hash,"Error",$error);
  3132. readingsEndUpdate($hash, 1);
  3133. # Logausgabe
  3134. Log3($name, 1, "$name - ERROR - Operation $OpMode of Camera $camname was not successful. Errorcode: $errorcode - $error");
  3135. Log3($name, 4, "$name - --- End Function $OpMode nonblocking with error ---");
  3136. }
  3137. }
  3138. return (logout_nonbl($hash));
  3139. }
  3140. ###################################################################################
  3141. #### Funktion logout
  3142. sub logout_nonbl ($) {
  3143. my ($hash) = @_;
  3144. my $name = $hash->{NAME};
  3145. my $serveraddr = $hash->{SERVERADDR};
  3146. my $serverport = $hash->{SERVERPORT};
  3147. my $apiauth = $hash->{HELPER}{APIAUTH};
  3148. my $apiauthpath = $hash->{HELPER}{APIAUTHPATH};
  3149. my $apiauthmaxver = $hash->{HELPER}{APIAUTHMAXVER};
  3150. my $sid = $hash->{HELPER}{SID};
  3151. my $url;
  3152. my $param;
  3153. my $httptimeout;
  3154. # logout wird ausgeführt, Rückkehr wird mit "logoutret_nonbl" verarbeitet
  3155. Log3($name, 4, "$name - --- Begin Function logout nonblocking ---");
  3156. $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4";
  3157. Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s");
  3158. if (defined($attr{$name}{session}) and $attr{$name}{session} eq "SurveillanceStation") {
  3159. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&session=SurveillanceStation&_sid=$sid";
  3160. }
  3161. else
  3162. {
  3163. $url = "http://$serveraddr:$serverport/webapi/$apiauthpath?api=$apiauth&version=$apiauthmaxver&method=Logout&_sid=$sid";
  3164. }
  3165. $param = {
  3166. url => $url,
  3167. timeout => $httptimeout,
  3168. hash => $hash,
  3169. method => "GET",
  3170. header => "Accept: application/json",
  3171. callback => \&logoutret_nonbl
  3172. };
  3173. HttpUtils_NonblockingGet ($param);
  3174. }
  3175. ###################################################################################
  3176. #### Rückkehr aus Funktion logout_nonbl,
  3177. #### check Funktion logout
  3178. sub logoutret_nonbl ($) {
  3179. my ($param, $err, $myjson) = @_;
  3180. my $hash = $param->{hash};
  3181. my $name = $hash->{NAME};
  3182. my $sid = $hash->{HELPER}{SID};
  3183. my ($success, $username) = getcredentials($hash,0);
  3184. my $OpMode = $hash->{OPMODE};
  3185. my $data;
  3186. my $error;
  3187. my $errorcode;
  3188. if($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
  3189. {
  3190. Log3($name, 1, "$name - error while requesting ".$param->{url}." - $err");
  3191. Log3($name, 4, "$name - --- End Function logout nonblocking with error ---");
  3192. readingsSingleUpdate($hash, "Error", $err, 1); # Readings erzeugen
  3193. }
  3194. elsif($myjson ne "") # wenn die Abfrage erfolgreich war ($data enthält die Ergebnisdaten des HTTP Aufrufes)
  3195. {
  3196. Log3($name, 4, "$name - URL-Call: ".$param->{url});
  3197. # Evaluiere ob Daten im JSON-Format empfangen wurden
  3198. ($hash, $success) = &evaljson($hash,$myjson,$param->{url});
  3199. unless ($success) {
  3200. Log3($name, 4, "$name - Data returned: ".$myjson);
  3201. $hash->{HELPER}{ACTIVE} = "off";
  3202. if ($attr{$name}{debugactivetoken}) {
  3203. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3204. }
  3205. return;
  3206. }
  3207. $data = decode_json($myjson);
  3208. # Logausgabe decodierte JSON Daten
  3209. Log3($name, 4, "$name - JSON returned: ". Dumper $data);
  3210. $success = $data->{'success'};
  3211. if ($success)
  3212. {
  3213. # die Logout-URL konnte erfolgreich aufgerufen werden
  3214. # Session-ID aus Helper-hash löschen
  3215. delete $hash->{HELPER}{SID};
  3216. # Logausgabe
  3217. Log3($name, 4, "$name - Session of User $username has ended - SID: $sid has been deleted");
  3218. Log3($name, 4, "$name - --- End Function logout nonblocking ---");
  3219. }
  3220. else
  3221. {
  3222. # Errorcode aus JSON ermitteln
  3223. $errorcode = $data->{'error'}->{'code'};
  3224. # Fehlertext zum Errorcode ermitteln
  3225. $error = &experrorauth($hash,$errorcode);
  3226. # Logausgabe
  3227. Log3($name, 1, "$name - ERROR - Logout of User $username was not successful. Errorcode: $errorcode - $error");
  3228. Log3($name, 4, "$name - --- End Function logout nonblocking with error ---");
  3229. }
  3230. }
  3231. # ausgeführte Funktion ist erledigt (auch wenn logout nicht erfolgreich), Freigabe Funktionstoken
  3232. $hash->{HELPER}{ACTIVE} = "off";
  3233. if ($attr{$name}{debugactivetoken}) {
  3234. Log3($name, 3, "$name - Active-Token deleted by OPMODE: $hash->{OPMODE}");
  3235. }
  3236. return;
  3237. }
  3238. #############################################################################################################################
  3239. ######### Ende Kameraoperationen mit NonblockingGet (nicht blockierender HTTP-Call) #############
  3240. #############################################################################################################################
  3241. #############################################################################################################################
  3242. ######### Hilfsroutinen #############
  3243. #############################################################################################################################
  3244. ###############################################################################
  3245. ### Test ob JSON-String empfangen wurde
  3246. sub evaljson {
  3247. my ($hash,$myjson,$url)= @_;
  3248. my $success = 1;
  3249. my $e;
  3250. eval {decode_json($myjson)} or do
  3251. {
  3252. $success = 0;
  3253. $e = $@;
  3254. # Setreading
  3255. readingsBeginUpdate($hash);
  3256. readingsBulkUpdate($hash,"Errorcode","none");
  3257. readingsBulkUpdate($hash,"Error","malformed JSON string received");
  3258. readingsEndUpdate($hash, 1);
  3259. };
  3260. return($hash,$success);
  3261. }
  3262. ##############################################################################
  3263. ### Auflösung Errorcodes bei Login / Logout
  3264. sub experrorauth {
  3265. # Übernahmewerte sind $hash, $errorcode
  3266. my ($hash,@errorcode) = @_;
  3267. my $device = $hash->{NAME};
  3268. my $errorcode = shift @errorcode;
  3269. my $error;
  3270. unless (exists($SSCam_errauthlist{"$errorcode"})) {$error = "Message of errorcode \"$errorcode\" not found. Please turn to Synology Web API-Guide."; return ($error);}
  3271. # Fehlertext aus Hash-Tabelle %errorauthlist ermitteln
  3272. $error = $SSCam_errauthlist{"$errorcode"};
  3273. return ($error);
  3274. }
  3275. ##############################################################################
  3276. ### Auflösung Errorcodes SVS API
  3277. sub experror {
  3278. # Übernahmewerte sind $hash, $errorcode
  3279. my ($hash,@errorcode) = @_;
  3280. my $device = $hash->{NAME};
  3281. my $errorcode = shift @errorcode;
  3282. my $error;
  3283. unless (exists($SSCam_errlist{"$errorcode"})) {$error = "Message of errorcode $errorcode not found. Please turn to Synology Web API-Guide."; return ($error);}
  3284. # Fehlertext aus Hash-Tabelle %errorlist ermitteln
  3285. $error = $SSCam_errlist{"$errorcode"};
  3286. return ($error);
  3287. }
  3288. 1;
  3289. =pod
  3290. =item summary operate surveillance cameras which are defined in Synology Surveillance Station
  3291. =item summary_DE steuert Kameras welche in der Synology Surveillance Station definiert sind
  3292. =begin html
  3293. <a name="SSCam"></a>
  3294. <h3>SSCam</h3>
  3295. <ul>
  3296. Using this Module you are able to operate cameras which are defined in Synology Surveillance Station (SVS). <br>
  3297. At present the following functions are available: <br><br>
  3298. <ul>
  3299. <ul>
  3300. <li>Start a Recording</li>
  3301. <li>Stop a Recording (using command or automatically after the &lt;RecordTime&gt; period</li>
  3302. <li>Trigger a Snapshot </li>
  3303. <li>Deaktivate a Camera in Synology Surveillance Station</li>
  3304. <li>Activate a Camera in Synology Surveillance Station</li>
  3305. <li>Control of the exposure modes day, night and automatic </li>
  3306. <li>switchover the motion detection by camera, by SVS or to deactivate </li>
  3307. <li>control of motion detection parameters sensitivity, threshold, object size and percentage for release </li>
  3308. <li>Retrieval of Camera Properties (also by Polling) as well as informations about the installed SVS-package</li>
  3309. <li>Move to a predefined Preset-position (at PTZ-cameras) </li>
  3310. <li>Start a predefined Patrol (at PTZ-cameras) </li>
  3311. <li>Positioning of PTZ-cameras to absolute X/Y-coordinates </li>
  3312. <li>continuous moving of PTZ-camera lense </li>
  3313. <li>trigger of external events 1-10 (action rules in SVS) </li>
  3314. <li>start and stop of camera livestreams </li>
  3315. <li>fetch of livestream-Url's with key (login not needed in that case) </li>
  3316. <li>playback of last recording </li><br>
  3317. </ul>
  3318. </ul>
  3319. 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>
  3320. For example the recordings are stored for a defined time in Surveillance Station and will be deleted after that period.<br><br>
  3321. If you like to discuss or help to improve this module please use FHEM-Forum with link: <br>
  3322. <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>
  3323. <b> Prerequisites </b> <br><br>
  3324. This module uses the CPAN-module JSON. Please consider to install this package (Debian: libjson-perl).<br>
  3325. SSCam is completely using the nonblocking functions of HttpUtils respectively HttpUtils_NonblockingGet. <br>
  3326. 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>
  3327. Further informations could be find among <a href="#SSCam_Credentials">Credentials</a>. <br><br>
  3328. Overview which Perl-modules SSCam is using: <br><br>
  3329. JSON <br>
  3330. Data::Dumper <br>
  3331. MIME::Base64 <br>
  3332. Time::HiRes <br>
  3333. HttpUtils (FHEM-module) <br><br>
  3334. <a name="SSCamdefine"></a>
  3335. <b>Define</b>
  3336. <ul>
  3337. <br>
  3338. <code>define &lt;name&gt; SSCAM &lt;Cameraname in SVS&gt; &lt;ServerAddr&gt; [Port] </code><br>
  3339. <br>
  3340. Defines a new camera device for SSCam. At first the devices have to be set up and operable in Synology Surveillance Station 7.0 and above. <br><br>
  3341. The Modul SSCam ist based on functions of Synology Surveillance Station API. <br>
  3342. Please refer the <a href="http://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf">Web API Guide</a>. <br><br>
  3343. Currently only HTTP-protocol is supported to call Synology DS. <br><br>
  3344. The parameters are in detail:
  3345. <br>
  3346. <br>
  3347. <table>
  3348. <colgroup> <col width=15%> <col width=85%> </colgroup>
  3349. <tr><td>name: </td><td>the name of the new device to use in FHEM</td></tr>
  3350. <tr><td>Cameraname: </td><td>Cameraname as defined in Synology Surveillance Station, Spaces are not allowed in Cameraname !</td></tr>
  3351. <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>
  3352. <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>
  3353. </table>
  3354. <br><br>
  3355. <b>Example:</b>
  3356. <pre>
  3357. define CamCP SSCAM Carport 192.168.2.20 [5000]
  3358. </pre>
  3359. When a new Camera is defined, as a start the recordingtime of 15 seconds will be assigned to the device.<br>
  3360. Using the <a href="#SSCamattr">attribute</a> "rectime" you can adapt the recordingtime for every camera individually.<br>
  3361. 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>
  3362. Due to a Log-Entry with a hint to that circumstance will be written. <br><br>
  3363. If the <a href="#SSCamattr">attribute</a> "rectime" would be deleted again, the default-value for recording-time (15s) become active.<br><br>
  3364. 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>
  3365. and the attribute "rectime" (if it is set) uniquely. <br><br>
  3366. In that case the command <b>"set &lt;name&gt; on 0"</b> leads also to an endless recording as well.<br><br>
  3367. If you have specified a pre-recording time in SVS it will be considered too. <br><br><br>
  3368. <a name="SSCam_Credentials"></a>
  3369. <b>Credentials </b><br><br>
  3370. After a camera-device is defined, firstly it is needed to save the credentials. This will be done with command:
  3371. <pre>
  3372. set &lt;name&gt; credentials &lt;username&gt; &lt;password&gt;
  3373. </pre>
  3374. The operator can, dependend on what functions are planned to execute, create an user in DSM respectively in Synology Surveillance Station as well. <br>
  3375. 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>
  3376. The required minimum rights to execute functions are listed in a table further down. <br>
  3377. 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>
  3378. whereat the access to particular cameras can be restricted by the privilege profile (please see help function in SVS for details). <br>
  3379. As best practice it is proposed to create an user in DSM as well as in SVS too: <br><br>
  3380. <ul>
  3381. <li>DSM-User as member of admin group: unrestricted test of all module functions -&gt; session: DSM </li>
  3382. <li>SVS-User as Manager or observer: adjusted privilege profile -&gt; session: SurveillanceStation </li>
  3383. </ul>
  3384. <br>
  3385. Using the <a href="#SSCamattr">Attribute</a> "session" can be selected, if the session should be established to DSM or the SVS instead. <br>
  3386. 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>
  3387. 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>
  3388. 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>
  3389. The following list shows the minimum rights what the particular module function needs. <br><br>
  3390. <ul>
  3391. <table>
  3392. <colgroup> <col width=20%> <col width=80%> </colgroup>
  3393. <tr><td><li>set ... on </td><td> session: ServeillanceStation - observer with enhanced privilege "manual recording" </li></td></tr>
  3394. <tr><td><li>set ... off </td><td> session: ServeillanceStation - observer with enhanced privilege "manual recording" </li></td></tr>
  3395. <tr><td><li>set ... snap </td><td> session: ServeillanceStation - observer </li></td></tr>
  3396. <tr><td><li>set ... disable </td><td> session: ServeillanceStation - manager </li></td></tr>
  3397. <tr><td><li>set ... enable </td><td> session: ServeillanceStation - manager </li></td></tr>
  3398. <tr><td><li>set ... expmode </td><td> session: ServeillanceStation - manager </li></td></tr>
  3399. <tr><td><li>set ... motdetsc </td><td> session: ServeillanceStation - manager </li></td></tr>
  3400. <tr><td><li>set ... goPreset </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  3401. <tr><td><li>set ... runPatrol </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  3402. <tr><td><li>set ... goAbsPTZ </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  3403. <tr><td><li>set ... move </td><td> session: ServeillanceStation - observer with privilege objective control of camera </li></td></tr>
  3404. <tr><td><li>set ... runView </td><td> session: ServeillanceStation - observer with privilege liveview of camera </li></td></tr>
  3405. <tr><td><li>set ... extevent </td><td> session: DSM - user as member of admin-group </li></td></tr>
  3406. <tr><td><li>set ... stopView </td><td> - </li></td></tr>
  3407. <tr><td><li>set ... credentials </td><td> - </li></td></tr>
  3408. <tr><td><li>get ... caminfoall </td><td> session: ServeillanceStation - observer </li></td></tr>
  3409. <tr><td><li>get ... eventlist </td><td> session: ServeillanceStation - observer </li></td></tr>
  3410. <tr><td><li>get ... svsinfo </td><td> session: ServeillanceStation - observer </li></td></tr>
  3411. <tr><td><li>get ... snapfileinfo </td><td> session: ServeillanceStation - observer </li></td></tr>
  3412. <tr><td><li>get ... stmUrlPath </td><td> session: ServeillanceStation - observer </li></td></tr>
  3413. </table>
  3414. </ul>
  3415. <br><br>
  3416. <a name="SSCam_HTTPTimeout"></a>
  3417. <b>HTTP-Timeout Settings</b><br><br>
  3418. All functions of the SSCam-Module are using HTTP-Calls to the SVS Web API. <br>
  3419. The Default-Value of the 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>
  3420. </ul>
  3421. <br><br><br>
  3422. <a name="SSCamset"></a>
  3423. <b>Set </b>
  3424. <ul>
  3425. Currently there are the following options for "Set &lt;name&gt; ..." : <br><br>
  3426. <table>
  3427. <colgroup> <col width=35%> <col width=65%> </colgroup>
  3428. <tr><td>"on [rectime]": </td><td>starts a recording. The recording will be stopped automatically after a period of [rectime] </td></tr>
  3429. <tr><td> </td><td>if [rectime] = 0 an endless recording will be started </td></tr>
  3430. <tr><td>"off" : </td><td>stopps a running recording manually or using other events (e.g. with at, notify)</td></tr>
  3431. <tr><td>"snap": </td><td>triggers a snapshot of the relevant camera and store it into Synology Surveillance Station</td></tr>
  3432. <tr><td>"disable": </td><td>deactivates a camera in Synology Surveillance Station</td></tr>
  3433. <tr><td>"enable": </td><td>activates a camera in Synology Surveillance Station</td></tr>
  3434. <tr><td>"credentials &lt;username&gt; &lt;password&gt;": </td><td>save a set of credentils </td></tr>
  3435. <tr><td>"expmode [ day | night | auto ]": </td><td>set the exposure mode to day, night or auto </td></tr>
  3436. <tr><td>"extevent [ 1-10 ]": </td><td>triggers the external event 1-10 (see actionrule editor in SVS) </td></tr>
  3437. <tr><td>"motdetsc [ camera | SVS | disable ]": </td><td>set motion detection to the desired mode </td></tr>
  3438. <tr><td>"goPreset &lt;Presetname&gt;": </td><td>moves a PTZ-camera to a predefinied Preset-position </td></tr>
  3439. <tr><td>"runPatrol &lt;Patrolname&gt;": </td><td>starts a predefinied patrol (PTZ-cameras) </td></tr>
  3440. <tr><td>"goAbsPTZ [ X Y | up | down | left | right ]": </td><td>moves a PTZ-camera to a absolute X/Y-coordinate or to direction up/down/left/right </td></tr>
  3441. <tr><td>"move [ up | down | left | right | dir_X ]": </td><td>starts a continuous move of PTZ-camera to direction up/down/left/right or dir_X </td></tr>
  3442. <tr><td>"runView [image | lastrec | lastrec_open | link | link_open &lt;room&gt; ]": </td><td>starts a livestream as embedded image or link </td></tr>
  3443. <tr><td>"stopView": </td><td>stops a camera livestream </td></tr>
  3444. </table>
  3445. <br><br>
  3446. <b>"set &lt;name&gt; [on] [off]"</b> <br><br>
  3447. 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.
  3448. 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]".
  3449. The recording will be stopped after processing time "rectime"automatically.<br>
  3450. 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
  3451. by command "set &lt;name&gt; off" explicitely.<br>
  3452. The recording behavior can be impacted with <a href="#SSCamattr">attribute</a> "recextend" furthermore as explained as follows.<br><br>
  3453. <b>Attribute "recextend = 0" or not set (default):</b><br><br>
  3454. <ul>
  3455. <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.
  3456. A hint will be logged in case of verboselevel = 3. </li>
  3457. </ul>
  3458. <br>
  3459. <b>Attribute "recextend = 1" is set:</b><br><br>
  3460. <ul>
  3461. <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
  3462. 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.
  3463. Therefore a running recording will be extended until no start command will be get. </li>
  3464. <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
  3465. don't set the <a href="#SSCamattr">attribute</a> "recextend" in case of endless-recordings. </li>
  3466. </ul>
  3467. <br>
  3468. Examples for simple <b>Start/Stop a Recording</b>: <br><br>
  3469. <table>
  3470. <colgroup> <col width=20%> <col width=80%> </colgroup>
  3471. <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>
  3472. <tr><td>set &lt;name&gt; off </td><td>stops the recording of camera &lt;name&gt;</td></tr>
  3473. </table>
  3474. <br>
  3475. <br>
  3476. <b> "set &lt;name&gt; snap" </b> <br><br>
  3477. A snapshot can be triggered with:
  3478. <pre>
  3479. set &lt;name&gt; snap
  3480. </pre>
  3481. Subsequent some Examples for <b>taking snapshots</b>: <br><br>
  3482. If a serial of snapshots should be released, it can be done using the following notify command.
  3483. For the example a serial of snapshots are to be triggerd if the recording of a camera starts. <br>
  3484. 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.
  3485. <pre>
  3486. define he1_snap_3 notify CamHE1:Record.*on define h3 at +*{3}00:00:02 set CamHE1 snap
  3487. </pre>
  3488. Release of 2 Snapshots of camera "CamHE1" at intervals of 6 seconds after the motion sensor "MelderHE1" has sent an event, <br>
  3489. can be done e.g. with following notify-command:
  3490. <pre>
  3491. define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap
  3492. </pre>
  3493. 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>
  3494. <b> "set &lt;name&gt; [enable] [disable]" </b> <br><br>
  3495. For <br>deactivating / activating</br> a list of cameras or all cameras using a Regex-expression, subsequent two examples using "at":
  3496. <pre>
  3497. define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
  3498. define a14 at 21:46 set Cam.* disable (enable)
  3499. </pre>
  3500. A bit more convenient is it to use a dummy-device for enable/disable all available cameras in Surveillance Station.<br>
  3501. At first the Dummy will be created.
  3502. <pre>
  3503. define allcams dummy
  3504. attr allcams eventMap on:enable off:disable
  3505. attr allcams room Cams
  3506. attr allcams webCmd enable:disable
  3507. </pre>
  3508. 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".
  3509. <pre>
  3510. define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
  3511. attr all_cams_disable room Cams
  3512. define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
  3513. attr all_cams_enable room Cams
  3514. </pre>
  3515. <br><br>
  3516. <b> "set &lt;name&gt; expmode [day] [night] [auto]" </b> <br><br>
  3517. With this command you are able to control the exposure mode and can set it to day, night or automatic mode.
  3518. Thereby, for example, the behavior of camera LED's will be suitable controlled.
  3519. The successful switch will be reported by the reading CamExposureMode (command "get ... caminfoall"). <br><br>
  3520. <b> Hint: </b> <br>
  3521. The successfully execution of this function depends on if SVS supports that functionality of the connected camera.
  3522. 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.
  3523. <br><br><br>
  3524. <b> "set &lt;name&gt; motdetsc [camera] [SVS] [disable]" </b> <br><br>
  3525. The command "motdetsc" (stands for "motion detection source") switchover the motion detection to the desired mode.
  3526. If motion detection will be done by camera / SVS without any parameters, the original camera motion detection settings are kept.
  3527. The successful execution of that opreration one can retrace by the state in SVS -&gt; IP-camera -&gt; event detection -&gt; motion. <br><br>
  3528. For the motion detection further parameter can be specified. The available options for motion detection by SVS are "sensitivity" and "threshold". <br><br>
  3529. <ul>
  3530. <table>
  3531. <colgroup> <col width=50%> <col width=50%> </colgroup>
  3532. <tr><td>set <name> motdetsc SVS [sensitivity] [threshold] </td><td># command pattern </td></tr>
  3533. <tr><td>set <name> motdetsc SVS 91 30 </td><td># set the sensitivity to 91 and threshold to 30 </td></tr>
  3534. <tr><td>set <name> motdetsc SVS 0 40 </td><td># keep the old value of sensitivity, set threshold to 40 </td></tr>
  3535. <tr><td>set <name> motdetsc SVS 15 </td><td># set the sensitivity to 15, threshold keep unchanged </td></tr>
  3536. </table>
  3537. </ul>
  3538. <br><br>
  3539. If the motion detection is used by camera, there are the options "sensitivity", "object size", "percentage for release" available. <br><br>
  3540. <ul>
  3541. <table>
  3542. <colgroup> <col width=50%> <col width=50%> </colgroup>
  3543. <tr><td>set <name> motdetsc camera [sensitivity] [threshold] [percentage] </td><td># command pattern </td></tr>
  3544. <tr><td>set <name> motdetsc camera 89 0 20 </td><td># set the sensitivity to 89, percentage to 20 </td></tr>
  3545. <tr><td>set <name> motdetsc camera 0 40 10 </td><td># keep old value for sensitivity, set threshold to 40, percentage to 10 </td></tr>
  3546. <tr><td>set <name> motdetsc camera 30 </td><td># set the sensitivity to 30, other values keep unchanged </td></tr>
  3547. </table>
  3548. </ul>
  3549. <br><br>
  3550. 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).
  3551. The numerical values are between 1 - 99 (except special case "0"). <br><br>
  3552. 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
  3553. SVS -&gt; edit camera -&gt; motion detection. Further informations please read in SVS online help. <br><br>
  3554. With the command "get ... caminfoall" the <a href="#SSCamreadings">Reading</a> "CamMotDetSc" also will be updated which documents the current setup of motion detection.
  3555. 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>
  3556. Example:
  3557. <pre>
  3558. CamMotDetSc SVS, sensitivity: 76, threshold: 55
  3559. </pre>
  3560. <br><br>
  3561. <b> "set &lt;name&gt; goPreset &lt;Preset&gt;" </b> <br><br>
  3562. Using this command you can move PTZ-cameras to a predefined position. <br>
  3563. 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.
  3564. 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.
  3565. 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.
  3566. <br><br>
  3567. Here it is an example of a PTZ-control depended on IR-motiondetector event:
  3568. <pre>
  3569. 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
  3570. </pre>
  3571. Operating Mode: <br>
  3572. 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.
  3573. 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>
  3574. When the recording starts 3 snapshots with an interval of 5 seconds will be taken as well. <br>
  3575. After a time of 30 seconds in position "Wandschrank" the camera moves back to postion "Home". <br><br>
  3576. An extract of the log illustrates the process:
  3577. <pre>
  3578. 2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
  3579. 2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
  3580. 2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  3581. 2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
  3582. 2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  3583. 2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  3584. 2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
  3585. </pre>
  3586. <br><br>
  3587. <b> "set &lt;name&gt; runPatrol &lt;Patrolname&gt;" </b> <br><br>
  3588. This commans starts a predefined patrol (tour) of a PTZ-camera. <br>
  3589. 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.
  3590. The patrol tours will be read with command "get &lt;name&gt; caminfoall" which is be executed automatically when FHEM restarts.
  3591. 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
  3592. if the user change it in the IP-camera setup itself.
  3593. Further informations for creating patrols you can get in the online-help of Surveillance Station.
  3594. <br><br>
  3595. <b> "set &lt;name&gt; goAbsPTZ [ X Y | up | down | left | right ]" </b> <br><br>
  3596. 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.
  3597. 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" .
  3598. <br><br>
  3599. Example for a control to absolute X/Y-coordinates: <br>
  3600. <pre>
  3601. set &lt;name&gt; goAbsPTZ 120 450
  3602. </pre>
  3603. In this example the camera lense moves to position X=120 und Y=450. <br>
  3604. The valuation is:
  3605. <pre>
  3606. X = 0 - 640 (0 - 319 moves lense left, 321 - 640 moves lense right, 320 don't move lense)
  3607. Y = 0 - 480 (0 - 239 moves lense down, 241 - 480 moves lense up, 240 don't move lense)
  3608. </pre>
  3609. The lense can be moved in smallest steps to very large steps into the desired direction.
  3610. If necessary the procedure has to be repeated to bring the lense into the desired position. <br><br>
  3611. If the motion should be done with the largest possible increment the following command can be used for simplification:
  3612. <pre>
  3613. set &lt;name&gt; goAbsPTZ up [down ] [left] [right]
  3614. </pre>
  3615. In this case the lense will be moved with largest possible increment into the given absolute position.
  3616. Also in this case the procedure has to be repeated to bring the lense into the desired position if necessary.
  3617. <br><br><br>
  3618. <b> set &lt;name&gt; move [ up | down | left | right | dir_X ] [seconds] </b> <br><br>
  3619. 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
  3620. "dir_X". The grain size of graduation depends on properties of the camera and can be identified by the Reading "CapPTZDirections". <br><br>
  3621. The radian measure of 360 degrees will be devided by the value of "CapPTZDirections" and describes the move drections starting with "0=right" counterclockwise.
  3622. 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
  3623. the appropriate directions between. The possible moving directions of cameras with "CapPTZDirections = 32" are correspondingly divided into smaller sections. <br><br>
  3624. 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.
  3625. 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>
  3626. Examples: <br>
  3627. <pre>
  3628. set &lt;name&gt; move up 0.5 : moves PTZ 0,5 Sek. (plus processing time) to the top
  3629. set &lt;name&gt; move dir_1 1.5 : moves PTZ 1,5 Sek. (plus processing time) to top-right
  3630. set &lt;name&gt; move dir_20 0.7 : moves PTZ 1,5 Sek. (plus processing time) to left-bottom ("CapPTZDirections = 32)"
  3631. </pre>
  3632. <br>
  3633. <b> set &lt;name&gt; runView [ image | lastrec | lastrec_open | link | link_open &lt;room&gt; ] </b> <br><br>
  3634. With "image, link, link_open" a livestream (mjpeg-stream) of a camera will be started, either as embedded image or as a generated link.
  3635. Access to the last recording of a camera can be done using "lastrec" respectively "lastrec_open".
  3636. The behavior of livestream in FHEMWEB can be affected by statements in <a href="#SSCamattr">attribute</a> "htmlattr". <br><br>
  3637. <b>Examples:</b><br>
  3638. <pre>
  3639. attr &lt;name&gt; htmlattr target=_blank width="500" height="375"
  3640. attr &lt;name&gt; htmlattr target=_blank width=500,height=375
  3641. attr &lt;name&gt; htmlattr width=700,height=525,top=200,left=300
  3642. </pre>
  3643. With these attribute values a streaming link will be opened (by click on) in a new browser tab or windows. If the stream will be started as an image, the size changes appropriately the
  3644. values of width and hight. <br>
  3645. The command <b>"set &lt;name&gt; runView link_open"</b> starts the stream immediately in a new browser window (longpoll=1 must be set for WEB).
  3646. A browser window will be initiated to open for every FHEM session which is active. If you want to change this,
  3647. you can use command <b>"set &lt;name&gt; runView link_open &lt;room&gt;"</b> what initiates to open a browser window in that FHEM session that has just opend the room &lt;room&gt;.
  3648. The settings of <a href="#SSCamattr">attribute</a> "livestreamprefix" overwrites the data for protocol, servername and port in <a href="#SSCamreadings">reading</a> "LiveStreamUrl".
  3649. By "livestreamprefix" the LivestreamURL (is shown if <a href="#SSCamattr">attribute</a> "showStmInfoFull" is set) can be modified and used for distribution and external
  3650. access to SVS livestream. <br><br>
  3651. <b>Example:</b><br>
  3652. <pre>
  3653. attr &lt;name&gt; livestreamprefix https://&lt;Servername&gt;:&lt;Port&gt;
  3654. </pre>
  3655. The livestream will be stopped again using command <b>"set &lt;name&gt; stopView"</b> .
  3656. <br><br>
  3657. <b> set &lt;name&gt; extevent [ 1-10 ] </b> <br><br>
  3658. This command triggers an external event (1-10) in SVS.
  3659. 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.
  3660. 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.
  3661. Further informations can be found in the online help of the actionrule editor.
  3662. The used user needs to be a member of the admin-group and DSM-session is needed too.
  3663. <br><br><br>
  3664. </ul>
  3665. <br>
  3666. <a name="SSCamget"></a>
  3667. <b>Get</b>
  3668. <ul>
  3669. With SSCam the properties of SVS and defined Cameras could be retrieved. Actually it could be done by using the following commands:
  3670. <pre>
  3671. get &lt;name&gt; caminfoall
  3672. get &lt;name&gt; eventlist
  3673. get &lt;name&gt; stmUrlPath
  3674. get &lt;name&gt; svsinfo
  3675. get &lt;name&gt; snapfileinfo
  3676. </pre>
  3677. With command <b>"get &lt;name&gt; caminfoall"</b> dependend of the type of Camera (e.g. Fix- or PTZ-Camera) the available properties will be retrieved and provided as Readings.<br>
  3678. For example the Reading "Availability" will be set to "disconnected" if the Camera would be disconnected from Synology Surveillance Station and can be used for further
  3679. processing like creating events. <br>
  3680. By command <b>"get &lt;name&gt; eventlist"</b> the <a href="#SSCamreadings">Reading</a> "CamEventNum" and "CamLastRecord" will be refreshed which containes the total number of in SVS
  3681. registered camera events and the path / name of the last recording.
  3682. This command will be implicit executed when "get ... caminfoall" is running. <br>
  3683. The <a href="#SSCamattr">attribute</a> "videofolderMap" replaces the content of reading "VideoFolder". You can use it for example if you have mounted the videofolder of SVS
  3684. under another name or path and want to access by your local pc.
  3685. Using <b>"get &lt;name&gt; snapfileinfo"</b> the filename of the last snapshot will be retrieved. This command will be executed with <b>"get &lt;name&gt; snap"</b> automatically. <br>
  3686. The command <b>"get &lt;name&gt; svsinfo"</b> is not really dependend on a camera, but rather a command to determine common informations about the installed SVS-version and other properties. <br>
  3687. The functions "caminfoall" and "svsinfo" will be executed automatically once-only after FHEM restarts to collect some relevant informations for camera control. <br>
  3688. Please consider to save the <a href="#SSCam_Credentials">credentials</a> what will be used for login to DSM or SVS !
  3689. <br><br>
  3690. <b> get &lt;name&gt; stmUrlPath </b> <br><br>
  3691. 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
  3692. to send it and run by your own application like a browser (see example).
  3693. 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
  3694. 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.
  3695. The strUrlPath function will be included automatically if polling is used.
  3696. <br><br>
  3697. Example to create an http-call to a livestream using the StmKey: <br>
  3698. <pre>
  3699. 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"
  3700. </pre>
  3701. cameraId (INTERNAL), StmKey has to be replaced by valid values. <br><br>
  3702. <b>Hint:</b> <br>
  3703. If you use the stream-call from external and replace hostname / port with valid values and open your router ip ports, please make shure that no
  3704. unauthorized person could get this sensible data ! <br><br>
  3705. <b>Polling of Camera-Properties:</b><br><br>
  3706. Retrieval of Camera-Properties can be done automatically if the attribute "pollcaminfoall" will be set to a value &gt; 10. <br>
  3707. As default that attribute "pollcaminfoall" isn't be set and the automatic polling isn't be active. <br>
  3708. 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>
  3709. respectively stopped when the value was set to &gt; 10 before. <br><br>
  3710. The attribute "pollcaminfoall" is monitored by a watchdog-timer. Changes of the attribute-value will be checked every 90 seconds and transact corresponding. <br>
  3711. 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>
  3712. 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>
  3713. will be actived due to analysis purposes. <br><br>
  3714. If FHEM will be restarted, the first data retrieval will be done within 60 seconds after start. <br><br>
  3715. The state of automatic polling will be displayed by reading "PollState": <br><br>
  3716. <ul>
  3717. <li><b> PollState = Active </b> - automatic polling will be executed with interval correspondig value of attribute "pollcaminfoall" </li>
  3718. <li><b> PollState = Inactive </b> - automatic polling won't be executed </li>
  3719. </ul>
  3720. <br>
  3721. The meaning of reading values is described under <a href="#SSCamreadings">Readings</a> . <br><br>
  3722. <b>Notes:</b> <br><br>
  3723. If polling is used, the interval should be adjusted only as short as needed due to the detected camera values are predominantly static. <br>
  3724. A feasible guide value for attribute "pollcaminfoall" could be between 600 - 1800 (s). <br>
  3725. Per polling call and camera approximately 10 - 20 Http-calls will are stepped against Surveillance Station. <br>
  3726. 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>
  3727. Considering a safety margin, in that example you shouldn't set the polling interval lower than 160 seconds. <br><br>
  3728. 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>
  3729. and thereby caused potential source of errors during request Synology Surveillance Station. <br>
  3730. A marginal difference between the polling intervals of the defined cameras, e.g. 1 second, can already be faced as sufficient value. <br><br>
  3731. </ul>
  3732. <a name="SSCaminternals"></a>
  3733. <b>Internals</b> <br>
  3734. <ul>
  3735. The meaning of used Internals is depicted in following list: <br><br>
  3736. <ul>
  3737. <li><b>CAMID</b> - the ID of camera defined in SVS, the value will be retrieved automatically on the basis of SVS-cameraname </li>
  3738. <li><b>CAMNAME</b> - the name of the camera in SVS </li>
  3739. <li><b>CREDENTIALS</b> - the value is "Set" if Credentials are set </li>
  3740. <li><b>NAME</b> - the cameraname in FHEM </li>
  3741. <li><b>OPMODE</b> - the last executed operation of the module </li>
  3742. <li><b>SERVERADDR</b> - IP-Address of SVS Host </li>
  3743. <li><b>SERVERPORT</b> - SVS-Port </li>
  3744. <br><br>
  3745. </ul>
  3746. </ul>
  3747. <a name="SSCamreadings"></a>
  3748. <b>Readings</b>
  3749. <ul>
  3750. <br>
  3751. Using the polling mechanism or retrieval by "get"-call readings are provieded, The meaning of the readings are listed in subsequent table: <br>
  3752. The transfered Readings can be deversified dependend on the type of camera.<br><br>
  3753. <ul>
  3754. <table>
  3755. <colgroup> <col width=5%> <col width=95%> </colgroup>
  3756. <tr><td><li>Availability</li> </td><td>- Availability of Camera (disabled, enabled, disconnected, other) </td></tr>
  3757. <tr><td><li>CamEventNum</li> </td><td>- delivers the total number of in SVS registered events of the camera </td></tr>
  3758. <tr><td><li>CamExposureControl</li> </td><td>- indicating type of exposure control </td></tr>
  3759. <tr><td><li>CamExposureMode</li> </td><td>- current exposure mode (Day, Night, Auto, Schedule, Unknown) </td></tr>
  3760. <tr><td><li>CamForceEnableMulticast</li> </td><td>- Is the camera forced to enable multicast. </td></tr>
  3761. <tr><td><li>CamIP</li> </td><td>- IP-Address of Camera </td></tr>
  3762. <tr><td><li>CamLastRec</li> </td><td>- Path / name of the last recording </td></tr>
  3763. <tr><td><li>CamLastRecTime</li> </td><td>- date / starttime / endtime of the last recording </td></tr>
  3764. <tr><td><li>CamLiveMode</li> </td><td>- Source of Live-View (DS, Camera) </td></tr>
  3765. <tr><td><li>CamModel</li> </td><td>- Model of camera </td></tr>
  3766. <tr><td><li>CamMotDetSc</li> </td><td>- state of motion detection source (disabled, by camera, by SVS) and their parameter </td></tr>
  3767. <tr><td><li>CamPort</li> </td><td>- IP-Port of Camera </td></tr>
  3768. <tr><td><li>CamPreRecTime</li> </td><td>- Duration of Pre-Recording (in seconds) adjusted in SVS </td></tr>
  3769. <tr><td><li>CamRecShare</li> </td><td>- shared folder on disk station for recordings </td></tr>
  3770. <tr><td><li>CamRecVolume</li> </td><td>- Volume on disk station for recordings </td></tr>
  3771. <tr><td><li>CamVendor</li> </td><td>- Identifier of camera producer </td></tr>
  3772. <tr><td><li>CamVideoFlip</li> </td><td>- Is the video flip </td></tr>
  3773. <tr><td><li>CamVideoMirror</li> </td><td>- Is the video mirror </td></tr>
  3774. <tr><td><li>CapAudioOut</li> </td><td>- Capability to Audio Out over Surveillance Station (false/true) </td></tr>
  3775. <tr><td><li>CapChangeSpeed</li> </td><td>- Capability to various motion speed </td></tr>
  3776. <tr><td><li>CapPTZAbs</li> </td><td>- Capability to perform absolute PTZ action </td></tr>
  3777. <tr><td><li>CapPTZAutoFocus</li> </td><td>- Capability to perform auto focus action </td></tr>
  3778. <tr><td><li>CapPTZDirections</li> </td><td>- the PTZ directions that camera support </td></tr>
  3779. <tr><td><li>CapPTZFocus</li> </td><td>- mode of support for focus action </td></tr>
  3780. <tr><td><li>CapPTZHome</li> </td><td>- Capability to perform home action </td></tr>
  3781. <tr><td><li>CapPTZIris</li> </td><td>- mode of support for iris action </td></tr>
  3782. <tr><td><li>CapPTZPan</li> </td><td>- Capability to perform pan action </td></tr>
  3783. <tr><td><li>CapPTZTilt</li> </td><td>- mode of support for tilt action </td></tr>
  3784. <tr><td><li>CapPTZZoom</li> </td><td>- Capability to perform zoom action </td></tr>
  3785. <tr><td><li>DeviceType</li> </td><td>- device type (Camera, Video_Server, PTZ, Fisheye) </td></tr>
  3786. <tr><td><li>Error</li> </td><td>- message text of last error </td></tr>
  3787. <tr><td><li>Errorcode</li> </td><td>- error code of last error </td></tr>
  3788. <tr><td><li>LastSnapFilename</li> </td><td>- the filename of the last snapshot </td></tr>
  3789. <tr><td><li>LastSnapId</li> </td><td>- the ID of the last snapshot </td></tr>
  3790. <tr><td><li>LastUpdateTime</li> </td><td>- date / time the last update of readings by "caminfoall" </td></tr>
  3791. <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>
  3792. <tr><td><li>Patrols</li> </td><td>- in Synology Surveillance Station predefined patrols (at PTZ-Cameras) </td></tr>
  3793. <tr><td><li>PollState</li> </td><td>- shows the state of automatic polling </td></tr>
  3794. <tr><td><li>Presets</li> </td><td>- in Synology Surveillance Station predefined Presets (at PTZ-Cameras) </td></tr>
  3795. <tr><td><li>Record</li> </td><td>- if recording is running = Start, if no recording is running = Stop </td></tr>
  3796. <tr><td><li>StmKey</li> </td><td>- current streamkey. it can be used to open livestreams without session id </td></tr>
  3797. <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>
  3798. <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>
  3799. <tr><td><li>SVScustomPortHttp</li> </td><td>- Customized port of Surveillance Station (HTTP) (to get with "svsinfo") </td></tr>
  3800. <tr><td><li>SVScustomPortHttps</li> </td><td>- Customized port of Surveillance Station (HTTPS) (to get with "svsinfo") </td></tr>
  3801. <tr><td><li>SVSlicenseNumber</li> </td><td>- The total number of installed licenses (to get with "svsinfo") </td></tr>
  3802. <tr><td><li>SVSuserPriv</li> </td><td>- The effective rights of the user used for log in (to get with "svsinfo") </td></tr>
  3803. <tr><td><li>SVSversion</li> </td><td>- package version of the installed Surveillance Station (to get with "svsinfo") </td></tr>
  3804. <tr><td><li>UsedSpaceMB</li> </td><td>- used disk space of recordings by Camera </td></tr>
  3805. <tr><td><li>VideoFolder</li> </td><td>- Path to the recorded video </td></tr>
  3806. </table>
  3807. </ul>
  3808. <br><br>
  3809. </ul>
  3810. <a name="SSCamattr"></a>
  3811. <b>Attributes</b>
  3812. <br><br>
  3813. <ul>
  3814. <ul>
  3815. <li><b>debugactivetoken</b> - if set the state of active token will be logged - only for debugging, don't use it in normal operation ! </li>
  3816. <li><b>disable</b> - deactivates the module (device definition) </li>
  3817. <li><b>httptimeout</b> - Timeout-Value of HTTP-Calls to Synology Surveillance Station, Default: 4 seconds (if httptimeout = "0" or not set) </li>
  3818. <li><b>htmlattr</b> - additional specifications to livestream-Url to manipulate the behavior of stream, e.g. size of the image </li>
  3819. <li><b>livestreamprefix</b> - overwrites the specifications of protocol, servername and port for further use of the livestream address, e.g. as an link to external use. It has to be specified as "http(s)://&lt;servername&gt;:&lt;port&gt;" </li>
  3820. <li><b>noQuotesForSID</b> - this attribute may be helpfull in some cases to avoid errormessage "402 - permission denied" and makes login possible. </li>
  3821. <li><b>pollcaminfoall</b> - Interval of automatic polling the Camera properties (if < 10: no polling, if &gt; 10: polling with interval) </li>
  3822. <li><b>pollnologging</b> - "0" resp. not set = Logging device polling active (default), "1" = Logging device polling inactive</li>
  3823. <li><b>rectime</b> - the determined recordtime when a recording starts. If rectime = 0 an endless recording will be started. If it isn't defined, the default recordtime of 15s is activated </li>
  3824. <li><b>recextend</b> - "rectime" of a started recording will be set new. Thereby the recording time of the running recording will be extended </li>
  3825. <li><b>session</b> - selection of login-Session. Not set or set to "DSM" -&gt; session will be established to DSM (Sdefault). "SurveillanceStation" -&gt; session will be established to SVS </li>
  3826. <li><b>simu_SVSversion</b> - simulates another SVS version. (only a lower version than the installed one is possible !) </li>
  3827. <li><b>showStmInfoFull</b> - additional stream informations like LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp will be created </li>
  3828. <li><b>showPassInLog</b> - if set the used password will be shown in logfile with verbose 4. (default = 0) </li>
  3829. <li><b>videofolderMap</b> - replaces the content of reading "VideoFolder", Usage if e.g. folders are mountet with different names than original (SVS) </li>
  3830. <li><b>verbose</b></li><br>
  3831. <ul>
  3832. Different Verbose-Level are supported.<br>
  3833. Those are in detail:
  3834. <table>
  3835. <colgroup> <col width=5%> <col width=95%> </colgroup>
  3836. <tr><td> 0 </td><td>- Start/Stop-Event will be logged </td></tr>
  3837. <tr><td> 1 </td><td>- Error messages will be logged </td></tr>
  3838. <tr><td> 2 </td><td>- messages according to important events were logged </td></tr>
  3839. <tr><td> 3 </td><td>- sended commands will be logged </td></tr>
  3840. <tr><td> 4 </td><td>- sended and received informations will be logged </td></tr>
  3841. <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>
  3842. </table>
  3843. </ul>
  3844. <br><br>
  3845. <b>further Attributes:</b><br><br>
  3846. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  3847. </ul>
  3848. </ul>
  3849. <br><br>
  3850. </ul>
  3851. =end html
  3852. =begin html_DE
  3853. <a name="SSCam"></a>
  3854. <h3>SSCam</h3>
  3855. <ul>
  3856. Mit diesem Modul können Operationen von in der Synology Surveillance Station (SVS) definierten Kameras ausgeführt werden. <br>
  3857. Zur Zeit werden folgende Funktionen unterstützt: <br><br>
  3858. <ul>
  3859. <ul>
  3860. <li>Start einer Aufnahme</li>
  3861. <li>Stop einer Aufnahme (per Befehl bzw. automatisch nach Ablauf der Aufnahmedauer) </li>
  3862. <li>Aufnehmen eines Schnappschusses und Ablage in der Synology Surveillance Station </li>
  3863. <li>Deaktivieren einer Kamera in Synology Surveillance Station</li>
  3864. <li>Aktivieren einer Kamera in Synology Surveillance Station</li>
  3865. <li>Steuerung der Belichtungsmodi Tag, Nacht bzw. Automatisch </li>
  3866. <li>Umschaltung der Ereigniserkennung durch Kamera, durch SVS oder deaktiviert </li>
  3867. <li>steuern der Erkennungsparameterwerte Empfindlichkeit, Schwellwert, Objektgröße und Prozentsatz für Auslösung </li>
  3868. <li>Abfrage von Kameraeigenschaften (auch mit Polling) sowie den Eigenschaften des installierten SVS-Paketes</li>
  3869. <li>Bewegen an eine vordefinierte Preset-Position (bei PTZ-Kameras) </li>
  3870. <li>Start einer vordefinierten Überwachungstour (bei PTZ-Kameras) </li>
  3871. <li>Positionieren von PTZ-Kameras zu absoluten X/Y-Koordinaten </li>
  3872. <li>kontinuierliche Bewegung von PTZ-Kameras </li>
  3873. <li>auslösen externer Ereignisse 1-10 (Aktionsregel SVS) </li>
  3874. <li>starten und beenden von Kamera-Livestreams </li>
  3875. <li>Abruf und Ausgabe der Kamera Streamkeys sowie Stream-Urls (Nutzung von Kamera-Livestreams ohne Session Id) </li>
  3876. <li>abspielen der letzten Aufnahme </li><br>
  3877. </ul>
  3878. </ul>
  3879. 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>
  3880. So werden zum Beispiel die Aufnahmen entsprechend ihrer Archivierungsfrist gespeichert und dann gelöscht. <br><br>
  3881. Wenn sie über dieses Modul diskutieren oder zur Verbesserung des Moduls beitragen möchten, ist im FHEM-Forum ein Sammelplatz unter:<br>
  3882. <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>
  3883. Weitere Infomationen zum Modul sind im FHEM-Wiki zu finden:<br>
  3884. <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>
  3885. <b>Vorbereitung </b> <br><br>
  3886. Dieses Modul nutzt das CPAN Module JSON. Bitte darauf achten dieses Paket zu installieren. (Debian: libjson-perl). <br>
  3887. Das Modul verwendet für HTTP-Calls die nichtblockierenden Funktionen von HttpUtils bzw. HttpUtils_NonblockingGet. <br>
  3888. 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>
  3889. Nähere Informationen dazu unter <a href="#SSCam_Credentials">Credentials</a><br><br>
  3890. Überblick über die Perl-Module welche von SSCam genutzt werden: <br><br>
  3891. JSON <br>
  3892. Data::Dumper <br>
  3893. MIME::Base64 <br>
  3894. Time::HiRes <br>
  3895. HttpUtils (FHEM-Modul) <br><br>
  3896. <a name="SSCamdefine"></a>
  3897. <b>Definition</b>
  3898. <ul>
  3899. <br>
  3900. <code>define &lt;name&gt; SSCAM &lt;Kameraname in SVS&gt; &lt;ServerAddr&gt; [Port] </code><br>
  3901. <br>
  3902. Definiert eine neue Kamera für SSCam. Zunächst muß diese Kamera in der Synology Surveillance Station 7.0 oder höher eingebunden sein und entsprechend funktionieren.<br><br>
  3903. Das Modul SSCam basiert auf Funktionen der Synology Surveillance Station API. <br>
  3904. Weitere Informationen unter: <a href="http://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf">Web API Guide</a>. <br><br>
  3905. Momentan wird nur das HTTP-Protokoll unterstützt um die Web-Services der Synology DS aufzurufen. <br><br>
  3906. Die Parameter beschreiben im Einzelnen:
  3907. <br>
  3908. <br>
  3909. <table>
  3910. <colgroup> <col width=15%> <col width=85%> </colgroup>
  3911. <tr><td>name: </td><td>der Name des neuen Gerätes in FHEM</td></tr>
  3912. <tr><td>Kameraname: </td><td>Kameraname wie er in der Synology Surveillance Station angegeben ist. Leerzeichen im Namen sind nicht erlaubt !</td></tr>
  3913. <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>
  3914. <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>
  3915. </table>
  3916. <br><br>
  3917. <b>Beispiel:</b>
  3918. <pre>
  3919. define CamCP SSCAM Carport 192.168.2.20 [5000]
  3920. </pre>
  3921. Wird eine neue Kamera definiert, wird diesem Device zunächst eine Standardaufnahmedauer von 15 zugewiesen. <br>
  3922. Ü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>
  3923. Ein Logeintrag mit einem entsprechenden Hinweis auf diesen Umstand wird geschrieben. <br><br>
  3924. Wird das <a href="#SSCamattr">Attribut</a> "rectime" gelöscht, greift wieder der Default-Wert (15s) für die Aufnahmedauer. <br><br>
  3925. 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>
  3926. Auch in diesem Fall führt <b>"set &lt;name&gt; on 0"</b> zu einer Daueraufnahme. <br><br>
  3927. Eine eventuell in der SVS eingestellte Dauer der Voraufzeichnung wird weiterhin berücksichtigt. <br><br><br>
  3928. <a name="SSCam_Credentials"></a>
  3929. <b>Credentials </b><br><br>
  3930. Nach dem Definieren des Gerätes müssen zuerst die Zugangsparameter gespeichert werden. Das geschieht mit dem Befehl:
  3931. <pre>
  3932. set &lt;name&gt; credentials &lt;Username&gt; &lt;Passwort&gt;
  3933. </pre>
  3934. Der Anwender kann in Abhängigkeit der beabsichtigten einzusetzenden Funktionen einen Nutzer im DSM bzw. in der Surveillance Station einrichten. <br>
  3935. 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>
  3936. Rechtebedarf ausgeführt werden. Die benötigten Mindestrechte der Funktionen sind in der Tabelle weiter unten aufgeführt. <br>
  3937. 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>
  3938. auszuführen, wobei der Zugriff auf bestimmte Kameras/ im Privilegienprofil beschränkt werden kann (siehe Hilfefunktion in SVS). <br>
  3939. Als Best Practice wird vorgeschlagen jeweils einen User im DSM und einen in der SVS anzulegen: <br><br>
  3940. <ul>
  3941. <li>DSM-User als Mitglied der Admin-Gruppe: uneingeschränkter Test aller Modulfunktionen -> session:DSM </li>
  3942. <li>SVS-User als Manager oder Betrachter: angepasstes Privilegienprofil -> session: SurveillanceStation </li>
  3943. </ul>
  3944. <br>
  3945. Ü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>
  3946. 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>
  3947. 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>
  3948. 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>
  3949. Die nachfolgende Aufstellung zeigt die Mindestanforderungen der jeweiligen Modulfunktionen an die Nutzerrechte. <br><br>
  3950. <ul>
  3951. <table>
  3952. <colgroup> <col width=20%> <col width=80%> </colgroup>
  3953. <tr><td><li>set ... on </td><td> session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme" </li></td></tr>
  3954. <tr><td><li>set ... off </td><td> session: ServeillanceStation - Betrachter mit erweiterten Privileg "manuelle Aufnahme" </li></td></tr>
  3955. <tr><td><li>set ... snap </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3956. <tr><td><li>set ... disable </td><td> session: ServeillanceStation - Manager </li></td></tr>
  3957. <tr><td><li>set ... enable </td><td> session: ServeillanceStation - Manager </li></td></tr>
  3958. <tr><td><li>set ... expmode </td><td> session: ServeillanceStation - Manager </li></td></tr>
  3959. <tr><td><li>set ... motdetsc </td><td> session: ServeillanceStation - Manager </li></td></tr>
  3960. <tr><td><li>set ... goPreset </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  3961. <tr><td><li>set ... runPatrol </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  3962. <tr><td><li>set ... goAbsPTZ </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  3963. <tr><td><li>set ... move </td><td> session: ServeillanceStation - Betrachter mit Privileg Objektivsteuerung der Kamera </li></td></tr>
  3964. <tr><td><li>set ... runView </td><td> session: ServeillanceStation - Betrachter mit Privileg Liveansicht für Kamera </li></td></tr>
  3965. <tr><td><li>set ... stopView </td><td> - </li></td></tr>
  3966. <tr><td><li>set ... credentials </td><td> - </li></td></tr>
  3967. <tr><td><li>set ... extevent </td><td> session: DSM - Nutzer Mitglied von Admin-Gruppe </li></td></tr>
  3968. <tr><td><li>get ... caminfoall </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3969. <tr><td><li>get ... eventlist </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3970. <tr><td><li>get ... svsinfo </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3971. <tr><td><li>get ... snapfileinfo </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3972. <tr><td><li>get ... stmUrlPath </td><td> session: ServeillanceStation - Betrachter </li></td></tr>
  3973. </table>
  3974. </ul>
  3975. <br><br>
  3976. <a name="SSCam_HTTPTimeout"></a>
  3977. <b>HTTP-Timeout setzen</b><br><br>
  3978. Alle Funktionen dieses Moduls verwenden HTTP-Aufrufe gegenüber der SVS Web API. <br>
  3979. 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>
  3980. </ul>
  3981. <br><br><br>
  3982. <a name="SSCamset"></a>
  3983. <b>Set </b>
  3984. <ul>
  3985. Es gibt zur Zeit folgende Optionen für "set &lt;name&gt; ...": <br><br>
  3986. <table>
  3987. <colgroup> <col width=30%> <col width=70%> </colgroup>
  3988. <tr><td>"on [rectime]": </td><td>startet eine Aufnahme. Die Aufnahme wird automatisch nach Ablauf der Zeit [rectime] gestoppt.</td></tr>
  3989. <tr><td> </td><td>Mit rectime = 0 wird eine Daueraufnahme gestartet die durch "set &lt;name&gt; off" wieder gestoppt werden muß.</td></tr>
  3990. <tr><td>"off" : </td><td>stoppt eine laufende Aufnahme manuell oder durch die Nutzung anderer Events (z.B. über at, notify)</td></tr>
  3991. <tr><td>"snap": </td><td>löst einen Schnappschuß der entsprechenden Kamera aus und speichert ihn in der Synology Surveillance Station</td></tr>
  3992. <tr><td>"disable": </td><td>deaktiviert eine Kamera in der Synology Surveillance Station</td></tr>
  3993. <tr><td>"enable": </td><td>aktiviert eine Kamera in der Synology Surveillance Station</td></tr>
  3994. <tr><td>"credentials &lt;username&gt; &lt;password&gt;": </td><td>speichert die Zugangsinformationen</td></tr>
  3995. <tr><td>"expmode [ day | night | auto ]": </td><td>aktiviert den Belichtungsmodus Tag, Nacht oder Automatisch </td></tr>
  3996. <tr><td>"extevent [ 1-10 ]": </td><td>löst das externe Ereignis 1-10 aus (Aktionsregel in SVS) </td></tr>
  3997. <tr><td>"motdetsc [ camera | SVS | disable ]": </td><td>schaltet die Bewegungserkennung in den gewünschten Modus (durch Kamera, SVS, oder deaktiviert) </td></tr>
  3998. <tr><td>"goPreset &lt;Presetname&gt;": </td><td>bewegt eine PTZ-Kamera zu einer vordefinierten Preset-Position </td></tr>
  3999. <tr><td>"runPatrol &lt;Patrolname&gt;": </td><td>startet eine vordefinierte Überwachungstour einer PTZ-Kamera </td></tr>
  4000. <tr><td>"goAbsPTZ [ X Y | up | down | left | right ]": </td><td>positioniert eine PTZ-camera zu einer absoluten X/Y-Koordinate oder maximalen up/down/left/right-position </td></tr>
  4001. <tr><td>"move [ up | down | left | right | dir_X ]": </td><td>startet kontinuerliche Bewegung einer PTZ-Kamera in Richtung up/down/left/right bzw. dir_X </td></tr>
  4002. <tr><td>"runView [image | link | link_open | lastrec | lastrec_open | &lt;room&gt; ]": </td><td>startet einen Livestream als eingbettetes Image oder als Link </td></tr>
  4003. <tr><td>"stopView": </td><td>stoppt einen Kamera-Livestream </td></tr>
  4004. </table>
  4005. <br><br>
  4006. <b> "set &lt;name&gt; [on] [off]" </b> <br><br>
  4007. 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.
  4008. Die im Attribut (bzw. im Standard) hinterlegte Aufnahmedauer kann einmalig mit "set &lt;name&gt; on [rectime]" überschrieben werden.
  4009. Die Aufnahme stoppt automatisch nach Ablauf der Zeit "rectime".<br>
  4010. 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
  4011. explizit wieder mit dem Befehl "set &lt;name&gt; off" gestoppt werden muß.<br>
  4012. Das Aufnahmeverhalten kann weiterhin mit dem Attribut "recextend" wie folgt beeinflusst werden.<br><br>
  4013. <b>Attribut "recextend = 0" bzw. nicht gesetzt (Standard):</b><br><br>
  4014. <ul>
  4015. <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
  4016. beendet ist. Ein Hinweis wird bei verbose=3 im Logfile protokolliert. </li>
  4017. </ul>
  4018. <br>
  4019. <b>Attribut "recextend = 1" gesetzt:</b><br><br>
  4020. <ul>
  4021. <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
  4022. den automatischen Stop auf den Wert "rectime" neu gesetzt wird. Dieser Vorgang wiederholt sich mit jedem Start-Befehl. Dadurch verlängert sich eine laufende
  4023. Aufnahme bis kein Start-Inpuls mehr registriert wird. </li>
  4024. <li> eine zuvor gestartete Endlos-Aufnahme wird mit einem erneuten "set <name> on"-Befehl nach der Aufnahmezeit "rectime" gestoppt (Timerneustart). Ist dies
  4025. nicht gewünscht, ist darauf zu achten dass bei der Verwendung einer Endlos-Aufnahme das Attribut "recextend" nicht verwendet wird. </li>
  4026. </ul>
  4027. <br>
  4028. Beispiele für einfachen <b>Start/Stop einer Aufnahme</b>: <br><br>
  4029. <table>
  4030. <colgroup> <col width=20%> <col width=80%> </colgroup>
  4031. <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>
  4032. <tr><td>set &lt;name&gt; off </td><td>stoppt die Aufnahme der Kamera &lt;name&gt;</td></tr>
  4033. </table>
  4034. <br>
  4035. <br>
  4036. <b> "set &lt;name&gt; snap" </b> <br><br>
  4037. Ein <b>Schnappschuß</b> kann ausgelöst werden mit:
  4038. <pre>
  4039. set &lt;name&gt; snap
  4040. </pre>
  4041. Nachfolgend einige Beispiele für die <b>Auslösung von Schnappschüssen</b>. <br><br>
  4042. Soll eine Reihe von Schnappschüssen ausgelöst werden wenn eine Aufnahme startet, kann das z.B. durch folgendes notify geschehen. <br>
  4043. 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.
  4044. <pre>
  4045. define he1_snap_3 notify CamHE1:Record.*Start define h3 at +*{3}00:00:02 set CamHE1 snap
  4046. </pre>
  4047. Triggern von 2 Schnappschüssen der Kamera "CamHE1" im Abstand von 6 Sekunden nachdem der Bewegungsmelder "MelderHE1" einen Event gesendet hat, <br>
  4048. kann z.B. mit folgendem notify geschehen:
  4049. <pre>
  4050. define he1_snap_2 notify MelderHE1:on.* define h2 at +*{2}00:00:06 set CamHE1 snap
  4051. </pre>
  4052. 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>
  4053. <b> "set &lt;name&gt; [enable] [disable]" </b> <br><br>
  4054. 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:
  4055. <pre>
  4056. define a13 at 21:46 set CamCP1,CamFL,CamHE1,CamTER disable (enable)
  4057. define a14 at 21:46 set Cam.* disable (enable)
  4058. </pre>
  4059. Etwas komfortabler gelingt das Schalten aller Kameras über einen Dummy. Zunächst wird der Dummy angelegt:
  4060. <pre>
  4061. define allcams dummy
  4062. attr allcams eventMap on:enable off:disable
  4063. attr allcams room Cams
  4064. attr allcams webCmd enable:disable
  4065. </pre>
  4066. 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.
  4067. <pre>
  4068. define all_cams_disable notify allcams:.*off set CamCP1,CamFL,CamHE1,CamTER disable
  4069. attr all_cams_disable room Cams
  4070. define all_cams_enable notify allcams:on set CamCP1,CamFL,CamHE1,CamTER enable
  4071. attr all_cams_enable room Cams
  4072. </pre>
  4073. <br><br>
  4074. <b> "set &lt;name&gt; expmode [day] [night] [auto]" </b> <br><br>
  4075. Mit diesem Befehl kann der Belichtungsmodus der Kameras gesetzt werden. Dadurch wird z.B. das Verhalten der Kamera-LED's entsprechend gesteuert.
  4076. Die erfolgreiche Umschaltung wird durch das Reading CamExposureMode ("get ... caminfoall") reportet. <br><br>
  4077. <b> Hinweis: </b> <br>
  4078. Die erfolgreiche Ausführung dieser Funktion ist davon abhängig ob die SVS diese Funktionalität der Kamera unterstützt.
  4079. 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
  4080. Funktion auszugehen.
  4081. <br><br><br>
  4082. <b> "set &lt;name&gt; motdetsc [camera] [SVS] [disable]" </b> <br><br>
  4083. Der Befehl "motdetsc" (steht für motion detection source) schaltet die Bewegungserkennung in den gewünschten Modus.
  4084. Wird die Bewegungserkennung durch die Kamera / SVS ohne weitere Optionen eingestellt, werden die momentan gültigen Bewegungserkennungsparameter der
  4085. 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;
  4086. Bewegung nachvollziehen. <br><br>
  4087. Für die Bewegungserkennung durch SVS bzw. durch Kamera können weitere Optionen angegeben werden. Die verfügbaren Optionen bezüglich der Bewegungserkennung
  4088. durch SVS sind "Empfindlichkeit" und "Schwellwert". <br><br>
  4089. <ul>
  4090. <table>
  4091. <colgroup> <col width=50%> <col width=50%> </colgroup>
  4092. <tr><td>set <name> motdetsc SVS [Empfindlichkeit] [Schwellwert] </td><td># Befehlsmuster </td></tr>
  4093. <tr><td>set <name> motdetsc SVS 91 30 </td><td># setzt die Empfindlichkeit auf 91 und den Schwellwert auf 30 </td></tr>
  4094. <tr><td>set <name> motdetsc SVS 0 40 </td><td># behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40 </td></tr>
  4095. <tr><td>set <name> motdetsc SVS 15 </td><td># setzt die Empfindlichkeit auf 15, Schwellwert bleibt unverändert </td></tr>
  4096. </table>
  4097. </ul>
  4098. <br><br>
  4099. Wird die Bewegungserkennung durch die Kamera genutzt, stehen die Optionen "Empfindlichkeit", "Objektgröße" und "Prozentsatz für Auslösung" zur Verfügung. <br><br>
  4100. <ul>
  4101. <table>
  4102. <colgroup> <col width=50%> <col width=50%> </colgroup>
  4103. <tr><td>set <name> motdetsc camera [Empfindlichkeit] [Schwellwert] [Prozentsatz] </td><td># Befehlsmuster </td></tr>
  4104. <tr><td>set <name> motdetsc camera 89 0 20 </td><td># setzt die Empfindlichkeit auf 89, Prozentsatz auf 20 </td></tr>
  4105. <tr><td>set <name> motdetsc camera 0 40 10 </td><td># behält gesetzten Wert für Empfindlichkeit bei, setzt Schwellwert auf 40, Prozentsatz auf 10 </td></tr>
  4106. <tr><td>set <name> motdetsc camera 30 </td><td># setzt die Empfindlichkeit auf 30, andere Werte bleiben unverändert </td></tr>
  4107. </table>
  4108. </ul>
  4109. <br><br>
  4110. Es ist immer die Reihenfolge der Optionswerte zu beachten. Nicht gewünschte Optionen sind mit "0" zu besetzen sofern danach Optionen folgen
  4111. deren Werte verändert werden sollen (siehe Beispiele oben). Der Zahlenwert der Optionen beträgt 1 - 99 (außer Sonderfall "0"). <br><br>
  4112. 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
  4113. SVS -&gt; Kamera bearbeiten -&gt; Ereigniserkennung zur Verfügung stehen. Weitere Infos sind der Online-Hilfe zur SVS zu entnehmen. <br><br>
  4114. Über den Befehl "get ... caminfoall" wird auch das <a href="#SSCamreadings">Reading</a> "CamMotDetSc" aktualisiert welches die gegenwärtige Einstellung der Bewegungserkennung dokumentiert.
  4115. 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>
  4116. Beipiel:
  4117. <pre>
  4118. CamMotDetSc SVS, sensitivity: 76, threshold: 55
  4119. </pre>
  4120. <br><br>
  4121. <b> "set &lt;name&gt; goPreset &lt;Preset&gt;" </b> <br><br>
  4122. Mit diesem Kommando können PTZ-Kameras in eine vordefininierte Position bewegt werden. <br>
  4123. 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.
  4124. Die Presets werden über das Kommando "get &lt;name&gt; caminfoall" eingelesen (geschieht bei restart von FHEM automatisch). Der Einlesevorgang kann durch ein Kamerapolling
  4125. 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.
  4126. <br><br>
  4127. Hier ein Beispiel einer PTZ-Steuerung in Abhängigkeit eines IR-Melder Events:
  4128. <pre>
  4129. 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
  4130. </pre>
  4131. Funktionsweise: <br>
  4132. 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
  4133. später. Da die Voraufnahmezeit der Kamera 10s beträgt (vgl. Reading "CamPreRecTime"), startet die effektive Aufnahme wenn der Kameraschwenk beginnt. <br>
  4134. Mit dem Start der Aufnahme werden drei Schnappschüsse im Abstand von 5 Sekunden angefertigt. <br>
  4135. Nach einer Zeit von 30 Sekunden fährt die Kamera wieder zurück in die "Home"-Position. <br><br>
  4136. Ein Auszug aus dem Log verdeutlicht den Ablauf:
  4137. <pre>
  4138. 2016.02.04 15:02:14 2: CamFL - Camera Flur_Vorderhaus has moved to position "Wandschrank"
  4139. 2016.02.04 15:02:24 2: CamFL - Camera Flur_Vorderhaus Recording with Recordtime 5s started
  4140. 2016.02.04 15:02:29 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4141. 2016.02.04 15:02:30 2: CamFL - Camera Flur_Vorderhaus Recording stopped
  4142. 2016.02.04 15:02:34 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4143. 2016.02.04 15:02:39 2: CamFL - Snapshot of Camera Flur_Vorderhaus has been done successfully
  4144. 2016.02.04 15:02:44 2: CamFL - Camera Flur_Vorderhaus has moved to position "Home"
  4145. </pre>
  4146. <br>
  4147. <b> "set &lt;name&gt; runPatrol &lt;Patrolname&gt;" </b> <br><br>
  4148. Dieses Kommando startet die vordefinierterte Überwachungstour einer PTZ-Kamera. <br>
  4149. Die Überwachungstouren müssen dazu zunächst in der Synology Surveillance Station angelegt worden sein.
  4150. Das geschieht in der PTZ-Steuerung im IP-Kamera Setup -&gt; PTZ-Steuerung -&gt; Überwachung.
  4151. Die Überwachungstouren (Patrols) werden über das Kommando "get &lt;name&gt; caminfoall" eingelesen, welches beim Restart von FHEM automatisch abgearbeitet wird.
  4152. Der Einlesevorgang kann durch ein Kamerapolling regelmäßig wiederholt werden. Ein langes Pollingintervall ist in diesem Fall empfehlenswert, da sich die
  4153. Überwachungstouren nur im Fall der Neuanlage bzw. Änderung verändern werden.
  4154. Nähere Informationen zur Anlage von Überwachungstouren sind in der Hilfe zur Surveillance Station enthalten.
  4155. <br><br>
  4156. <b> "set &lt;name&gt; goAbsPTZ [ X Y | up | down | left | right ]" </b> <br><br>
  4157. 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.
  4158. 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.
  4159. <br><br>
  4160. Beispiel für Ansteuerung absoluter X/Y-Koordinaten: <br>
  4161. <pre>
  4162. set &lt;name&gt; goAbsPTZ 120 450
  4163. </pre>
  4164. Dieses Beispiel bewegt die Kameralinse in die Position X=120 und Y=450. <br>
  4165. Der Wertebereich ist dabei:
  4166. <pre>
  4167. X = 0 - 640 (0 - 319 bewegt nach links, 321 - 640 bewegt nach rechts, 320 bewegt die Linse nicht)
  4168. Y = 0 - 480 (0 - 239 bewegt nach unten, 241 - 480 bewegt nach oben, 240 bewegt die Linse nicht)
  4169. </pre>
  4170. Die Linse kann damit in kleinsten bis sehr großen Schritten in die gewünschte Richtung bewegt werden.
  4171. Dieser Vorgang muß ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen. <br><br>
  4172. Soll die Bewegung mit der maximalen Schrittweite erfolgen, kann zur Vereinfachung der Befehl:
  4173. <pre>
  4174. set &lt;name&gt; goAbsPTZ up [down ] [left] [right]
  4175. </pre>
  4176. verwendet werden. Die Optik wird in diesem Fall mit der größt möglichen Schrittweite zur Absolutposition in der angegebenen Richtung bewegt.
  4177. Auch in diesem Fall muß der Vorgang ggf. mehrfach wiederholt werden um die Kameralinse in die gewünschte Position zu bringen.
  4178. <br><br><br>
  4179. <b> set &lt;name&gt; move [ up | down | left | right | dir_X ] [Sekunden] </b> <br><br>
  4180. Mit diesem Kommando wird eine kontinuierliche Bewegung der PTZ-Kamera gestartet. Neben den vier Grundrichtungen up/down/left/right stehen auch
  4181. 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>
  4182. Das Bogenmaß von 360 Grad teilt sich durch den Wert von "CapPTZDirections" und beschreibt die Bewegungsrichtungen beginnend mit "0=rechts" entgegen dem
  4183. 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
  4184. die entsprechenden Zwischenrichtungen. Die möglichen Bewegungsrichtungen bei Kameras mit "CapPTZDirections = 32" sind dementsprechend kleinteiliger. <br><br>
  4185. 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.
  4186. 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>
  4187. <b>Beispiele: </b><br>
  4188. <pre>
  4189. set &lt;name&gt; move up 0.5 : bewegt PTZ 0,5 Sek. (zzgl. Prozesszeit) nach oben
  4190. set &lt;name&gt; move dir_1 1.5 : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach rechts-oben
  4191. set &lt;name&gt; move dir_20 0.7 : bewegt PTZ 1,5 Sek. (zzgl. Prozesszeit) nach links-unten ("CapPTZDirections = 32)"
  4192. </pre>
  4193. <br>
  4194. <b> set &lt;name&gt; runView [ image | lastrec | lastrec_open | link | link_open &lt;room&gt; ] </b> <br><br>
  4195. Mit "image, link, link_open" wird ein Livestream (mjpeg-Stream) der Kamera, entweder als eingebettetes Image oder als generierter Link, gestartet.
  4196. Der Zugriff auf die letzte Aufnahme einer Kamera kann über die Zusätze "lastrec" bzw. "lastrec_open" erfolgen.
  4197. Das Verhalten des Livestreams im FHEMWEB kann durch Angaben im <a href="#SSCamattr">Attribut</a> "htmlattr" beeinflusst werden. <br><br>
  4198. <b>Beispiel:</b><br>
  4199. <pre>
  4200. attr &lt;name&gt; htmlattr target=_blank width="500" height="375"
  4201. attr &lt;name&gt; htmlattr target=_blank width=500,height=375
  4202. attr &lt;name&gt; htmlattr width=700,height=525,top=200,left=300
  4203. </pre>
  4204. Mit diesen Attributwerten öffnet der Link (mit Klick) als weiteres Fenster/Browsertab. Wird der Stream als Image gestartet, ändert sich die Größe entsprechend der
  4205. Angaben von Width und Hight. <br>
  4206. Das Kommando <b>"set &lt;name&gt; runView link_open"</b> startet den Livestreamlink sofort in einem neuen Browserfenster (longpoll=1 muß für WEB gesetzt sein).
  4207. Dabei wird für jede aktive FHEM-Session eine Fensteröffnung initiiert. Soll dieses Verhalten geändert werden, kann <b>"set &lt;name&gt; runView link_open &lt;room&gt;"</b>
  4208. verwendet werden um das Öffnen des Browserwindows in einem beliebigen, in einer FHEM-Session angezeigten Raum &lt;room&gt;, zu initiieren.<br>
  4209. Das gesetzte <a href="#SSCamattr">Attribut</a> "livestreamprefix" überschreibt im <a href="#SSCamreadings">Reading</a> "LiveStreamUrl" die Angaben für Protokoll, Servername und Port.
  4210. Damit kann z.B. die LiveStreamUrl für den Versand und externen Zugriff auf die SVS modifiziert werden. <br><br>
  4211. <b>Beispiel:</b><br>
  4212. <pre>
  4213. attr &lt;name&gt; livestreamprefix https://&lt;Servername&gt;:&lt;Port&gt;
  4214. </pre>
  4215. Der Livestream wird über das Kommando <b>"set &lt;name&gt; stopView"</b> wieder beendet.
  4216. <br><br>
  4217. <b> set &lt;name&gt; extevent [ 1-10 ] </b> <br><br>
  4218. Dieses Kommando triggert ein externes Ereignis (1-10) in der SVS.
  4219. Die Aktionen, die dieses Ereignis auslöst, sind zuvor in dem Aktionsregeleditor der SVS einzustellen. Es stehen die Ereignisse 1-10 zur Verfügung.
  4220. In der Banchrichtigungs-App der SVS können auch Email, SMS oder Mobil (DS-Cam) Nachrichten ausgegeben werden wenn ein externes Ereignis ausgelöst wurde.
  4221. Nähere Informationen dazu sind in der Hilfe zum Aktionsregeleditor zu finden.
  4222. Der verwendete User benötigt Admin-Rechte in einer DSM-Session.
  4223. <br><br><br>
  4224. </ul>
  4225. <br>
  4226. <a name="SSCamget"></a>
  4227. <b>Get</b>
  4228. <ul>
  4229. Mit SSCam können die Eigenschaften der Surveillance Station und der Kameras abgefragt werden. ZUr Zeit stehen dazu folgende Befehle zur Verfügung:
  4230. <pre>
  4231. get &lt;name&gt; caminfoall
  4232. get &lt;name&gt; eventlist
  4233. get &lt;name&gt; stmUrlPath
  4234. get &lt;name&gt; svsinfo
  4235. get &lt;name&gt; snapfileinfo
  4236. </pre>
  4237. Mit dem Befehl <b>"get &lt;name&gt; caminfoall"</b> werden abhängig von der Art der Kamera (z.B. Fix- oder PTZ-Kamera) die verfügbaren Eigenschaften ermittelt und als Readings zur Verfügung gestellt. <br>
  4238. So wird zum Beispiel das Reading "Availability" auf "disconnected" gesetzt falls die Kamera von der Surveillance Station getrennt wird und kann für weitere Verarbeitungen genutzt werden. <br>
  4239. Durch <b>"get &lt;name&gt; eventlist"</b> wird das <a href="#SSCamreadings">Reading</a> "CamEventNum" und "CamLastRec" aktualisiert, welches die Gesamtanzahl der
  4240. registrierten Kameraevents und den Pfad / Namen der letzten Aufnahme enthält.
  4241. Dieser Befehl wird implizit mit "get ... caminfoall" ausgeführt. <br>
  4242. Mit dem <a href="#SSCamattr">Attribut</a> "videofolderMap" kann der Inhalt des Readings "VideoFolder" überschrieben werden.
  4243. Dies kann von Vortel sein wenn das Surveillance-Verzeichnis der SVS an dem lokalen PC unter anderem Pfadnamen gemountet ist und darüber der Zugriff auf die Aufnahmen
  4244. erfolgen soll (z.B. Verwendung Email-Versand). <br><br>
  4245. Ein DOIF-Beispiel für den Email-Versand von Snapshot und Aufnahmelink per Non-blocking sendmail:
  4246. <pre>
  4247. define CamHE1.snap.email DOIF ([CamHE1:"LastSnapFilename"])
  4248. ({DebianMailnbl ('Recipient@Domain','Bewegungsalarm CamHE1','Eine Bewegung wurde an der Haustür registriert. Aufnahmelink: \
  4249. \[CamHE1:VideoFolder]\[CamHE1:CamLastRec]','/media/sf_surveillance/@Snapshot/[CamHE1:LastSnapFilename]')})
  4250. </pre>
  4251. Mit <b>"get &lt;name&gt; snapfileinfo"</b> wird der Filename des letzten Schnapschusses ermittelt. Der Befehl wird implizit mit <b>"get &lt;name&gt; snap"</b> ausgeführt. <br>
  4252. Der Befehl <b>"get &lt;name&gt; svsinfo"</b> ist eigentlich nicht von der Kamera abhängig, sondern ermittelt vielmehr allgemeine Informationen zur installierten SVS-Version und andere Eigenschaften. <br>
  4253. Die Funktionen "caminfoall" und "svsinfo" werden einmalig automatisch beim Start von FHEM ausgeführt um steuerungsrelevante Informationen zu sammeln.<br>
  4254. Es ist darauf zu achten dass die <a href="#SSCam_Credentials">Credentials</a> gespeichert wurden !
  4255. <br><br>
  4256. <b> get &lt;name&gt; stmUrlPath </b> <br><br>
  4257. Mit diesem Kommando wird der aktuelle Streamkey der Kamera abgerufen und das Reading mit dem Key-Wert gefüllt.
  4258. Dieser Streamkey kann verwendet werden um eigene Aufrufe eines Livestreams aufzubauen (siehe Beispiel).
  4259. Wenn das <a href="#SSCamattr">Attribut</a> "showStmInfoFull" gesetzt ist, werden zusaätzliche Stream-Informationen wie "StmKeyUnicst", "StmKeymjpegHttp" ausgegeben.
  4260. 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.
  4261. 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.
  4262. Wird Polling der Kameraeigenschaften genutzt, wird die stmUrlPath-Funktion automatisch mit ausgeführt.
  4263. <br><br>
  4264. Beispiel für den Aufbau eines Http-Calls zu einem Livestream mit StmKey:
  4265. <pre>
  4266. 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"
  4267. </pre>
  4268. cameraId (INTERNAL), StmKey müssen durch gültige Werte ersetzt werden. <br><br>
  4269. <b>Hinweis:</b> <br>
  4270. Falls der Stream-Aufruf versendet und von extern genutzt wird sowie hostname / port durch gültige Werte ersetzt und die Routerports entsprechend geöffnet
  4271. werden, ist darauf zu achten dass diese sensiblen Daten nicht durch unauthorisierte Personen für den Zugriff genutzt werden können ! <br><br><br>
  4272. <b>Polling der Kameraeigenschaften:</b><br><br>
  4273. Die Abfrage der Kameraeigenschaften erfolgt automatisch, wenn das Attribut "pollcaminfoall" (siehe Attribute) mit einem Wert &gt; 10 gesetzt wird. <br>
  4274. Per Default ist das Attribut "pollcaminfoall" nicht gesetzt und das automatische Polling nicht aktiv. <br>
  4275. 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>
  4276. gestartet bzw. gestoppt wenn vorher der Wert &gt; 10 gesetzt war. <br><br>
  4277. Das Attribut "pollcaminfoall" wird durch einen Watchdog-Timer überwacht. Änderungen des Attributwertes werden alle 90 Sekunden ausgewertet und entsprechend umgesetzt. <br>
  4278. Eine Änderung des Pollingstatus / Pollingintervalls wird im FHEM-Logfile protokolliert. Diese Protokollierung kann durch Setzen des Attributes "pollnologging=1" abgeschaltet werden.<br>
  4279. Dadurch kann ein unnötiges Anwachsen des Logs vermieden werden. Ab verbose=4 wird allerdings trotz gesetzten "pollnologging"-Attribut ein Log des Pollings <br>
  4280. zu Analysezwecken aktiviert. <br><br>
  4281. Wird FHEM neu gestartet, wird bei aktivierten Polling der ersten Datenabruf innerhalb 60s nach dem Start ausgeführt. <br><br>
  4282. Der Status des automatischen Pollings wird durch das Reading "PollState" signalisiert: <br><br>
  4283. <ul>
  4284. <li><b> PollState = Active </b> - automatisches Polling wird mit Intervall entsprechend "pollcaminfoall" ausgeführt </li>
  4285. <li><b> PollState = Inactive </b> - automatisches Polling wird nicht ausgeführt </li>
  4286. </ul>
  4287. <br>
  4288. Die Bedeutung der Readingwerte ist unter <a href="#SSCamreadings">Readings</a> beschrieben. <br><br>
  4289. <b>Hinweise:</b> <br><br>
  4290. Wird Polling eingesetzt, sollte das Intervall nur so kurz wie benötigt eingestellt werden da die ermittelten Werte überwiegend statisch sind. <br>
  4291. Das eingestellte Intervall sollte nicht kleiner sein als die Summe aller HTTP-Verarbeitungszeiten.
  4292. Pro Pollingaufruf und Kamera werden ca. 10 - 20 Http-Calls gegen die Surveillance Station abgesetzt.<br><br>
  4293. 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>
  4294. In dem Beispiel sollte man das Pollingintervall mit einem Sicherheitszuschlag auf nicht weniger 160 Sekunden setzen. <br>
  4295. Ein praktikabler Richtwert könnte zwischen 600 - 1800 (s) liegen. <br>
  4296. Sind mehrere Kameras in SSCam definiert, sollte "pollcaminfoall" nicht bei allen Kameras auf exakt den gleichen Wert gesetzt werden um Verarbeitungsengpässe <br>
  4297. und dadurch versursachte potentielle Fehlerquellen bei der Abfrage der Synology Surveillance Station zu vermeiden. <br>
  4298. Ein geringfügiger Unterschied zwischen den Pollingintervallen der definierten Kameras von z.B. 1s kann bereits als ausreichend angesehen werden. <br><br>
  4299. </ul>
  4300. <a name="SSCaminternals"></a>
  4301. <b>Internals</b> <br>
  4302. <ul>
  4303. Die Bedeutung der verwendeten Internals stellt die nachfolgende Liste dar: <br><br>
  4304. <ul>
  4305. <li><b>CAMID</b> - die ID der Kamera in der SVS, der Wert wird automatisch anhand des SVS-Kameranamens ermittelt. </li>
  4306. <li><b>CAMNAME</b> - der Name der Kamera in der SVS </li>
  4307. <li><b>CREDENTIALS</b> - der Wert ist "Set" wenn die Credentials gesetzt wurden </li>
  4308. <li><b>NAME</b> - der Kameraname in FHEM </li>
  4309. <li><b>OPMODE</b> - die zuletzt ausgeführte Operation des Moduls </li>
  4310. <li><b>SERVERADDR</b> - IP-Adresse des SVS Hostes </li>
  4311. <li><b>SERVERPORT</b> - der SVS-Port </li>
  4312. <br><br>
  4313. </ul>
  4314. </ul>
  4315. <a name="SSCamreadings"></a>
  4316. <b>Readings</b>
  4317. <ul>
  4318. <br>
  4319. Über den Pollingmechanismus bzw. durch Abfrage mit "Get" werden Readings bereitgestellt, deren Bedeutung in der nachfolgenden Tabelle dargestellt sind. <br>
  4320. Die übermittelten Readings können in Abhängigkeit des Kameratyps variieren.<br><br>
  4321. <ul>
  4322. <table>
  4323. <colgroup> <col width=5%> <col width=95%> </colgroup>
  4324. <tr><td><li>Availability</li> </td><td>- Verfügbarkeit der Kamera (disabled, enabled, disconnected, other) </td></tr>
  4325. <tr><td><li>CamEventNum</li> </td><td>- liefert die Gesamtanzahl der in SVS registrierten Events der Kamera </td></tr>
  4326. <tr><td><li>CamExposureControl</li> </td><td>- zeigt den aktuell eingestellten Typ der Belichtungssteuerung </td></tr>
  4327. <tr><td><li>CamExposureMode</li> </td><td>- aktueller Belichtungsmodus (Day, Night, Auto, Schedule, Unknown) </td></tr>
  4328. <tr><td><li>CamForceEnableMulticast</li> </td><td>- sagt aus ob die Kamera verpflichet ist Multicast einzuschalten. </td></tr>
  4329. <tr><td><li>CamIP</li> </td><td>- IP-Adresse der Kamera </td></tr>
  4330. <tr><td><li>CamLastRec</li> </td><td>- Pfad / Name der letzten Aufnahme </td></tr>
  4331. <tr><td><li>CamLastRecTime</li> </td><td>- Datum / Startzeit - Stopzeit der letzten Aufnahme </td></tr>
  4332. <tr><td><li>CamLiveMode</li> </td><td>- Quelle für Live-Ansicht (DS, Camera) </td></tr>
  4333. <tr><td><li>CamModel</li> </td><td>- Kameramodell </td></tr>
  4334. <tr><td><li>CamMotDetSc</li> </td><td>- Status der Bewegungserkennung (disabled, durch Kamera, durch SVS) und deren Parameter </td></tr>
  4335. <tr><td><li>CamPort</li> </td><td>- IP-Port der Kamera </td></tr>
  4336. <tr><td><li>CamPreRecTime</li> </td><td>- Dauer der der Voraufzeichnung in Sekunden (Einstellung in SVS) </td></tr>
  4337. <tr><td><li>CamRecShare</li> </td><td>- gemeinsamer Ordner auf der DS für Aufnahmen </td></tr>
  4338. <tr><td><li>CamRecVolume</li> </td><td>- Volume auf der DS für Aufnahmen </td></tr>
  4339. <tr><td><li>CamVendor</li> </td><td>- Kamerahersteller Bezeichnung </td></tr>
  4340. <tr><td><li>CamVideoFlip</li> </td><td>- Ist das Video gedreht </td></tr>
  4341. <tr><td><li>CamVideoMirror</li> </td><td>- Ist das Video gespiegelt </td></tr>
  4342. <tr><td><li>CapAudioOut</li> </td><td>- Fähigkeit der Kamera zur Audioausgabe über Surveillance Station (false/true) </td></tr>
  4343. <tr><td><li>CapChangeSpeed</li> </td><td>- Fähigkeit der Kamera verschiedene Bewegungsgeschwindigkeiten auszuführen </td></tr>
  4344. <tr><td><li>CapPTZAbs</li> </td><td>- Fähigkeit der Kamera für absolute PTZ-Aktionen </td></tr>
  4345. <tr><td><li>CapPTZAutoFocus</li> </td><td>- Fähigkeit der Kamera für Autofokus Aktionen </td></tr>
  4346. <tr><td><li>CapPTZDirections</li> </td><td>- die verfügbaren PTZ-Richtungen der Kamera </td></tr>
  4347. <tr><td><li>CapPTZFocus</li> </td><td>- Art der Kameraunterstützung für Fokussierung </td></tr>
  4348. <tr><td><li>CapPTZHome</li> </td><td>- Unterstützung der Kamera für Home-Position </td></tr>
  4349. <tr><td><li>CapPTZIris</li> </td><td>- Unterstützung der Kamera für Iris-Aktion </td></tr>
  4350. <tr><td><li>CapPTZPan</li> </td><td>- Unterstützung der Kamera für Pan-Aktion </td></tr>
  4351. <tr><td><li>CapPTZTilt</li> </td><td>- Unterstützung der Kamera für Tilt-Aktion </td></tr>
  4352. <tr><td><li>CapPTZZoom</li> </td><td>- Unterstützung der Kamera für Zoom-Aktion </td></tr>
  4353. <tr><td><li>DeviceType</li> </td><td>- Kameratyp (Camera, Video_Server, PTZ, Fisheye) </td></tr>
  4354. <tr><td><li>Error</li> </td><td>- Meldungstext des letzten Fehlers </td></tr>
  4355. <tr><td><li>Errorcode</li> </td><td>- Fehlercode des letzten Fehlers </td></tr>
  4356. <tr><td><li>LastSnapFilename</li> </td><td>- der Filename des letzten Schnapschusses </td></tr>
  4357. <tr><td><li>LastSnapId</li> </td><td>- die ID des letzten Schnapschusses </td></tr>
  4358. <tr><td><li>LastUpdateTime</li> </td><td>- Datum / Zeit der letzten Aktualisierung durch "caminfoall" </td></tr>
  4359. <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>
  4360. <tr><td><li>Patrols</li> </td><td>- in Surveillance Station voreingestellte Überwachungstouren (bei PTZ-Kameras) </td></tr>
  4361. <tr><td><li>PollState</li> </td><td>- zeigt den Status des automatischen Pollings an </td></tr>
  4362. <tr><td><li>Presets</li> </td><td>- in Surveillance Station voreingestellte Positionen (bei PTZ-Kameras) </td></tr>
  4363. <tr><td><li>Record</li> </td><td>- Aufnahme läuft = Start, keine Aufnahme = Stop </td></tr>
  4364. <tr><td><li>StmKey</li> </td><td>- aktueller StreamKey. Kann zum öffnen eines Livestreams ohne Session Id genutzt werden. </td></tr>
  4365. <tr><td><li>StmKeyUnicst</li> </td><td>- Uni-cast Stream Pfad der Kamera. (<a href="#SSCamattr">Attribut</a> "showStmInfoFull" muss gesetzt sein) </td></tr>
  4366. <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>
  4367. <tr><td><li>SVScustomPortHttp</li> </td><td>- benutzerdefinierter Port der Surveillance Station (HTTP) im DSM-Anwendungsportal (get mit "svsinfo") </td></tr>
  4368. <tr><td><li>SVScustomPortHttps</li> </td><td>- benutzerdefinierter Port der Surveillance Station (HTTPS) im DSM-Anwendungsportal (get mit "svsinfo") </td></tr>
  4369. <tr><td><li>SVSlicenseNumber</li> </td><td>- die Anzahl der installierten Kameralizenzen (get mit "svsinfo") </td></tr>
  4370. <tr><td><li>SVSuserPriv</li> </td><td>- die effektiven Rechte des verwendeten Users nach dem Login (get mit "svsinfo") </td></tr>
  4371. <tr><td><li>SVSversion</li> </td><td>- die Paketversion der installierten Surveillance Station (get mit "svsinfo") </td></tr>
  4372. <tr><td><li>UsedSpaceMB</li> </td><td>- durch Aufnahmen der Kamera belegter Plattenplatz auf dem Volume </td></tr>
  4373. <tr><td><li>VideoFolder</li> </td><td>- Pfad zu den aufgenommenen Videos </td></tr>
  4374. </table>
  4375. </ul>
  4376. <br><br>
  4377. </ul>
  4378. <a name="SSCamattr"></a>
  4379. <b>Attribute</b>
  4380. <br><br>
  4381. <ul>
  4382. <ul>
  4383. <li><b>debugactivetoken</b> - wenn gesetzt wird der Status des Active-Tokens gelogged - nur für Debugging, nicht im normalen Betrieb benutzen ! </li>
  4384. <li><b>disable</b> - deaktiviert das Gerätemodul bzw. die Gerätedefinition </li>
  4385. <li><b>httptimeout</b> - Timeout-Wert für HTTP-Aufrufe zur Synology Surveillance Station, Default: 4 Sekunden (wenn httptimeout = "0" oder nicht gesetzt) </li>
  4386. <li><b>htmlattr</b> - ergänzende Angaben zur Livestream-Url um das Verhalten wie Bildgröße zu beeinflussen </li>
  4387. <li><b>livestreamprefix</b> - überschreibt die Angaben zu Protokoll, Servernamen und Port zur Weiterverwendung der Livestreamadresse als z.B. externer Link. Anzugeben in der Form "http(s)://&lt;servername&gt;:&lt;port&gt;" </li>
  4388. <li><b>noQuotesForSID</b> - dieses Attribut kann in bestimmten Fällen die Fehlermeldung "402 - permission denied" vermeiden und ein login ermöglichen. </li>
  4389. <li><b>pollcaminfoall</b> - Intervall der automatischen Eigenschaftsabfrage (Polling) einer Kamera (kleiner 10: kein Polling, größer 10: Polling mit Intervall) </li>
  4390. <li><b>pollnologging</b> - "0" bzw. nicht gesetzt = Logging Gerätepolling aktiv (default), "1" = Logging Gerätepolling inaktiv </li>
  4391. <li><b>rectime</b> - festgelegte Aufnahmezeit wenn eine Aufnahme gestartet wird. Mit rectime = 0 wird eine Endlosaufnahme gestartet. Ist "rectime" nicht gesetzt, wird der Defaultwert von 15s verwendet.</li>
  4392. <li><b>recextend</b> - "rectime" einer gestarteten Aufnahme wird neu gesetzt. Dadurch verlängert sich die Aufnahemzeit einer laufenden Aufnahme </li>
  4393. <li><b>session</b> - Auswahl der Login-Session. Nicht gesetzt oder "DSM" -> session wird mit DSM aufgebaut (Standard). "SurveillanceStation" -> Session-Aufbau erfolgt mit SVS </li>
  4394. <li><b>simu_SVSversion</b> - simuliert eine andere SVS-Version. (es ist nur eine niedrigere als die installierte SVS Version möglich !) </li>
  4395. <li><b>showStmInfoFull</b> - zusaätzliche Streaminformationen wie LiveStreamUrl, StmKeyUnicst, StmKeymjpegHttp werden ausgegeben</li>
  4396. <li><b>showPassInLog</b> - wenn gesetzt wird das verwendete Passwort im Logfile (verbose 4) angezeigt. (default = 0) </li>
  4397. <li><b>videofolderMap</b> - ersetzt den Inhalt des Readings "VideoFolder", Verwendung z.B. bei gemounteten Verzeichnissen </li>
  4398. <li><b>verbose</b> </li><br>
  4399. <ul>
  4400. Es werden verschiedene Verbose-Level unterstützt.
  4401. Dies sind im Einzelnen:
  4402. <table>
  4403. <colgroup> <col width=5%> <col width=95%> </colgroup>
  4404. <tr><td> 0 </td><td>- Start/Stop-Ereignisse werden geloggt </td></tr>
  4405. <tr><td> 1 </td><td>- Fehlermeldungen werden geloggt </td></tr>
  4406. <tr><td> 2 </td><td>- Meldungen über wichtige Ereignisse oder Alarme </td></tr>
  4407. <tr><td> 3 </td><td>- gesendete Kommandos werden geloggt </td></tr>
  4408. <tr><td> 4 </td><td>- gesendete und empfangene Daten werden geloggt </td></tr>
  4409. <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>
  4410. </table>
  4411. </ul>
  4412. <br><br>
  4413. <b>weitere Attribute:</b><br><br>
  4414. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  4415. </ul>
  4416. </ul>
  4417. <br><br>
  4418. </ul>
  4419. =end html_DE
  4420. =cut