70_WINCONNECT.pm 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. # $Id: 70_WINCONNECT.pm 16397 2018-03-13 08:15:58Z michael.winkler $
  2. ############################################################################
  3. # 2018-03-13, v0.0.28
  4. #
  5. # v0.0.28
  6. # - BUFIX: [FEHMModul] - "printer_names"="no_printing"
  7. #
  8. # v0.0.27
  9. # - BUFIX: [WinWebGUI] - Crash nach ca. 40-60 Sekunden
  10. # - CHANGE [FEHMModul] - get www_files und www_files_reset
  11. #
  12. # v0.0.26
  13. # - BUFIX: [WinWebGUI] - Installation Windows Service
  14. #
  15. # v0.0.25
  16. # - FEATURE: [WinWebGUI] - Starten als Windows Dienst
  17. # [WinWebGUI] - Kamera Vollbild Beenden Button
  18. # [WinWebGUI] - TTSMSG - Auswahl Windows integrierte Sprachen
  19. # [WinWebGUI] - TTSMSG - Google TTS
  20. # [WinWebGUI] - TTSMSG - Amazon Polly TTS (3 Sprachen)
  21. # [WinWebGUI] - SetFocusToApp
  22. # [WinWebGUI] - sendKey https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731.aspx
  23. # - CHANGE [WinWebGUI] - Logdatei wird in %TEMP% angelegt
  24. # [WinWebGUI] - Deletereading drive_X_* wenn Laufwerk entfernt wurde z.B. USB-Stick
  25. # - BUFIX: [FEHMModul] - Umlaute bei Messagebox und NotifyIcon
  26. # [FEHMModul] - Leerzeichen Support bei CheckProcess
  27. # [WinWebGUI] - Audio/Mikrofon Device
  28. # [WinWebGUI] - Software Kamera
  29. #
  30. # v0.0.23
  31. # - BUFIX: [FEHMModul] - Download gitlab GUI
  32. # - CHANGE [FEHMModul] - Download Timeout WinControl.exe = 30
  33. # - FEATURE: [WinWebGUI] - NotifyIcon - Kontextmenü
  34. #
  35. # v0.0.22
  36. # - BUFIX: [FEHMModul] - Überreste Attribut "http-noshutdown" entfernt
  37. # - FEATURE: [FEHMModul] - Attribut "autoupdatewincontrol:0,1" Standard = 1 / 0 = Hier kann das automatische GUI Update deaktiviert werden.
  38. # - CHANGE [WinWebGUI] - Autoupdate über Attribut steuerbar
  39. #
  40. # v0.0.21
  41. # - BUFIX: [WinWebGUI] - FHEM Server Connect / Reconnect
  42. # [WinWebGUI] - shutdown / standby / hibernate
  43. # [WinWebGUI] - accept trusted SSL certificat
  44. # [WinWebGUI] - battery_ChargeStatus 0 ersetzt in Middle
  45. # - CHANGE [WinWebGUI] - Autoupdate immer angeschalten
  46. # [WinWebGUI] - select SSL protocols ssl3, tls, tlsv11, tlsv12
  47. # - FEATURE: [WinWebGUI] - Icon FHEM Connect = blau
  48. # Icon FHEM Disconnect = rot
  49. # Icon FHEM Wrong Device = gelb
  50. # [WinWebGUI] - FQDN oder Netbios Name as FHEM Server
  51. # [WinWebGUI] - Support button / collect support informations
  52. # [WinWebGUI] - WMI Abfragen / WMI Wizard
  53. # [WinWebGUI] - Support Core Temp
  54. #
  55. # v0.0.20
  56. # - BUFIX: [FEHMModul] - $_ ersetzt durch $uResult
  57. # [FEHMModul] - reading "memory_available" und "memory_total" ohne Zusatz MB
  58. # [WinWebGUI] - Exit Messagebox entfernt
  59. # - FEATURE: [WinWebGUI] - Exit Menübutton
  60. #
  61. # v0.0.18
  62. # - BUFIX: [WinWebGUI] - Autoupdate
  63. # [WinWebGUI] - Shutdown Messagebox
  64. #
  65. # v0.0.17
  66. # - BUFIX: [FEHMModul] - Code Optimierungen
  67. # - CHANGE [WinWebGUI] - FHEM Devicename check auf Gültigkeit https://forum.fhem.de/index.php/topic,59251.msg667257.html#msg667257
  68. # - FEATURE: [WinWebGUI] - Fenster verstecken https://forum.fhem.de/index.php/topic,59251.msg665863.html#msg665863
  69. #
  70. # v0.0.16 erste SVN Version
  71. # - BUFIX: Refresh CSRFTOKEN nach einem reconnect
  72. # Readings zurücksetzen wenn Offline
  73. # os_RunTime_days,os_RunTime_hours und os_RunTime_minutes
  74. # printer_aktiv und printer_names
  75. # div. Optimierungen
  76. # - FEATURE Attribut "win_resetreadings:0,1" Standard = 1 / 1 = Readings zurücksetzen wenn Offline
  77. # Attribut "autoupdategitlab:0,1" Standard = 1 / 0 = Hier kann der automatische Download deaktiviert werden.
  78. # - CHANGE Attribut "http-noshutdown" Auf Standwardwert "0" gesetzt
  79. #
  80. # v0.0.15
  81. # - BUFIX: Start optimiert / Log sortiert
  82. #
  83. # v0.0.14
  84. # - FEATURE: Winconnect mit Windows starten
  85. # Ausführen (minimiert/normales Fenster)
  86. # checkprocess (prüft ob ein Prozess gestartet ist inkl. Anzahl)
  87. # wincontrol.exe.config wird nicht mehr benötigt
  88. # Windows Version (os_Version & os_ReleaseID ab Win10)
  89. # Benutzer / Hostname (os_Username, os_Computername & os_Domainname)
  90. # Performance: CPU, Festplatte, Netzwerk, RAM, …
  91. # Hardware Ausrüstung: Prozessor, BIOS & RAM (memory_*, bios_* und cpu_*)
  92. # VolumeDown, VolumeUp (mit attr volumeStep)
  93. # Laufzeiten in Tage/Stunden/Minuten (os_RunTime_minutes, os_RunTime_hours und os_RunTime_days)
  94. # - BUFIX: checkservice (im FHEM Reading wurde immer nur der erste Service eingetragen)
  95. #
  96. # v0.0.13
  97. # - FEATURE: Performance Optimierungen
  98. # set powermode add(standby/hibernate)
  99. # drive informations (Space in MB/change only > 10MB)
  100. # - BUFIX: div.
  101. # Programmabsturtz nach ca. 4-5 Tagen
  102. #
  103. # v0.0.12
  104. # - FEATURE: CSRFToken
  105. # - BUFIX: Detect Audio Sound
  106. #
  107. # v0.0.11
  108. # - FEATURE: ttsmsg play sound
  109. # messagebox play sound
  110. # set camera (on/off)
  111. # make picture (camera)
  112. # motion detect (camera)
  113. # Update Winconnect.exe (inkl. autoupdate)
  114. # microphone sound detection
  115. # Startscreen
  116. # - BUFIX: .NET Fehlermeldung
  117. # set screen on
  118. # set screen off
  119. # - Readings: audio_devicename
  120. # microphone_devicename
  121. #
  122. # v0.0.10
  123. # - FEATURE: send notifymsg (set notifymsg Ballon Tip)
  124. # send messagebox (set messagebox)
  125. # Verzeichnis überwachen
  126. # set powermode (shutdown/restart)
  127. #
  128. # v0.0.9
  129. # - FEATURE: FHEM SSL
  130. #
  131. # v0.0.8
  132. # - FEATURE: FHEM Anmeldung (basicAuth)
  133. # volume mute (on/off)
  134. # - BUGFIX: statusrequest (firststart)
  135. # - Readings: speecherrormessage
  136. # speecherrormessagequality
  137. # speechmessagequality
  138. # mute
  139. #
  140. # v0.0.7 - 20161107
  141. # - BUGFIX: Umlaute beim senden einer ttsmsg
  142. # - FEATURE: set commandhide
  143. # set user_aktividletime
  144. # printer_aktiv
  145. # Spracherkennung
  146. #
  147. # v0.0.6 - 20161025
  148. # - BUFIX: no audiodevice
  149. # - FEATURE: set brightness 0 - 100
  150. #
  151. # v0.0.5 - 20161024
  152. # - BUGFIX
  153. #
  154. # v0.0.4 - 20161024
  155. # - BUGFIX: (Bereinigung wincontrol / FHEM readings)
  156. # - FEATURE: send ttsmsg (TextToSpeech)
  157. # - Readings: os_StartTime = Startzeit Windows
  158. # wincontrol_starttime = Startzeit WinControl
  159. # wincontrol_user = Benutzer der Wintrol gestartet hat
  160. # battery_ChargeStatus
  161. # battery_LifePercent
  162. # battery_LifeRemainingsMin
  163. # battery_PowerLineStatus
  164. #
  165. # v0.0.3 - 20161020
  166. # - FEATURE: set command
  167. # set showfile
  168. # set checkservice
  169. #
  170. # v0.0.0 - 20161018
  171. # - FEATURE: ON/OFF Windows Screen
  172. # set volume
  173. # detect playing audio
  174. #
  175. # Copyright by Michael Winkler
  176. # e-mail: michael.winkler at online.de
  177. #
  178. # This file is part of fhem.
  179. #
  180. # Fhem is free software: you can redistribute it andor modify
  181. # it under the terms of the GNU General Public License as published by
  182. # the Free Software Foundation, either version 2 of the License, or
  183. # (at your option) any later version.
  184. #
  185. # Fhem is distributed in the hope that it will be useful,
  186. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  187. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  188. # GNU General Public License for more details.
  189. #
  190. # You should have received a copy of the GNU General Public License
  191. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  192. #
  193. ##############################################################################
  194. package main;
  195. use strict;
  196. use warnings;
  197. use HttpUtils;
  198. use Time::Piece;
  199. sub WINCONNECT_Set($@);
  200. sub WINCONNECT_Get($@);
  201. sub WINCONNECT_GetStatus($;$);
  202. sub WINCONNECT_Define($$);
  203. sub WINCONNECT_Undefine($$);
  204. # Autoupdateinformationen
  205. my $DownloadGURL = "https://gitlab.com/michael.winkler/winconnect/raw/master/WinControl_0.0.27.exe";
  206. my $DownloadSURL = "https://gitlab.com/michael.winkler/winconnect/raw/master/WinControlService_0.0.27.exe";
  207. my $DownloadVer = "0.0.27";
  208. my $DownloadError = "";
  209. ###################################
  210. sub WINCONNECT_Initialize($) {
  211. my ($hash) = @_;
  212. Log3 $hash, 5, "WINCONNECT_Initialize: Entering";
  213. $hash->{SetFn} = "WINCONNECT_Set";
  214. $hash->{GetFn} = "WINCONNECT_Get";
  215. $hash->{DefFn} = "WINCONNECT_Define";
  216. $hash->{UndefFn} = "WINCONNECT_Undefine";
  217. $hash->{AttrList} = "volumeStep win_resetreadings:0,1 disable:0,1 autoupdategitlab:0,1 autoupdatewincontrol:0,1 " . $readingFnAttributes;
  218. return;
  219. }
  220. #####################################
  221. # Get Status
  222. #####################################
  223. sub WINCONNECT_GetStatus($;$) {
  224. my ($hash, $update ) = @_;
  225. my $name = $hash->{NAME};
  226. my $interval = $hash->{INTERVAL};
  227. my $filemtime = "-";
  228. if ($DownloadError eq "") {$DownloadError = ReadingsVal( $name, "wincontrol_error", "Start WinControl....." );}
  229. return if ( AttrVal( $name, "disable", 0 ) == 1 );
  230. InternalTimer( gettimeofday() + $interval, "WINCONNECT_GetStatus", $hash, 0 );
  231. my $filename = '././www/winconnect/WinControl.exe';
  232. my $filenameSR = '././www/winconnect/WinControlService.exe';
  233. my $filedir = '././www/winconnect';
  234. if ((-e $filename)) {$filemtime = (stat $filename)[9];}
  235. Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_GetStatus()";
  236. Log3 $name, 5, "WINCONNECT $name: filename = " . $filename . " filemtime = " . $filemtime;
  237. #Alte Readings bereinigen
  238. print (fhem( "deletereading $name wincontrol_gitlap" )) if ( ReadingsVal( $name, "wincontrol_gitlap", "0" ) ne "0" ) ;
  239. print (fhem( "deletereading $name wincontrol_gitlap_url" )) if ( ReadingsVal( $name, "wincontrol_gitlap_url", "0" ) ne "0" ) ;
  240. if ( !$update ) {
  241. WINCONNECT_SendCommand( $hash, "powerstate" );
  242. }
  243. else {
  244. WINCONNECT_SendCommand( $hash, "statusrequest" );
  245. }
  246. if (ReadingsVal( $name, "wincontrol_type", ".." ) eq "GUI with own device") {
  247. print (fhem( "deletereading $name wincontrol_update" )) if ( ReadingsVal( $name, "wincontrol_update", "0" ) ne "0" ) ;
  248. print (fhem( "deletereading $name wincontrol_gitlab_url" )) if ( ReadingsVal( $name, "wincontrol_gitlab_url", "0" ) ne "0" ) ;
  249. print (fhem( "deletereading $name wincontrol_gitlab" )) if ( ReadingsVal( $name, "wincontrol_gitlab", "0" ) ne "0" ) ;
  250. print (fhem( "deletereading $name wincontrol_error" )) if ( ReadingsVal( $name, "wincontrol_error", "0" ) ne "0" ) ;
  251. return;
  252. }
  253. readingsBeginUpdate($hash);
  254. #WinControl Versionsinformationen
  255. readingsBulkUpdateIfChanged( $hash, "wincontrol_gitlab", $DownloadVer );
  256. readingsBulkUpdateIfChanged( $hash, "wincontrol_gitlab_url", $DownloadGURL);
  257. readingsBulkUpdateIfChanged( $hash, "wincontrol_gitlab_serviceurl", $DownloadSURL);
  258. #WinControl Update Info eintragen
  259. if ($filemtime eq "-") {$filemtime = 0;}
  260. readingsBulkUpdateIfChanged( $hash, "wincontrol_update", $filemtime );
  261. if (ReadingsVal( $name, "os_Name", "unbekannt" ) ne "unbekannt") {readingsBulkUpdateIfChanged( $hash, "model", ReadingsVal( $name, "os_Name", "unbekannt" ));}
  262. #WinControl Last Error
  263. readingsBulkUpdateIfChanged( $hash, "wincontrol_error", $DownloadError);
  264. readingsEndUpdate( $hash, 1 );
  265. #Autoupdatefile von Gitlab herunterladen
  266. if ($DownloadGURL ne '' && !(-e $filename . "_" .$DownloadVer) && AttrVal( $name, "autoupdategitlab", "1" ) ) {
  267. #Verzeichnis anlegen
  268. mkdir($filedir, 0777) unless(-d $filedir );
  269. if(!open (FILE, ">". $filename . "_" .$DownloadVer)) {
  270. $DownloadError = "WINCONNECT [NEW] Download ERROR Can't write = " .$filename . "_" .$DownloadVer . " Error=" .$!;
  271. Log3 $name, 5, $DownloadError;
  272. }else {
  273. print FILE $name;
  274. close (FILE);
  275. #Delete old version
  276. if ((-e $filename)) {unlink $filename}
  277. if ((-e $filenameSR)) {unlink $filenameSR}
  278. HttpUtils_NonblockingGet({url=>$DownloadGURL, timeout=>30, hash=>$hash, service=>"autoupdate", callback=>\&WINCONNECT_GetNewGUIVersion});
  279. HttpUtils_NonblockingGet({url=>$DownloadSURL, timeout=>30, hash=>$hash, service=>"autoupdate", callback=>\&WINCONNECT_GetNewServiceVersion});
  280. }
  281. }
  282. return;
  283. }
  284. sub WINCONNECT_GetNewGUIVersion($$$) {
  285. my ($hash, $err, $data) = @_;
  286. my $filename = '././www/winconnect/WinControl.exe';
  287. my $name = $hash->{NAME};
  288. my $CheckFile = $filename . "_" .$DownloadVer;
  289. # Download neue Datei
  290. if(!open(FH, ">$filename")) {
  291. $DownloadError = "Download ERROR Can't write = " .$filename . " Error=" .$!;
  292. Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
  293. #Delete Version Flag
  294. if ((-e $CheckFile)) {unlink $CheckFile}
  295. }else{
  296. print FH $data;
  297. close(FH);
  298. my $filesize = -s $filename;
  299. # Prüfen ob die Dateigröße passt!
  300. if ($filesize < 600000) {
  301. $DownloadError = "Download ERROR file to small. Filesize = " . $filesize;
  302. Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
  303. #Download fehlgeschlagen! / Flag wieder löschen
  304. if ((-e $CheckFile)) {unlink $CheckFile}
  305. }else{
  306. Log3 $name, 0, "WINCONNECT [NEW] Download new version URL = $DownloadGURL";
  307. Log3 $name, 0, "WINCONNECT [NEW] Download new version OK";
  308. $DownloadError = "Download new version = $DownloadVer";
  309. }
  310. }
  311. }
  312. sub WINCONNECT_GetNewServiceVersion($$$) {
  313. my ($hash, $err, $data) = @_;
  314. my $filename = '././www/winconnect/WinControlService.exe';
  315. my $name = $hash->{NAME};
  316. my $CheckFile = $filename . "_" .$DownloadVer;
  317. # Download neue Datei
  318. if(!open(FH, ">$filename")) {
  319. $DownloadError = "Download ERROR Can't write = " .$filename . " Error=" .$!;
  320. Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
  321. #Delete Version Flag
  322. if ((-e $CheckFile)) {unlink $CheckFile}
  323. }else{
  324. print FH $data;
  325. close(FH);
  326. my $filesize = -s $filename;
  327. # Prüfen ob die Dateigröße passt!
  328. if ($filesize < 50000) {
  329. $DownloadError = "Download ERROR file to small. Filesize = " . $filesize;
  330. Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
  331. #Download fehlgeschlagen! / Flag wieder löschen
  332. if ((-e $CheckFile)) {unlink $CheckFile}
  333. }else{
  334. Log3 $name, 0, "WINCONNECT [NEW] Download new version URL = $DownloadSURL";
  335. Log3 $name, 0, "WINCONNECT [NEW] Download new version OK";
  336. $DownloadError = "Download new version = $DownloadVer";
  337. }
  338. }
  339. }
  340. ###################################
  341. sub WINCONNECT_SendCommand($$;$$) {
  342. my ( $hash, $service, $cmd ) = @_;
  343. my $name = $hash->{NAME};
  344. my $address = $hash->{helper}{ADDRESS};
  345. my $serviceurl = "";
  346. my $PWRState = ReadingsVal( $name, "state", "" );
  347. my $Winconnect = ReadingsVal( $name, "wincontrol", "statusrequest" );
  348. my $WinconnectUPD = ReadingsVal( $name, "wincontrol_update", "0" );
  349. my $GUIPort = ReadingsVal( $name, "wincontrol_user_port", "8183" );
  350. my $URL;
  351. Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_SendCommand()";
  352. # Check Service and change serviceurl
  353. if ($service eq "statusrequest") {
  354. $serviceurl = "statusrequest";
  355. }
  356. elsif ($service eq "volume") {
  357. $serviceurl = "volume";
  358. }
  359. elsif ($service eq "file_dir") {
  360. $serviceurl = "file_dir";
  361. }
  362. elsif ($service eq "picture_dir") {
  363. $serviceurl = "picture_dir";
  364. }
  365. elsif ($service eq "camera") {
  366. $serviceurl = "camera";
  367. }
  368. elsif ($service eq "file_order") {
  369. $serviceurl = "file_order";
  370. }
  371. elsif ($service eq "file_filter") {
  372. $serviceurl = "file_filter";
  373. }
  374. elsif ($service eq "mute") {
  375. $serviceurl = "volumemute";
  376. }
  377. elsif ($service eq "speechcommands") {
  378. $serviceurl = "speechcommands";
  379. }
  380. elsif ($service eq "speechquality") {
  381. $serviceurl = "speechquality";
  382. }
  383. elsif ($service eq "brightness") {
  384. $serviceurl = "brightness";
  385. }
  386. elsif ($service eq "user_aktividletime") {
  387. $serviceurl = "user_aktividletime";
  388. }
  389. elsif ($service eq "powerstate") {
  390. if ( AttrVal( $name, "autoupdatewincontrol", 1 ) == 1 ) {$serviceurl = "powerstate" . "=" . $PWRState . ";" . $Winconnect . ";" . $WinconnectUPD;}
  391. else {$serviceurl = "powerstate" . "=" . $PWRState . ";" . $Winconnect . ";0";}
  392. }
  393. elsif ($service eq "command") {
  394. $serviceurl = "command";
  395. }
  396. elsif ($service eq "commandhide") {
  397. $serviceurl = "commandhide";
  398. }
  399. elsif ($service eq "update") {
  400. $serviceurl = "update";
  401. }
  402. elsif ($service eq "checkservice") {
  403. $serviceurl = "checkservice";
  404. }
  405. elsif ($service eq "checkperformance") {
  406. $serviceurl = "checkperformance";
  407. }
  408. elsif ($service eq "checkperformance_interval") {
  409. $serviceurl = "checkperformance_interval";
  410. }
  411. elsif ($service eq "checkprocess") {
  412. $serviceurl = "checkprocess";
  413. }
  414. elsif ($service eq "checkprocess_type") {
  415. $serviceurl = "serviceconfigwrite";
  416. }
  417. elsif ($service eq "showfile") {
  418. $serviceurl = "showfile";
  419. }
  420. elsif ($service eq "setfocustoapp") {
  421. $serviceurl = "setfocustoapp";
  422. }
  423. elsif ($service eq "ttsmsg") {
  424. $serviceurl = "ttsmsg";
  425. }
  426. elsif ($service eq "powermode") {
  427. $serviceurl = "powermode";
  428. }
  429. elsif ($service eq "messagebox") {
  430. $serviceurl = "messagebox";
  431. }
  432. elsif ($service eq "notifymsg") {
  433. $serviceurl = "notifymsg";
  434. }
  435. elsif ($service eq "screenon") {
  436. $serviceurl = "screen=on";
  437. }
  438. elsif ($service eq "picture_make") {
  439. $serviceurl = "picture_make";
  440. }
  441. elsif ($service eq "screenoff") {
  442. $serviceurl = "screen=off";
  443. }
  444. elsif ($service eq "sendkey") {
  445. $serviceurl = "sendkey";
  446. }
  447. else{
  448. $serviceurl = $service;
  449. }
  450. # URL zusammenbauen
  451. $cmd = ( defined($cmd) ) ? $cmd : "";
  452. $URL = "http://" . $address . ":" . $GUIPort . "/fhem/" . $serviceurl . $cmd ;
  453. $URL =~ tr/\r\n/|/;
  454. Log3 $name, 5, "WINCONNECT $name: GET " . urlDecode($URL);
  455. HttpUtils_NonblockingGet(
  456. {
  457. url => $URL,
  458. timeout => 10,
  459. noshutdown => 0,
  460. #data => undef, 2017.07.20 - enfernt
  461. hash => $hash,
  462. service => $service,
  463. cmd => $cmd,
  464. #type => $type, 2017.07.20 - enfernt
  465. callback => \&WINCONNECT_ReceiveCommand
  466. }
  467. );
  468. return;
  469. }
  470. ###################################
  471. sub WINCONNECT_Set($@) {
  472. my ( $hash, @a ) = @_;
  473. my $name = $hash->{NAME};
  474. my $state = ReadingsVal( $name, "state", "absent" );
  475. my $cmd = "";
  476. my $Value = "";
  477. my $Count = 0;
  478. my $SetValue = 0;
  479. my $GUIType = ReadingsVal( $name, "wincontrol_type", "GUI without service" );
  480. my $usage = "";
  481. Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Set()";
  482. # Set´s anzeigen je nach WinControl Typ!
  483. if ($GUIType eq "GUI with own device") {
  484. # GUI mit eigenem Device und einem Windows Service
  485. $usage = "choose one of camera:on,off picture_make:noArg speechquality:slider,0,1,100 statusRequest:noArg screenOn:noArg screenOff:noArg command commandhide sendkey showfile picture_dir checkprocess notifymsg messagebox file_dir file_filter file_order:ascending,descending ttsmsg user_aktividletime speechcommands setfocustoapp ";
  486. }
  487. elsif($GUIType eq "GUI without service") {
  488. # Standard GUI ohne einen Service
  489. $usage = "choose one of brightness:slider,0,1,100 camera:on,off checkperformance:textField-long checkperformance_interval checkprocess checkservice command commandhide file_dir file_filter file_order:ascending,descending messagebox mute:on,off notifymsg picture_dir picture_make:noArg powermode:shutdown,restart,standby,hibernate screenOn:noArg screenOff:noArg sendkey setfocustoapp showfile speechcommands speechquality:slider,0,1,100 statusRequest:noArg ttsmsg update:noArg user_aktividletime volume:slider,0,1,100 volumeDown:noArg volumeUp:noArg ";
  490. }
  491. else {
  492. # Windows Service betrieb / GUI ohne eigenes Device aber mit einem Windows Service
  493. $usage = "choose one of brightness:slider,0,1,100 camera:on,off checkperformance:textField-long checkperformance_interval checkprocess checkprocess_type:service,gui checkservice command commandhide command_type:service,gui file_dir file_filter file_order:ascending,descending file_type:service,gui messagebox mute:on,off notifymsg picture_dir picture_make:noArg powermode:shutdown,restart,standby,hibernate screenOn:noArg screenOff:noArg sendkey setfocustoapp showfile speechcommands speechquality:slider,0,1,100 statusRequest:noArg ttsmsg update:noArg user_aktividletime volume:slider,0,1,100 volumeDown:noArg volumeUp:noArg ";
  494. }
  495. return "No Argument given" if ( !defined( $a[1] ) );
  496. # statusRequest
  497. if ( lc( $a[1] ) eq "statusrequest" ) {
  498. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  499. WINCONNECT_SendCommand( $hash, "statusrequest" );
  500. }
  501. # on
  502. elsif ( lc( $a[1] ) eq "on" ) {
  503. readingsSingleUpdate( $hash, "state", "on",1 );
  504. }
  505. # powerstate
  506. elsif ( lc( $a[1] ) eq "powerstate" ) {
  507. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  508. WINCONNECT_SendCommand( $hash, "powerstate" );
  509. }
  510. # update
  511. elsif ( lc( $a[1] ) eq "update" ) {
  512. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  513. WINCONNECT_SendCommand( $hash, "update" );
  514. }
  515. # off
  516. elsif ( lc( $a[1] ) eq "off" ) {
  517. readingsSingleUpdate( $hash, "state", "off",1 );
  518. }
  519. # screenOn
  520. elsif ( lc( $a[1] ) eq "screenon" ) {
  521. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  522. if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "screenon" );}else {return "Device needs to be ON to adjust screenon.";}
  523. }
  524. #screenOff
  525. elsif ( lc( $a[1] ) eq "screenoff" ) {
  526. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  527. if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "screenoff" );}else {return "Device needs to be ON to adjust screenoff.";}
  528. }
  529. # volume
  530. elsif ( lc( $a[1] ) eq "volume" ) {
  531. return "No argument given" if ( !defined( $a[2] ) );
  532. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  533. if ( $state eq "on" ) {
  534. $SetValue = $a[2];
  535. if ($SetValue >= 0 && $SetValue <= 100 ) {
  536. $cmd = $a[2];
  537. }
  538. else {
  539. return "Argument $SetValue does not seem to be a valid integer between 0 and 100";
  540. }
  541. WINCONNECT_SendCommand( $hash, "volume" , "=" . $cmd );
  542. readingsSingleUpdate( $hash, "volume", $cmd,1 );
  543. }
  544. else {return "Device needs to be ON to adjust volume.";}
  545. }
  546. # volumeUp
  547. elsif ( lc( $a[1] ) eq "volumeup" ) {
  548. my $volumeStep = int(AttrVal($name, "volumeStep", 5));
  549. my $volumenow = ReadingsVal( $name, "volume", 0);
  550. my $volumeNew = $volumenow + $volumeStep;
  551. if ($volumeNew > 100) {$volumeNew = 100;}
  552. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $volumeNew;
  553. if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "volume" , "=" . $volumeNew );readingsSingleUpdate( $hash, "volume", $volumeNew,1 );}else {return "Device needs to be ON to adjust volume.";}
  554. }
  555. # volumeDown
  556. elsif ( lc( $a[1] ) eq "volumedown" ) {
  557. my $volumeStep = int(AttrVal($name, "volumeStep", 5));
  558. my $volumenow = ReadingsVal( $name, "volume", 0);
  559. my $volumeNew = $volumenow - $volumeStep;
  560. if ($volumeNew < 0) {$volumeNew = 0;}
  561. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $volumeNew;
  562. if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "volume" , "=" . $volumeNew );readingsSingleUpdate( $hash, "volume", $volumeNew,1 );}else {return "Device needs to be ON to adjust volume.";}
  563. }
  564. # mute
  565. elsif ( lc( $a[1] ) eq "mute" ) {
  566. return "No argument given" if ( !defined( $a[2] ) );
  567. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  568. if ( $state eq "on" ) {
  569. WINCONNECT_SendCommand( $hash, "volumemute" , "=" . $a[2] );
  570. readingsSingleUpdate( $hash, "mute", $a[2],0 );
  571. }
  572. else {return "Device needs to be ON to adjust volume mute.";}
  573. }
  574. # powermode
  575. elsif ( lc( $a[1] ) eq "powermode" ) {
  576. return "No argument given" if ( !defined( $a[2] ) );
  577. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  578. if ( $state eq "on" ) {
  579. WINCONNECT_SendCommand( $hash, "powermode" , "=" . $a[2] );
  580. }
  581. else {return "Device needs to be ON to adjust powermode.";}
  582. }
  583. # user_aktividletime
  584. elsif ( lc( $a[1] ) eq "user_aktividletime" ) {
  585. return "No argument given" if ( !defined( $a[2] ) );
  586. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  587. if ( $state eq "on" ) {
  588. $SetValue = $a[2];
  589. if ($SetValue >= 0 && $SetValue <= 10000 ) {
  590. $cmd = $a[2];
  591. }
  592. else {
  593. return "Argument does not seem to be a valid integer between 0 and 10000";
  594. }
  595. WINCONNECT_SendCommand( $hash, "user_aktividletime" , "=" . $cmd );
  596. readingsSingleUpdate( $hash, "user_aktividletime", $cmd,1 );
  597. }
  598. else {return "Device needs to be ON to adjust user_aktividletime.";}
  599. }
  600. # brightness
  601. elsif ( lc( $a[1] ) eq "brightness" ) {
  602. return "No argument given" if ( !defined( $a[2] ) );
  603. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  604. if ( $state eq "on" ) {
  605. $SetValue = $a[2];
  606. if ($SetValue >= 0 && $SetValue <= 100 ) {
  607. $cmd = $a[2];
  608. }
  609. else {
  610. return "Argument does not seem to be a valid integer between 0 and 100";
  611. }
  612. WINCONNECT_SendCommand( $hash, "brightness" , "=" . $cmd );
  613. readingsSingleUpdate( $hash, "brightness", $cmd,1 );
  614. }
  615. else {return "Device needs to be ON to adjust brightness.";}
  616. }
  617. # speechquality
  618. elsif ( lc( $a[1] ) eq "speechquality" ) {
  619. return "No argument given" if ( !defined( $a[2] ) );
  620. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  621. if ( $state eq "on" ) {
  622. $SetValue = $a[2];
  623. if ($SetValue >= 0 && $SetValue <= 100 ) {
  624. $cmd = $a[2];
  625. }
  626. else {
  627. return "Argument does not seem to be a valid integer between 0 and 100";
  628. }
  629. WINCONNECT_SendCommand( $hash, "speechquality" , "=" . $cmd );
  630. readingsSingleUpdate( $hash, "speechquality", $cmd,1 );
  631. }
  632. else {return "Device needs to be ON to adjust speechquality.";}
  633. }
  634. # command
  635. elsif ( lc( $a[1] ) eq "command" ) {
  636. return "No argument given" if ( !defined( $a[2] ) );
  637. if ( $state eq "on" ) {
  638. foreach (@a) {
  639. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  640. }
  641. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  642. WINCONNECT_SendCommand( $hash, "command" , "=" . $cmd );
  643. }
  644. else {return "Device needs to be ON to execute command.";}
  645. }
  646. # commandhide
  647. elsif ( lc( $a[1] ) eq "commandhide" ) {
  648. return "No argument given" if ( !defined( $a[2] ) );
  649. if ( $state eq "on" ) {
  650. foreach (@a) {
  651. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  652. }
  653. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  654. WINCONNECT_SendCommand( $hash, "commandhide" , "=" . $cmd );
  655. }
  656. else {return "Device needs to be ON to execute commandhide.";}
  657. }
  658. # command_type
  659. elsif ( lc( $a[1] ) eq "command_type" ) {
  660. return "No argument given" if ( !defined( $a[2] ) );
  661. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  662. if ( $state eq "on" ) {
  663. readingsSingleUpdate( $hash, "command_type", $a[2],1 );
  664. WINCONNECT_SendCommand( $hash, "SERVICECONFIGWRITE" , "%20type_service_command%20" . $a[2] );
  665. }
  666. else {return "Device needs to be ON to adjust command_type.";}
  667. }
  668. # showfile
  669. elsif ( lc( $a[1] ) eq "showfile" ) {
  670. return "No argument given" if ( !defined( $a[2] ) );
  671. if ( $state eq "on" ) {
  672. foreach (@a) {
  673. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  674. }
  675. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  676. WINCONNECT_SendCommand( $hash, "showfile" , "=" . $cmd );
  677. }
  678. else {return "Device needs to be ON to showfile.";}
  679. }
  680. # sendkey
  681. elsif ( lc( $a[1] ) eq "sendkey" ) {
  682. return "No argument given" if ( !defined( $a[2] ) );
  683. if ( $state eq "on" ) {
  684. foreach (@a) {
  685. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  686. }
  687. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  688. WINCONNECT_SendCommand( $hash, "sendkey" , "=" . $cmd );
  689. }
  690. else {return "Device needs to be ON to sendkey.";}
  691. }
  692. # setfocustoapp
  693. elsif ( lc( $a[1] ) eq "setfocustoapp" ) {
  694. return "No argument given" if ( !defined( $a[2] ) );
  695. if ( $state eq "on" ) {
  696. foreach (@a) {
  697. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  698. }
  699. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  700. WINCONNECT_SendCommand( $hash, "setfocustoapp" , "=" . $cmd );
  701. }
  702. else {return "Device needs to be ON to setfocustoapp.";}
  703. }
  704. # ttsmsg
  705. elsif ( lc( $a[1] ) eq "ttsmsg" ) {
  706. return "No argument given" if ( !defined( $a[2] ) );
  707. if ( $state eq "on" ) {
  708. foreach (@a) {
  709. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  710. $Count = $Count + 1;
  711. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  712. }
  713. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  714. WINCONNECT_SendCommand( $hash, "ttsmsg" , "=" . $cmd );
  715. readingsSingleUpdate( $hash, "ttsmsg", $Value,1 );
  716. }
  717. else {return "Device needs to be ON to send ttsmsg.";}
  718. }
  719. # messagebox
  720. elsif ( lc( $a[1] ) eq "messagebox" ) {
  721. return "No argument given" if ( !defined( $a[2] ) );
  722. if ( $state eq "on" ) {
  723. foreach (@a) {
  724. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  725. $Count = $Count + 1;
  726. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  727. }
  728. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  729. WINCONNECT_SendCommand( $hash, "messagebox" , "=" . $cmd );
  730. readingsSingleUpdate( $hash, "messagebox", $Value,1 );
  731. }
  732. else {return "Device needs to be ON to send messagebox.";}
  733. }
  734. # notifymsg
  735. elsif ( lc( $a[1] ) eq "notifymsg" ) {
  736. return "No argument given" if ( !defined( $a[2] ) );
  737. if ( $state eq "on" ) {
  738. foreach (@a) {
  739. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  740. $Count = $Count + 1;
  741. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  742. }
  743. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  744. WINCONNECT_SendCommand( $hash, "notifymsg" , "=" . $cmd );
  745. readingsSingleUpdate( $hash, "notifymsg", $Value,1 );
  746. }
  747. else {return "Device needs to be ON to send notifymsg.";}
  748. }
  749. # checkservice
  750. elsif ( lc( $a[1] ) eq "checkservice" ) {
  751. if ( $state eq "on" ) {
  752. foreach (@a) {
  753. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  754. $Count = $Count + 1;
  755. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  756. }
  757. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  758. readingsSingleUpdate( $hash, "checkservice", $Value,1 );
  759. WINCONNECT_SendCommand( $hash, "checkservice" , "=" . $cmd );
  760. }
  761. else {return "Device needs to be ON to checkservice.";}
  762. }
  763. # checkperformance
  764. elsif ( lc( $a[1] ) eq "checkperformance" ) {
  765. if ( $state eq "on" ) {
  766. foreach (@a) {
  767. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  768. $Count = $Count + 1;
  769. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  770. }
  771. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  772. readingsSingleUpdate( $hash, "checkperformance", $Value,1 );
  773. WINCONNECT_SendCommand( $hash, "checkperformance" , "=" . $cmd );
  774. }
  775. else {return "Device needs to be ON to checkperformance.";}
  776. }
  777. # checkperformance_interval
  778. elsif ( lc( $a[1] ) eq "checkperformance_interval" ) {
  779. return "No argument given" if ( !defined( $a[2] ) );
  780. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  781. if ( $state eq "on" ) {
  782. $SetValue = $a[2];
  783. if ($SetValue >= 10 && $SetValue <= 10000 ) {
  784. $cmd = $a[2];
  785. }
  786. else {
  787. return "Argument does not seem to be a valid integer between 10 and 10000";
  788. }
  789. WINCONNECT_SendCommand( $hash, "checkperformance_interval" , "=" . $cmd );
  790. readingsSingleUpdate( $hash, "checkperformance_interval", $cmd,0 );
  791. }
  792. else {return "Device needs to be ON to adjust checkperformance_interval.";}
  793. }
  794. # checkprocess
  795. elsif ( lc( $a[1] ) eq "checkprocess" ) {
  796. if ( $state eq "on" ) {
  797. foreach (@a) {
  798. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  799. $Count = $Count + 1;
  800. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  801. }
  802. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  803. readingsSingleUpdate( $hash, "checkprocess", $Value,1 );
  804. WINCONNECT_SendCommand( $hash, "checkprocess" , "=" . $cmd );
  805. }
  806. else {return "Device needs to be ON to checkprocess.";}
  807. }
  808. # checkprocess_type
  809. elsif ( lc( $a[1] ) eq "checkprocess_type" ) {
  810. return "No argument given" if ( !defined( $a[2] ) );
  811. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  812. if ( $state eq "on" ) {
  813. readingsSingleUpdate( $hash, "checkprocess_type", $a[2],1 );
  814. WINCONNECT_SendCommand( $hash, "SERVICECONFIGWRITE" , "%20type_service_checkprocess%20" . $a[2] );
  815. }
  816. else {return "Device needs to be ON to adjust checkprocess_type.";}
  817. }
  818. # speechcommands
  819. elsif ( lc( $a[1] ) eq "speechcommands" ) {
  820. if ( $state eq "on" ) {
  821. foreach (@a) {
  822. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  823. $Count = $Count + 1;
  824. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  825. }
  826. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  827. WINCONNECT_SendCommand( $hash, "speechcommands" , "=" . $cmd );
  828. readingsSingleUpdate( $hash, "speechcommands", $Value,1 );
  829. }
  830. else {return "Device needs to be ON to speechcommands.";}
  831. }
  832. # file_dir
  833. elsif ( lc( $a[1] ) eq "file_dir" ) {
  834. if ( $state eq "on" ) {
  835. foreach (@a) {
  836. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  837. $Count = $Count + 1;
  838. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  839. }
  840. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  841. WINCONNECT_SendCommand( $hash, "file_dir" , "=" . $cmd );
  842. readingsSingleUpdate( $hash, "file_dir", $Value,1 );
  843. }
  844. else {return "Device needs to be ON to file_dir.";}
  845. }
  846. # file_filter
  847. elsif ( lc( $a[1] ) eq "file_filter" ) {
  848. if ( $state eq "on" ) {
  849. foreach (@a) {
  850. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  851. $Count = $Count + 1;
  852. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  853. }
  854. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  855. WINCONNECT_SendCommand( $hash, "file_filter" , "=" . $cmd );
  856. readingsSingleUpdate( $hash, "file_filter", $Value,0 );
  857. }
  858. else {return "Device needs to be ON to file_filter.";}
  859. }
  860. # file_order
  861. elsif ( lc( $a[1] ) eq "file_order" ) {
  862. return "No argument given" if ( !defined( $a[2] ) );
  863. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  864. if ( $state eq "on" ) {
  865. WINCONNECT_SendCommand( $hash, "file_order" , "=" . $a[2] );
  866. readingsSingleUpdate( $hash, "file_order", $a[2],1 );
  867. }
  868. else {return "Device needs to be ON to adjust file_order.";}
  869. }
  870. # file_type
  871. elsif ( lc( $a[1] ) eq "file_type" ) {
  872. return "No argument given" if ( !defined( $a[2] ) );
  873. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  874. if ( $state eq "on" ) {
  875. readingsSingleUpdate( $hash, "file_type", $a[2],1 );
  876. WINCONNECT_SendCommand( $hash, "SERVICECONFIGWRITE" , "%20type_service_file%20" . $a[2] );
  877. }
  878. else {return "Device needs to be ON to adjust file_type.";}
  879. }
  880. # picture_dir
  881. elsif ( lc( $a[1] ) eq "picture_dir" ) {
  882. if ( $state eq "on" ) {
  883. foreach (@a) {
  884. if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
  885. $Count = $Count + 1;
  886. if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
  887. }
  888. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
  889. WINCONNECT_SendCommand( $hash, "picture_dir" , "=" . $cmd );
  890. readingsSingleUpdate( $hash, "picture_dir", $Value,1 );
  891. }
  892. else {return "Device needs to be ON to picture_dir.";}
  893. }
  894. # picture_make
  895. elsif ( lc( $a[1] ) eq "picture_make" ) {
  896. Log3 $name, 3, "WINCONNECT set $name " . $a[1];
  897. if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "picture_make" );}else {return "Device needs to be ON to adjust picture_make.";}
  898. }
  899. # camera
  900. elsif ( lc( $a[1] ) eq "camera" ) {
  901. return "No argument given" if ( !defined( $a[2] ) );
  902. Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
  903. if ( $state eq "on" ) {
  904. WINCONNECT_SendCommand( $hash, "camera" , "=" . $a[2] );
  905. }
  906. else {return "Device needs to be ON to adjust camera.";}
  907. }
  908. # return usage hint
  909. else {return $usage;}
  910. return;
  911. }
  912. sub WINCONNECT_Get($@) {
  913. my ( $hash, @a ) = @_;
  914. my $name = $hash->{NAME};
  915. my $what;
  916. my $files;
  917. return "argument is missing" if ( int(@a) < 2 );
  918. $what = $a[1];
  919. #2017.07.21 - Log nur schreiben wenn get nicht initialisiert wird
  920. if ($what ne '?') {
  921. Log3 $name, 5, "WINCONNECT $name [WINCONNECT_Get] [$what] called function";
  922. }
  923. if ( $what =~ /^(www_files|www_files_reset)$/)
  924. {
  925. if ( $what eq "www_files" ) {
  926. my $directory = '././www/winconnect';
  927. opendir (DIR, $directory) or die $!;
  928. while (my $file = readdir(DIR)) {
  929. if ($file ne "." && $file ne "..") {
  930. $files = $files . "$file\n";
  931. }
  932. }
  933. closedir(DIR);
  934. return $files ;
  935. }
  936. elsif ( $what eq "www_files_reset" ) {
  937. my $directory = '././www/winconnect';
  938. opendir (DIR, $directory) or die $!;
  939. while (my $file = readdir(DIR)) {
  940. if ($file ne "." && $file ne "..") {
  941. Log3 $name, 0, "WINCONNECT [WINCONNECT_Get] [www_files_reset] ././www/winconnect/$file delete!";
  942. unlink "././www/winconnect/$file";
  943. $files = $files . "DELETE $file\n";
  944. }
  945. }
  946. closedir(DIR);
  947. return $files ;
  948. }
  949. else {
  950. return "no such reading: $what";
  951. }
  952. }
  953. else {
  954. return "Unknown argument $what, choose one of www_files:noArg www_files_reset:noArg ";
  955. }
  956. }
  957. ###################################
  958. sub WINCONNECT_Define($$) {
  959. my ( $hash, $def ) = @_;
  960. my @a = split( "[ \t][ \t]*", $def );
  961. my $name = $hash->{NAME};
  962. Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Define()";
  963. if ( int(@a) < 2 ) {
  964. my $msg = "Wrong syntax: define <name> WINCONNECT <ip-or-hostname> [<poll-interval>] ";
  965. Log3 $name, 4, $msg;
  966. return $msg;
  967. }
  968. $hash->{TYPE} = "WINCONNECT";
  969. my $address = $a[2];
  970. $hash->{helper}{ADDRESS} = $address;
  971. # use interval of 45sec if not defined
  972. my $interval = $a[3] || 45;
  973. $hash->{INTERVAL} = $interval;
  974. # set default settings on first define
  975. if ($init_done) {
  976. $attr{$name}{icon} = 'it_server';
  977. }
  978. # start the status update timer
  979. #RemoveInternalTimer($hash);
  980. InternalTimer( gettimeofday() + 2, "WINCONNECT_GetStatus", $hash, 1);
  981. return;
  982. }
  983. sub WINCONNECT_ReceiveCommand($) {
  984. my ($param, $err, $data) = @_;
  985. my $hash = $param->{hash};
  986. my $name = $hash->{NAME};
  987. my $VerWin = substr(ReadingsVal( $name, "wincontrol", "0.0.0.0" ),4);
  988. my $VerGit = substr(ReadingsVal( $name, "wincontrol_gitlab", "0.0.0.0" ),4);
  989. my $service = $param->{service};
  990. readingsBeginUpdate($hash);
  991. # Versionsnachricht
  992. my $Message = $name . "%20NOTIFYMSG%20Neue%20WinConnect%20Version%20verfügbar!%20Downloadlink%20=%20" . $DownloadGURL;
  993. if($err ne "") {
  994. Log3 $name, 5, "WINCONNECT $name: error while requesting ".$param->{url}." - $err";
  995. readingsBulkUpdateIfChanged( $hash, "state", "off" );
  996. if (ReadingsVal( $name, "wincontrol_user_port", "8183" ) eq "8183" && AttrVal($name, "win_resetreadings", 1) eq '1') {
  997. readingsBulkUpdateIfChanged( $hash, "user_aktiv", "false" );
  998. readingsBulkUpdateIfChanged( $hash, "audio", "off");
  999. readingsBulkUpdateIfChanged( $hash, "user_aktiv", "false" );
  1000. readingsBulkUpdateIfChanged( $hash, "os_RunTime_days", "0" );
  1001. readingsBulkUpdateIfChanged( $hash, "os_RunTime_hours", "0" );
  1002. readingsBulkUpdateIfChanged( $hash, "os_RunTime_minutes", "0" );
  1003. readingsBulkUpdateIfChanged( $hash, "printer_aktiv", "false" );
  1004. readingsBulkUpdateIfChanged( $hash, "printer_names", "no_printing" );
  1005. }
  1006. }
  1007. elsif($data ne "")
  1008. {
  1009. readingsBulkUpdateIfChanged( $hash, "state", "on" );
  1010. Log3 $name, 5, "WINCONNECT $name: url ".$param->{url}." returned: $data";
  1011. if(!defined($hash->{helper}{SENDVERSION})) {$hash->{helper}{SENDVERSION}='';}
  1012. # 2017.07.26 - Check update
  1013. if ( AttrVal( $name, "autoupdatewincontrol", 1 ) == 1 ) {
  1014. if ($VerWin < $VerGit && $hash->{helper}{SENDVERSION} eq '2' && $service ne 'notifymsg') {
  1015. # Neue Version vorhanden
  1016. $hash->{helper}{SENDVERSION} = '1';
  1017. WINCONNECT_SendCommand( $hash, "notifymsg" , "=" . $Message);
  1018. } else{
  1019. delete($hash->{helper}{SENDVERSION})
  1020. }
  1021. }
  1022. }
  1023. readingsEndUpdate( $hash, 1 );
  1024. }
  1025. ############################################################################################################
  1026. #
  1027. # Begin of helper functions
  1028. #
  1029. ############################################################################################################
  1030. ###################################
  1031. sub WINCONNECT_Undefine($$) {
  1032. my ( $hash, $arg ) = @_;
  1033. my $name = $hash->{NAME};
  1034. Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Undefine()";
  1035. # Stop the internal GetStatus-Loop and exit
  1036. RemoveInternalTimer($hash);
  1037. return;
  1038. }
  1039. 1;
  1040. =pod
  1041. =item device
  1042. =item summary control for Windows based systems via network connection
  1043. =item summary_DE Steuerung von Windows basierte Systemen &uuml;ber das Netzwerk
  1044. =begin html
  1045. <a name="WINCONNECT"></a>
  1046. <h3>WINCONNECT</h3>
  1047. <ul>
  1048. This module controls a Windows PC.
  1049. <br><br>
  1050. <ul>
  1051. <a name="WINCONNECTdefine" id="WINCONNECTdefine"></a> <b>Define</b>
  1052. <ul>
  1053. <code>define &lt;name&gt; WINCONNECT &lt;ip-address-or-hostname&gt; [&lt;poll-interval&gt;]</code><br>
  1054. <br>
  1055. Defining an WINCONNECT device will schedule an internal task (interval can be set with optional parameter &lt;poll-interval&gt; in seconds, if not set, the value is 45 seconds), which periodically reads the status of the device and triggers notify/filelog commands.<br>
  1056. <br>
  1057. Example:<br>
  1058. <ul>
  1059. <code>define Buero.PC WINCONNECT 192.168.0.10<br>
  1060. <br>
  1061. # With custom interval of 60 seconds<br>
  1062. define Buero.PC WINCONNECT 192.168.0.10 60<br></code>
  1063. </ul>
  1064. </ul>
  1065. </ul>
  1066. <br><br>
  1067. More information on <a target="_blank" href="https://wiki.fhem.de/wiki/WINCONNECT">FHEM Wiki</a>.<br/>
  1068. <br>
  1069. </ul>
  1070. =end html
  1071. =begin html_DE
  1072. <a name="WINCONNECT"></a>
  1073. <h3>WINCONNECT</h3>
  1074. <ul>
  1075. Dieses Module dient zur Steuerung eines Windows PCs
  1076. <br><br>
  1077. <ul>
  1078. <a name="WINCONNECTdefine" id="WINCONNECTdefine"></a> <b>Define</b>
  1079. <ul>
  1080. <code>define &lt;name&gt; WINCONNECT &lt;ip-address-or-hostname&gt; [&lt;poll-interval&gt;]</code><br>
  1081. <br>
  1082. F&uuml;r definierte WINCONNECT Ger&auml;te wird ein interner Task angelegt, welcher periodisch die Readings aktualisiert. Der Standartpollintervall ist 45 Sekunden.<br>
  1083. <br>
  1084. Example:<br>
  1085. <ul>
  1086. <code>define Buero.PC WINCONNECT 192.168.0.10<br>
  1087. <br>
  1088. # Alternativer poll intervall von 60 seconds<br>
  1089. define Buero.PC WINCONNECT 192.168.0.10 60<br></code>
  1090. </ul>
  1091. </ul>
  1092. </ul>
  1093. <br><br>
  1094. Mehr Information im <a target="_blank" href="https://wiki.fhem.de/wiki/WINCONNECT">FHEM Wiki</a>.<br/>
  1095. <br>
  1096. </ul>
  1097. =end html_DE
  1098. =cut