70_WINCONNECT.pm 44 KB

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