89_FULLY.pm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. ##############################################################################
  2. #
  3. # 89_FULLY.pm 0.8
  4. #
  5. # $Id: 89_FULLY.pm 17221 2018-08-28 06:16:32Z zap $
  6. #
  7. # Control Fully browser on Android tablets from FHEM.
  8. # Requires Fully Plus license!
  9. #
  10. ##############################################################################
  11. package main;
  12. use strict;
  13. use warnings;
  14. use Blocking;
  15. use SetExtensions;
  16. # Declare functions
  17. sub FULLY_Initialize ($);
  18. sub FULLY_Define ($$);
  19. sub FULLY_Undef ($$);
  20. sub FULLY_Shutdown ($);
  21. sub FULLY_Set ($@);
  22. sub FULLY_Get ($@);
  23. sub FULLY_Attr ($@);
  24. sub FULLY_Detail ($@);
  25. sub FULLY_UpdateDeviceInfo ($);
  26. sub FULLY_Execute ($$$$);
  27. sub FULLY_ScreenOff ($);
  28. sub FULLY_GetDeviceInfo ($);
  29. sub FULLY_ProcessDeviceInfo ($$);
  30. sub FULLY_GotDeviceInfo ($);
  31. sub FULLY_Abort ($);
  32. sub FULLY_UpdateReadings ($$);
  33. sub FULLY_Ping ($$);
  34. my $FULLY_VERSION = "0.8";
  35. my $FULLY_TIMEOUT = 4;
  36. my $FULLY_POLL_INTERVAL = 3600;
  37. my $FULLY_FHEM_COMMAND = qq(
  38. function SendRequest(FHEM_Address, Devicename, Command) {
  39. var Port = "8085"
  40. var url = "http://" + FHEM_Address + ":" + Port + "/fhem?XHR=1&cmd." + Devicename + "=" + Command;
  41. var req = new XMLHttpRequest();
  42. req.open("GET", url);
  43. req.send(null);
  44. req = null;
  45. }
  46. );
  47. ##################################################
  48. # Initialize module
  49. ##################################################
  50. sub FULLY_Initialize ($)
  51. {
  52. my ($hash) = @_;
  53. $hash->{DefFn} = "FULLY_Define";
  54. $hash->{UndefFn} = "FULLY_Undef";
  55. $hash->{SetFn} = "FULLY_Set";
  56. $hash->{GetFn} = "FULLY_Get";
  57. $hash->{AttrFn} = "FULLY_Attr";
  58. $hash->{ShutdownFn} = "FULLY_Shutdown";
  59. $hash->{FW_detailFn} = "FULLY_Detail";
  60. $hash->{parseParams} = 1;
  61. $hash->{AttrList} = "pingBeforeCmd:0,1,2 pollInterval requestTimeout repeatCommand:0,1,2 " .
  62. "disable:0,1 " .
  63. $readingFnAttributes;
  64. }
  65. ##################################################
  66. # Define device
  67. ##################################################
  68. sub FULLY_Define ($$)
  69. {
  70. my ($hash, $a, $h) = @_;
  71. my $name = $hash->{NAME};
  72. my $rc = 0;
  73. return "Usage: define devname FULLY IP_or_Hostname password [poll-interval]"
  74. if (@$a < 4);
  75. return "FULLY: polling interval must be in range 10 - 86400"
  76. if (@$a == 5 && ($$a[4] !~ /^[1-9][0-9]+$/ || $$a[4] < 10 || $$a[4] > 86400));
  77. $hash->{host} = $$a[2];
  78. $hash->{version} = $FULLY_VERSION;
  79. $hash->{onForTimer} = 'off';
  80. # $hash->{remoteAdmin} = '<html><a href="http://'.$hash->{host}.':2323">Remote Admin</a></html>';
  81. $hash->{fully}{password} = $$a[3];
  82. $hash->{fully}{schedule} = 0;
  83. Log3 $name, 1, "FULLY: Version $FULLY_VERSION Opening device ".$hash->{host};
  84. my $result = FULLY_GetDeviceInfo ($name);
  85. if (!FULLY_UpdateReadings ($hash, $result)) {
  86. Log3 $name, 2, "FULLY: Update of device info failed";
  87. }
  88. if (@$a == 5) {
  89. $attr{$name}{'pollInterval'} = $$a[4];
  90. $hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$$a[4]);
  91. InternalTimer (gettimeofday()+$$a[4], "FULLY_UpdateDeviceInfo", $hash, 0);
  92. }
  93. else {
  94. $hash->{nextUpdate} = 'off';
  95. }
  96. return undef;
  97. }
  98. #####################################
  99. # Set or delete attribute
  100. #####################################
  101. sub FULLY_Attr ($@)
  102. {
  103. my ($cmd, $name, $attrname, $attrval) = @_;
  104. my $hash = $defs{$name};
  105. if ($cmd eq 'set') {
  106. if ($attrname eq 'pollInterval') {
  107. if ($attrval >= 10 && $attrval <= 86400) {
  108. my $curval = AttrVal ($name, 'pollInterval', $FULLY_POLL_INTERVAL);
  109. if ($attrval != $curval) {
  110. Log3 $name, 2, "FULLY: Polling interval set to $attrval";
  111. RemoveInternalTimer ($hash);
  112. $hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$attrval);
  113. InternalTimer (gettimeofday()+$attrval, "FULLY_UpdateDeviceInfo", $hash, 0);
  114. }
  115. }
  116. elsif ($attrval == 0) {
  117. RemoveInternalTimer ($hash);
  118. $hash->{nextUpdate} = 'off';
  119. }
  120. else {
  121. return "FULLY: Polling interval must be in range 10-86400";
  122. }
  123. }
  124. elsif ($attrname eq 'requestTimeout') {
  125. return "FULLY: Timeout must be greater than 0" if ($attrval < 1);
  126. }
  127. }
  128. elsif ($cmd eq 'del') {
  129. if ($attrname eq 'pollInterval') {
  130. RemoveInternalTimer ($hash);
  131. $hash->{nextUpdate} = 'off';
  132. }
  133. }
  134. return undef;
  135. }
  136. #####################################
  137. # Delete device
  138. #####################################
  139. sub FULLY_Undef ($$)
  140. {
  141. my ($hash, $arg) = @_;
  142. RemoveInternalTimer ($hash);
  143. BlockingKill ($hash->{fully}{bc}) if (defined ($hash->{fully}{bc}));
  144. return undef;
  145. }
  146. #####################################
  147. # Shutdown FHEM
  148. #####################################
  149. sub FULLY_Shutdown ($)
  150. {
  151. my ($hash) = @_;
  152. RemoveInternalTimer ($hash);
  153. BlockingKill ($hash->{fully}{bc}) if (defined ($hash->{fully}{bc}));
  154. return undef;
  155. }
  156. #####################################
  157. # Enhance device detail view
  158. #####################################
  159. sub FULLY_Detail ($@)
  160. {
  161. my ($FW_wname, $name, $room, $pageHash) = @_;
  162. my $hash = $defs{$name};
  163. my $html = qq(
  164. <span class='mkTitle'>Device Administration</span>
  165. <table class="block wide">
  166. <tr class="odd">
  167. <td><div class="col1">
  168. <a target="_blank" href="http://$hash->{host}:2323">Remote Admin</a>
  169. </div></td>
  170. </tr>
  171. </table>
  172. );
  173. return $html;
  174. }
  175. #####################################
  176. # Set commands
  177. #####################################
  178. sub FULLY_Set ($@)
  179. {
  180. my ($hash, $a, $h) = @_;
  181. my $name = shift @$a;
  182. my $opt = shift @$a;
  183. my $options = "brightness clearCache:noArg exit:noArg lock:noArg motionDetection:on,off ".
  184. "off:noArg on:noArg on-for-timer restart:noArg screenOffTimer screenSaver:start,stop ".
  185. "screenSaverTimer screenSaverURL speak startURL unlock:noArg url";
  186. my $response;
  187. # Fully commands without argument
  188. my %cmds = (
  189. "clearCache" => "clearCache",
  190. "exit" => "exitApp", "restart" => "restartApp",
  191. "on" => "screenOn", "off" => "screenOff",
  192. "lock" => "enabledLockedMode", "unlock" => "disableLockedMode"
  193. );
  194. my $disable = AttrVal ($name, 'disable', 0);
  195. return undef if ($disable);
  196. if (exists ($cmds{$opt})) {
  197. $response = FULLY_Execute ($hash, $cmds{$opt}, undef, 1);
  198. }
  199. elsif ($opt eq 'on-for-timer') {
  200. my $par = shift @$a;
  201. $par = "forever" if (!defined ($par));
  202. if ($par eq 'forever') {
  203. $response = FULLY_Execute ($hash, "setBooleanSetting",
  204. { "key" => "keepScreenOn", "value" => "true" }, 1);
  205. $response = FULLY_Execute ($hash, "screenOn", undef, 0)
  206. if (defined ($response) && $response ne '');
  207. }
  208. elsif ($par eq 'off') {
  209. $response = FULLY_Execute ($hash, "setBooleanSetting",
  210. { "key" => "keepScreenOn", "value" => "false" }, 1);
  211. $response = FULLY_Execute ($hash, "setStringSetting",
  212. { "key" => "timeToScreenOffV2", "value" => "0" }, 0)
  213. if (defined ($response) && $response ne '');
  214. }
  215. elsif ($par =~ /^[0-9]+$/) {
  216. $response = FULLY_Execute ($hash, "setBooleanSetting",
  217. { "key" => "keepScreenOn", "value" => "true" }, 1);
  218. $response = FULLY_Execute ($hash, "screenOn", undef, 0)
  219. if (defined ($response) && $response ne '');
  220. InternalTimer (gettimeofday()+$par, "FULLY_ScreenOff", $hash, 0);
  221. }
  222. else {
  223. return "Usage: set $name on-for-timer [{ Seconds | forever | off }]";
  224. }
  225. RemoveInternalTimer ($hash, "FULLY_ScreenOff") if ($par eq 'off' || $par eq 'forever');
  226. $hash->{onForTimer} = $par if (defined ($response) && $response ne '');
  227. }
  228. elsif ($opt eq 'screenOffTimer') {
  229. my $value = shift @$a;
  230. return "Usage: set $name $opt {seconds}" if (!defined ($value));
  231. $response = FULLY_Execute ($hash, "setStringSetting",
  232. { "key" => "timeToScreenOffV2", "value" => "$value" }, 1);
  233. }
  234. elsif ($opt eq 'screenSaver') {
  235. my $state = shift @$a;
  236. return "Usage: set $name $opt { start | stop }" if (!defined ($state));
  237. if ($state eq 'start') {
  238. $response = FULLY_Execute ($hash, "startScreensaver", undef, 1);
  239. }
  240. elsif ($state eq 'stop') {
  241. $response = FULLY_Execute ($hash, "stopScreensaver", undef, 1);
  242. }
  243. else {
  244. return "Usage: set $name $opt { start | stop }";
  245. }
  246. }
  247. elsif ($opt eq 'screenSaverTimer') {
  248. my $value = shift @$a;
  249. return "Usage: set $name $opt {seconds}" if (!defined ($value));
  250. $response = FULLY_Execute ($hash, "setStringSetting",
  251. { "key" => "timeToScreensaverV2", "value" => "$value" }, 1);
  252. }
  253. elsif ($opt eq 'screenSaverURL') {
  254. my $value = shift @$a;
  255. return "Usage: set $name $opt {URL}" if (!defined ($value));
  256. $response = FULLY_Execute ($hash, "setStringSetting",
  257. { "key" => "screensaverURL", "value" => "$value" }, 1);
  258. }
  259. elsif ($opt eq 'startURL') {
  260. my $value = shift @$a;
  261. return "Usage: set $name $opt {URL}" if (!defined ($value));
  262. $response = FULLY_Execute ($hash, "setStringSetting",
  263. { "key" => "startURL", "value" => "$value" }, 1);
  264. }
  265. elsif ($opt eq 'brightness') {
  266. my $value = shift @$a;
  267. return "Usage: set $name brightness 0-255" if (!defined ($value));
  268. $value = 255 if ($value > 255);
  269. $response = FULLY_Execute ($hash, "setStringSetting",
  270. { "key" => "screenBrightness", "value" => "$value" }, 1);
  271. }
  272. elsif ($opt eq 'motionDetection') {
  273. my $state = shift @$a;
  274. return "Usage: set $name motionDetection { on | off }" if (!defined ($state));
  275. my $value = $state eq 'on' ? 'true' : 'false';
  276. $response = FULLY_Execute ($hash, "setBooleanSetting",
  277. { "key" => "motionDetection", "value" => "$value" }, 1);
  278. }
  279. elsif ($opt eq 'speak') {
  280. my $text = shift @$a;
  281. return 'Usage: set $name speak "{Text}"' if (!defined ($text));
  282. while ($text =~ /\[(.+):(.+)\]/) {
  283. my ($device, $reading) = ($1, $2);
  284. my $value = ReadingsVal ($device, $reading, '');
  285. $text =~ s/\[$device:$reading\]/$value/g;
  286. }
  287. my $enctext = urlEncode ($text);
  288. $response = FULLY_Execute ($hash, "textToSpeech", { "text" => "$enctext" }, 1);
  289. }
  290. elsif ($opt eq 'url') {
  291. my $url = shift @$a;
  292. my $cmd = defined ($url) ? "loadURL" : "loadStartURL";
  293. $response = FULLY_Execute ($hash, $cmd, { "url" => "$url" }, 1);
  294. }
  295. else {
  296. return "FULLY: Unknown argument $opt, choose one of ".$options;
  297. }
  298. my $result = FULLY_ProcessDeviceInfo ($name, $response);
  299. if (!FULLY_UpdateReadings ($hash, $result)) {
  300. Log3 $name, 2, "FULLY: Command failed";
  301. return "FULLY: Command failed";
  302. }
  303. return undef;
  304. }
  305. #####################################
  306. # Get commands
  307. #####################################
  308. sub FULLY_Get ($@)
  309. {
  310. my ($hash, $a, $h) = @_;
  311. my $name = shift @$a;
  312. my $opt = shift @$a;
  313. my $options = "info:noArg stats:noArg update:noArg";
  314. my $response;
  315. my $disable = AttrVal ($name, 'disable', 0);
  316. return undef if ($disable);
  317. if ($opt eq 'info') {
  318. my $result = FULLY_Execute ($hash, 'deviceInfo', undef, 1);
  319. if (!defined ($result) || $result eq '') {
  320. Log3 $name, 2, "FULLY: Command failed";
  321. return "FULLY: Command failed";
  322. }
  323. elsif ($response =~ /Wrong password/) {
  324. Log3 $name, 2, "FULLY: Wrong password";
  325. return "FULLY: Wrong password";
  326. }
  327. $response = '';
  328. while ($result =~ /table-cell\">([^<]+)<\/td><td class="table-cell">([^<]+)</g) {
  329. $response .= "$1 = $2<br/>\n";
  330. }
  331. return $response;
  332. }
  333. elsif ($opt eq 'stats') {
  334. return "FULLY: Command not implemented";
  335. }
  336. elsif ($opt eq 'update') {
  337. my $result = FULLY_GetDeviceInfo ($name);
  338. if (!FULLY_UpdateReadings ($hash, $result)) {
  339. Log3 $name, 2, "FULLY: Command failed";
  340. return "FULLY: Command failed";
  341. }
  342. }
  343. else {
  344. return "FULLY: Unknown argument $opt, choose one of ".$options;
  345. }
  346. return undef;
  347. }
  348. #####################################
  349. # Execute Fully command
  350. #####################################
  351. sub FULLY_Execute ($$$$)
  352. {
  353. my ($hash, $command, $param, $doping) = @_;
  354. my $name = $hash->{NAME};
  355. # Get attributes
  356. my $timeout = AttrVal ($name, 'requestTimeout', $FULLY_TIMEOUT);
  357. my $repeatCommand = min (AttrVal ($name, 'repeatCommand', 0), 2);
  358. my $ping = min (AttrVal ($name, 'pingBeforeCmd', 0), 2);
  359. my $response = '';
  360. my $url = "http://".$hash->{host}.":2323/?cmd=$command";
  361. if (defined ($param)) {
  362. foreach my $parname (keys %$param) {
  363. if (defined ($param->{$parname})) {
  364. $url .= "&$parname=".$param->{$parname};
  365. }
  366. }
  367. }
  368. # Ping tablet device
  369. FULLY_Ping ($hash, $ping) if ($doping && $ping > 0);
  370. my $i = 0;
  371. while ($i <= $repeatCommand && (!defined ($response) || $response eq '')) {
  372. $response = GetFileFromURL ("$url&password=".$hash->{fully}{password}, $timeout);
  373. Log3 $name, 4, "FULLY: HTTP response empty" if (defined ($response) && $response eq '');
  374. $i++;
  375. }
  376. return $response;
  377. }
  378. #####################################
  379. # Timer function: Turn screen off
  380. #####################################
  381. sub FULLY_ScreenOff ($)
  382. {
  383. my ($hash) = @_;
  384. my $response = FULLY_Execute ($hash, "setBooleanSetting",
  385. { "key" => "keepScreenOn", "value" => "false" }, 1);
  386. $response = FULLY_Execute ($hash, "screenOff", undef, 1)
  387. if (defined ($response) && $response ne '');
  388. $hash->{onForTimer} = 'off' if (defined ($response) && $response ne '');
  389. }
  390. #####################################
  391. # Timer function: Read device info
  392. #####################################
  393. sub FULLY_UpdateDeviceInfo ($)
  394. {
  395. my ($hash) = @_;
  396. my $name = $hash->{NAME};
  397. my $disable = AttrVal ($name, 'disable', 0);
  398. if (!exists ($hash->{fully}{bc}) && $disable == 0) {
  399. $hash->{fully}{bc} = BlockingCall ("FULLY_GetDeviceInfo", $name, "FULLY_GotDeviceInfo",
  400. 120, "FULLY_Abort", $hash);
  401. }
  402. }
  403. #####################################
  404. # Get tablet device information
  405. #####################################
  406. sub FULLY_GetDeviceInfo ($)
  407. {
  408. my ($name) = @_;
  409. my $hash = $defs{$name};
  410. my $result = FULLY_Execute ($hash, 'deviceInfo', undef, 1);
  411. return FULLY_ProcessDeviceInfo ($name, $result);
  412. }
  413. #####################################
  414. # Extract parameters from HTML code
  415. #####################################
  416. sub FULLY_ProcessDeviceInfo ($$)
  417. {
  418. my ($name, $result) = @_;
  419. return "$name|0|state=failed" if (!defined ($result) || $result eq '');
  420. return "$name|0|state=wrong password" if ($result =~ /Wrong password/);
  421. my $parameters = "$name|1";
  422. while ($result =~ /table-cell\">([^<]+)<\/td><td class="table-cell">([^<]+)</g) {
  423. my $rn = lc($1);
  424. my $rv = $2;
  425. $rv =~ s/\s+$//;
  426. $rn =~ s/\:/\./g;
  427. $rn =~ s/[^A-Za-z\d_\.-]+/_/g;
  428. $rn =~ s/[_]+$//;
  429. if ($rn eq 'battery_level') {
  430. if ($rv =~ /^([0-9]+)% \(([^\)]+)\)$/) {
  431. $parameters .= "|$rn=$1|power=$2";
  432. next;
  433. }
  434. }
  435. elsif ($rn eq 'screen_brightness') {
  436. $rn = "brightness";
  437. }
  438. elsif ($rn eq 'screen_status') {
  439. $parameters .= "|state=$rv";
  440. }
  441. $parameters .= "|$rn=$rv";
  442. }
  443. return $parameters;
  444. }
  445. #####################################
  446. # Success function for blocking call
  447. #####################################
  448. sub FULLY_GotDeviceInfo ($)
  449. {
  450. my ($string) = @_;
  451. my ($name, $result) = split ('\|', $string, 2);
  452. my $hash = $defs{$name};
  453. my $pollInterval = AttrVal ($name, 'pollInterval', $FULLY_POLL_INTERVAL);
  454. my $timeout = AttrVal ($name, 'requestTimeout', $FULLY_TIMEOUT);
  455. delete $hash->{fully}{bc} if (exists ($hash->{fully}{bc}));
  456. my $rc = FULLY_UpdateReadings ($hash, $string);
  457. if (!$rc) {
  458. Log3 $name, 2, "FULLY: Request timed out";
  459. if ($hash->{fully}{schedule} == 0) {
  460. $hash->{fully}{schedule} += 1;
  461. Log3 $name, 2, "FULLY: Rescheduling in $timeout seconds.";
  462. $pollInterval = $timeout;
  463. }
  464. else {
  465. $hash->{fully}{schedule} = 0;
  466. }
  467. }
  468. $hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$pollInterval);
  469. InternalTimer (gettimeofday()+$pollInterval, "FULLY_UpdateDeviceInfo", $hash, 0)
  470. if ($pollInterval > 0);
  471. }
  472. #####################################
  473. # Abort function for blocking call
  474. #####################################
  475. sub FULLY_Abort ($)
  476. {
  477. my ($hash) = @_;
  478. my $name = $hash->{NAME};
  479. my $pollInterval = AttrVal ($name, 'pollInterval', $FULLY_POLL_INTERVAL);
  480. my $timeout = AttrVal ($name, 'requestTimeout', $FULLY_TIMEOUT);
  481. delete $hash->{fully}{bc} if (exists ($hash->{fully}{bc}));
  482. Log3 $name, 2, "FULLY: request timed out";
  483. if ($hash->{fully}{schedule} == 0) {
  484. $hash->{fully}{schedule} += 1;
  485. Log3 $name, 2, "FULLY: Rescheduling in $timeout seconds.";
  486. $pollInterval = $timeout;
  487. }
  488. else {
  489. $hash->{fully}{schedule} = 0;
  490. }
  491. $hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$pollInterval);
  492. InternalTimer (gettimeofday()+$pollInterval, "FULLY_UpdateDeviceInfo", $hash, 0)
  493. if ($pollInterval > 0);
  494. }
  495. #####################################
  496. # Update readings
  497. #####################################
  498. sub FULLY_UpdateReadings ($$)
  499. {
  500. my ($hash, $result) = @_;
  501. my $name = $hash->{NAME};
  502. my $rc = 1;
  503. if (!defined ($result) || $result eq '') {
  504. Log3 $name, 2, "FULLY: empty response";
  505. return 0;
  506. }
  507. my @parameters = split ('\|', $result);
  508. if (scalar (@parameters) == 0) {
  509. Log3 $name, 2, "FULLY: empty response";
  510. return 0;
  511. }
  512. if ($parameters[0] eq $name) {
  513. my $n = shift @parameters;
  514. $rc = shift @parameters;
  515. }
  516. readingsBeginUpdate ($hash);
  517. foreach my $parval (@parameters) {
  518. my ($rn, $rv) = split ('=', $parval);
  519. readingsBulkUpdate ($hash, $rn, $rv);
  520. }
  521. readingsEndUpdate ($hash, 1);
  522. return $rc;
  523. }
  524. #####################################
  525. # Send ICMP request to tablet device
  526. # Adapted from presence module.
  527. # Thx Markus.
  528. #####################################
  529. sub FULLY_Ping ($$)
  530. {
  531. my ($hash, $count) = @_;
  532. my $name = $hash->{NAME};
  533. my $host = $hash->{host};
  534. my $temp;
  535. if ($^O =~ m/(Win|cygwin)/)
  536. {
  537. $temp = qx(ping -n $count -4 $host);
  538. }
  539. elsif ($^O =~ m/solaris/)
  540. {
  541. $temp = qx(ping $host $count 2>&1);
  542. }
  543. else
  544. {
  545. $temp = qx(ping -c $count $host 2>&1);
  546. }
  547. Log3 $name, 4, "FULLY: Ping response = $temp" if (defined ($temp));
  548. sleep (1);
  549. return $temp;
  550. }
  551. 1;
  552. =pod
  553. =item device
  554. =item summary FULLY Browser Integration
  555. =begin html
  556. <a name="FULLY"></a>
  557. <h3>FULLY</h3>
  558. <ul>
  559. Module for controlling of Fully browser on Android tablets.
  560. </br></br>
  561. <a name="HMCCUdefine"></a>
  562. <b>Define</b><br/><br/>
  563. <ul>
  564. <code>define &lt;name&gt; FULLY &lt;HostOrIP&gt; &lt;password&gt; [&lt;poll-interval&gt;]</code>
  565. <br/><br/>
  566. The parameter <i>password</i> is the password set in Fully browser.
  567. </ul>
  568. <br/>
  569. <a name="FULLYset"></a>
  570. <b>Set</b><br/><br/>
  571. <ul>
  572. <li><b>set &lt;name&gt; brightness 0-255</b><br/>
  573. Adjust screen brightness.
  574. </li><br/>
  575. <li><b>set &lt;name&gt; clearCache</b><br/>
  576. Clear browser cache.
  577. </li><br/>
  578. <li><b>set &lt;name&gt; exit</b><br/>
  579. Terminate Fully.
  580. </li><br/>
  581. <li><b>set &lt;name&gt; motionDetection { on | off }</b><br/>
  582. Turn motion detection by camera on or off.
  583. </li><br/>
  584. <li><b>set &lt;name&gt; { lock | unlock }</b><br/>
  585. Lock or unlock display.
  586. </li><br/>
  587. <li><b>set &lt;name&gt; { on | off }</b><br/>
  588. Turn tablet display on or off.
  589. </li><br/>
  590. <li><b>set &lt;name&gt; on-for-timer [{ &lt;Seconds&gt; | <u>forever</u> | off }]</b><br/>
  591. Set timer for display. Default is forever.
  592. </li><br/>
  593. <li><b>set &lt;name&gt; restart</b><br/>
  594. Restart Fully.
  595. </li><br/>
  596. <li><b>set &lt;name&gt; screenOffTimer &lt;seconds&gt;</b><br/>
  597. Turn screen off after some idle seconds, set to 0 to disable timer.
  598. </li><br/>
  599. <li><b>set &lt;name&gt; screenSaver { start | stop }</b><br/>
  600. Start or stop screen saver. Screen saver URL can be set with command <b>set screenSaverURL</b>.
  601. </li><br/>
  602. <li><b>set &lt;name&gt; screenSaverTimer &lt;seconds&gt;</b><br/>
  603. Show screen saver URL after some idle seconds, set to 0 to disable timer.
  604. </li><br/>
  605. <li><b>set &lt;name&gt; screenSaverURL &lt;URL&gt;</b><br/>
  606. Show this URL when screensaver starts, set daydream: for Android daydream or dim: for black.<br/>
  607. </li><br/>
  608. <li><b>set &lt;name&gt; speak &lt;text&gt;</b><br/>
  609. Audio output of <i>text</i>. If <i>text</i> contains blanks it must be enclosed
  610. in double quotes. The text can contain device readings in format [device:reading].
  611. </li><br/>
  612. <li><b>set &lt;name&gt; startURL &lt;URL&gt;</b><br/>
  613. Show this URL when FULLY starts.<br/>
  614. </li><br/>
  615. <li><b>set &lt;name&gt; url [&lt;URL&gt;]</b><br/>
  616. Navigate to <i>URL</i>. If no URL is specified navigate to start URL.
  617. </li><br/>
  618. </ul>
  619. <br/>
  620. <a name="FULLYget"></a>
  621. <b>Get</b><br/><br/>
  622. <ul>
  623. <li><b>get &lt;name&gt; info</b><br/>
  624. Display Fully information.
  625. </li><br/>
  626. <li><b>get &lt;name&gt; stats</b><br/>
  627. Show Fully statistics.
  628. </li><br/>
  629. <li><b>get &lt;name&gt; update</b><br/>
  630. Update readings.
  631. </li><br/>
  632. </ul>
  633. <br/>
  634. <a name="FULLYattr"></a>
  635. <b>Attributes</b><br/>
  636. <br/>
  637. <ul>
  638. <li><b>disable &lt;0 | 1&gt;</b><br/>
  639. Disable device and automatic polling.
  640. </li><br/>
  641. <li><b>pingBeforeCmd &lt;Count&gt;</b><br/>
  642. Send <i>Count</i> ping request to tablet before executing commands. Valid values
  643. for <i>Count</i> are 0,1,2. Default is 0 (do not send ping request).
  644. </li><br/>
  645. <li><b>pollInterval &lt;seconds&gt;</b><br/>
  646. Set polling interval for FULLY device information.
  647. If <i>seconds</i> is 0 polling is turned off. Valid values are from 10 to
  648. 86400 seconds.
  649. </li><br/>
  650. <li><b>requestTimeout &lt;seconds&gt;</b><br/>
  651. Set timeout for http requests. Default is 4 seconds.
  652. </li><br/>
  653. <li><b>repeatCommand &lt;Count&gt;</b><br/>
  654. Repeat fully command on failure. Valid values for <i>Count</i> are 0,1,2. Default
  655. is 0 (do not repeat commands).
  656. </li><br/>
  657. </ul>
  658. </ul>
  659. =end html
  660. =cut