00_ZWDongle.pm 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. ##############################################
  2. # $Id: 00_ZWDongle.pm 12654 2016-11-25 19:18:53Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use Time::HiRes qw(gettimeofday);
  7. use ZWLib;
  8. use vars qw($FW_ME);
  9. sub ZWDongle_Parse($$$);
  10. sub ZWDongle_Read($@);
  11. sub ZWDongle_ReadAnswer($$$);
  12. sub ZWDongle_Ready($);
  13. sub ZWDongle_Write($$$);
  14. sub ZWDongle_ProcessSendStack($);
  15. sub ZWDongle_NUCheck($$$$);
  16. # See also:
  17. # http://www.digiwave.dk/en/programming/an-introduction-to-the-z-wave-protocol/
  18. # http://open-zwave.googlecode.com/svn-history/r426/trunk/cpp/src/Driver.cpp
  19. # http://buzzdavidson.com/?p=68
  20. # https://bitbucket.org/bradsjm/aeonzstickdriver
  21. my %sets = (
  22. "addNode" => { cmd => "4a%02x@", # ZW_ADD_NODE_TO_NETWORK
  23. param => { onNw =>0xc1, on =>0x81, off=>0x05,
  24. onNwSec=>0xc1, onSec=>0x81 } },
  25. "backupCreate" => { cmd => "" },
  26. "backupRestore" => { cmd => "" },
  27. "controllerChange" => { cmd => "4d%02x@", # ZW_CONTROLLER_CHANGE
  28. param => { on =>0x02, stop =>0x05,
  29. stopFailed =>0x06 } },
  30. "createNewPrimary" => { cmd => "4c%02x@", # ZW_CREATE_NEW_PRIMARY
  31. param => { on =>0x02, stop =>0x05,
  32. stopFailed =>0x06 } },
  33. "createNode" => { cmd => "60%02x" }, # ZW_REQUEST_NODE_INFO
  34. "factoryReset" => { cmd => "" }, # ZW_SET_DEFAULT
  35. "learnMode" => { cmd => "50%02x@", # ZW_SET_LEARN_MODE
  36. param => { onNw =>0x02, on =>0x01,
  37. disable=>0x00 } },
  38. "removeFailedNode" => { cmd => "61%02x@" }, # ZW_REMOVE_FAILED_NODE_ID
  39. "removeNode" => { cmd => "4b%02x@", # ZW_REMOVE_NODE_FROM_NETWORK
  40. param => {onNw=>0xc1, on=>0x81, off=>0x05 } },
  41. "reopen" => { cmd => "" },
  42. "replaceFailedNode"=> { cmd => "63%02x@" }, # ZW_REPLACE_FAILED_NODE
  43. "sendNIF" => { cmd => "12%02x05@" },# ZW_SEND_NODE_INFORMATION
  44. "setNIF" => { cmd => "03%02x%02x%02x%02x" },
  45. # SERIAL_API_APPL_NODE_INFORMATION
  46. "sucNodeId" => { cmd => "54%02x%02x00%02x@"},
  47. # ZW_SET_SUC_NODE_ID
  48. "sucRequestUpdate" => { cmd => "53%02x@"}, # ZW_REQUEST_NETWORK_UPDATE
  49. "sucSendNodeId" => { cmd => "57%02x25@"}, # ZW_SEND_SUC_ID
  50. "timeouts" => { cmd => "06%02x%02x" }, # SERIAL_API_SET_TIMEOUTS
  51. );
  52. my %gets = (
  53. "caps" => "07", # SERIAL_API_GET_CAPABILITIES
  54. "ctrlCaps" => "05", # ZW_GET_CONTROLLER_CAPS
  55. "homeId" => "20", # MEMORY_GET_ID
  56. "isFailedNode" => "62%02x", # ZW_IS_FAILED_NODE
  57. "neighborList" => "80%02x", # GET_ROUTING_TABLE_LINE
  58. "nodeInfo" => "41%02x", # ZW_GET_NODE_PROTOCOL_INFO
  59. "nodeList" => "02", # SERIAL_API_GET_INIT_DATA
  60. "random" => "1c%02x", # ZW_GET_RANDOM
  61. "raw" => "%s", # hex
  62. "routeFor" => "92%02x", # hex
  63. "sucNodeId" => "56", # ZW_GET_SUC_NODE_ID
  64. "timeouts" => "06", # SERIAL_API_SET_TIMEOUTS
  65. "version" => "15", # ZW_GET_VERSION
  66. );
  67. sub
  68. ZWDongle_Initialize($)
  69. {
  70. my ($hash) = @_;
  71. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  72. # Provider
  73. $hash->{ReadFn} = "ZWDongle_Read";
  74. $hash->{WriteFn} = "ZWDongle_Write";
  75. $hash->{ReadyFn} = "ZWDongle_Ready";
  76. $hash->{ReadAnswerFn} = "ZWDongle_ReadAnswer";
  77. # Normal devices
  78. $hash->{DefFn} = "ZWDongle_Define";
  79. $hash->{SetFn} = "ZWDongle_Set";
  80. $hash->{GetFn} = "ZWDongle_Get";
  81. $hash->{AttrFn} = "ZWDongle_Attr";
  82. $hash->{UndefFn} = "ZWDongle_Undef";
  83. $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 model:ZWDongle disable:0,1 ".
  84. "helpSites:multiple,pepper,alliance homeId networkKey ".
  85. "neighborListPos neighborListFmt";
  86. $hash->{FW_detailFn} = "ZWDongle_fhemwebFn";
  87. }
  88. #####################################
  89. sub
  90. ZWDongle_Define($$)
  91. {
  92. my ($hash, $def) = @_;
  93. my @a = split("[ \t][ \t]*", $def);
  94. if(@a != 3) {
  95. my $msg = "wrong syntax: define <name> ZWDongle {none[:homeId] | ".
  96. "devicename[\@baudrate] | ".
  97. "devicename\@directio | ".
  98. "hostname:port}";
  99. return $msg;
  100. }
  101. DevIo_CloseDev($hash);
  102. my $name = $a[0];
  103. my $dev = $a[2];
  104. $hash->{Clients} = ":ZWave:";
  105. my %matchList = ( "1:ZWave" => ".*" );
  106. $hash->{MatchList} = \%matchList;
  107. if($dev =~ m/none:(.*)/) {
  108. $hash->{homeId} = $1;
  109. Log3 $name, 1,
  110. "$name device is none (homeId:$1), commands will be echoed only";
  111. $attr{$name}{dummy} = 1;
  112. readingsSingleUpdate($hash, "state", "dummy", 1);
  113. return undef;
  114. } elsif($dev !~ m/@/ && $dev !~ m/:/) {
  115. $def .= "\@115200"; # default baudrate
  116. }
  117. $hash->{DeviceName} = $dev;
  118. $hash->{CallbackNr} = 0;
  119. $hash->{nrNAck} = 0;
  120. my @empty;
  121. $hash->{SendStack} = \@empty;
  122. ZWDongle_shiftSendStack($hash, 0, 5, undef);
  123. my $ret = DevIo_OpenDev($hash, 0, "ZWDongle_DoInit");
  124. return $ret;
  125. }
  126. #####################################
  127. sub
  128. ZWDongle_fhemwebFn($$$$)
  129. {
  130. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  131. my $js = "$FW_ME/pgm2/zwave_neighborlist.js";
  132. return
  133. "<div id='ZWDongleNr'><a id='zw_snm' href='#'>Show neighbor map</a></div>".
  134. "<div id='ZWDongleNrSVG'></div>".
  135. "<script type='text/javascript' src='$js'></script>".
  136. '<script type="text/javascript">'.<<"JSEND"
  137. \$(document).ready(function() {
  138. \$("div#ZWDongleNr a#zw_snm")
  139. .click(function(e){
  140. e.preventDefault();
  141. zw_nl('ZWDongle_nlData("$d")');
  142. });
  143. });
  144. </script>
  145. JSEND
  146. }
  147. sub
  148. ZWDongle_nlData($)
  149. {
  150. my ($d) = @_;
  151. my @a = devspec2array("TYPE=ZWave,FILTER=IODev=$d");
  152. my (@dn, %nb, @ret);
  153. my $fmt = eval AttrVal($d, "neighborListFmt",
  154. '{ txt=>"NAME", img=>"IMAGE", title=>"Time to ack: timeToAck" }');
  155. for my $e (@a) {
  156. my $h = $defs{$e};
  157. next if($h->{ZWaveSubDevice} ne "no");
  158. $h->{IMAGE} = ZWave_getPic($d, ReadingsVal($e, "modelId", ""));
  159. my $nl = ReadingsVal($e, "neighborList", "");
  160. $nl = ReadingsVal($d, "neighborList_".hex($h->{nodeIdHex}), "")
  161. if(!$nl);
  162. $nl =~ s/,/ /g; $nl =~ s/\bempty\b//g;
  163. push @dn, $e if($nl =~ m/\b$d\b/);
  164. $nl = '"'.join('","',split(" ", $nl)).'"' if($nl);
  165. my %line = (
  166. pos => '['.AttrVal($e, "neighborListPos", "").']',
  167. class => '"zwBox"',
  168. neighbors => '['.$nl.']'
  169. );
  170. my $r = $h->{READINGS};
  171. my $a = $attr{$e};
  172. for my $key (keys %{$fmt}) {
  173. my $val = $fmt->{$key};
  174. $val =~ s/\b(\w+)\b/{ $h->{$1} ? $h->{$1} :
  175. $r->{$1} ? $r->{$1}{VAL} :
  176. $a->{$1} ? $a->{$1} : $1 }/ge;
  177. $line{$key} = "\"$val\"" if($val ne $fmt->{$key}); # Skip unchanged
  178. }
  179. push @ret, "\"$e\":{". join(',',map({"\"$_\":$line{$_}" } keys %line)) ."}";
  180. $nb{$e} = $nl;
  181. }
  182. my $pos = AttrVal($d, "neighborListPos", "");
  183. my $nl = (@dn ? '"'.join('","',@dn).'"' : '');
  184. push @ret, "\"$d\":{\"txt\":\"$d\", \"pos\":[$pos],".
  185. "\"class\":\"zwDongle\",\"neighbors\":[$nl] }";
  186. return "{ \"saveFn\":\"attr {1} neighborListPos {2}\",".
  187. "\"firstObj\":\"$d\",".
  188. "\"el\":{".join(",",@ret)."} }";
  189. }
  190. #####################################
  191. sub
  192. ZWDongle_Undef($$)
  193. {
  194. my ($hash,$arg) = @_;
  195. DevIo_CloseDev($hash);
  196. return undef;
  197. }
  198. #####################################
  199. sub
  200. ZWDongle_Set($@)
  201. {
  202. my ($hash, @a) = @_;
  203. my $name = shift @a;
  204. return "\"set ZWDongle\" needs at least one parameter" if(@a < 1);
  205. my $type = shift @a;
  206. if(!defined($sets{$type})) {
  207. my @r;
  208. map { my $p = $sets{$_}{param};
  209. push @r,($p ? "$_:".join(",",sort keys %{$p}) : $_)} sort keys %sets;
  210. return "Unknown argument $type, choose one of " . join(" ",@r);
  211. }
  212. Log3 $hash, 4, "ZWDongle *** set $name $type ".join(" ",@a);
  213. if($type eq "reopen") {
  214. return if(AttrVal($name, "dummy",undef) || AttrVal($name, "disable",undef));
  215. delete $hash->{NEXT_OPEN};
  216. DevIo_CloseDev($hash);
  217. sleep(1);
  218. DevIo_OpenDev($hash, 0, "ZWDongle_DoInit");
  219. return;
  220. }
  221. if($type eq "backupCreate") {
  222. my $caps = ReadingsVal($name, "caps","");
  223. my $is4 = ($caps =~ m/MEMORY_GET_BUFFER/);
  224. my $is5 = ($caps =~ m/NVM_EXT_READ_LONG_BUFFER/);
  225. return "Creating a backup is not supported by this device"
  226. if(!$is4 && !$is5);
  227. return "Usage: set $name backupCreate [16k|32k|64k|128k|256k]"
  228. if(int(@a) != 1 || $a[0] !~ m/^(16|32|64|128|256)k$/);
  229. my $fn = ($is5 ? "NVM_EXT_READ_LONG_BUFFER" : "MEMORY_GET_BUFFER");
  230. my $cmdFormat = ($is5 ? "002a%06x0040" : "0023%04x20");
  231. my $cmdRe = ($is5 ? "^012a" : "^0123");
  232. my $inc = ($is5 ? 64 : 32);
  233. my $l = $1 * 1024;
  234. my $fName = "$attr{global}{modpath}/$name.bin";
  235. open(OUT, ">$fName") || return "Cant open $fName: $!";
  236. binmode(OUT);
  237. for(my $off = 0; $off < $l;) {
  238. ZWDongle_Write($hash, "", sprintf($cmdFormat, $off));
  239. my ($err, $ret) = ZWDongle_ReadAnswer($hash, $fn, $cmdRe);
  240. return $err if($err);
  241. print OUT pack('H*', substr($ret, 4));
  242. $off += $inc;
  243. Log 3, "$name backupCreate at $off bytes" if($off % 16384 == 0);
  244. }
  245. close(OUT);
  246. return "Wrote $l bytes to $fName";
  247. }
  248. if($type eq "backupRestore") {
  249. my $caps = ReadingsVal($name, "caps","");
  250. my $is4 = ($caps =~ m/MEMORY_PUT_BUFFER/);
  251. my $is5 = ($caps =~ m/NVM_EXT_WRITE_LONG_BUFFER/);
  252. return "Restoring a backup is not supported by this device"
  253. if(!$is4 && !$is5);
  254. my $fn = ($is5 ? "NVM_EXT_WRITE_LONG_BUFFER" : "MEMORY_PUT_BUFFER");
  255. my $cmdFormat = ($is5 ? "002b%06x0040%s" : "0024%04x40%s");
  256. my $cmdRe = ($is5 ? "^012b" : "^0124");
  257. my $cmdRet = ($is5 ? "^012b01" : "^012401");
  258. my $inc = ($is5 ? 64 : 32);
  259. return "Usage: set $name backupRestore" if(int(@a) != 0);
  260. my $fName = "$attr{global}{modpath}/$name.bin";
  261. my $l = -s $fName;
  262. return "$fName does not exists, or is empty" if(!$l);
  263. open(IN, $fName) || return "Cant open $fName: $!";
  264. binmode(IN);
  265. my $buf;
  266. for(my $off = 0; $off < $l;) {
  267. if(sysread(IN, $buf, $inc) != $inc) {
  268. return "Cant read $inc bytes from $fName";
  269. }
  270. ZWDongle_Write($hash, "", sprintf($cmdFormat, $off, unpack('H*',$buf)));
  271. my ($err, $ret) = ZWDongle_ReadAnswer($hash, $fn, $cmdRe);
  272. return $err if($err);
  273. return "Unexpected $fn return value $ret"
  274. if($ret !~ m/$cmdRet/);
  275. $off += $inc;
  276. Log 3, "$name backupRestore at $off bytes" if($off % 16384 == 0);
  277. }
  278. close(IN);
  279. return "Restored $l bytes from $fName";
  280. }
  281. if($type eq "factoryReset") {
  282. return "Reset to default is not supported by this device"
  283. if(ReadingsVal($name, "caps","") !~ m/ZW_SET_DEFAULT/);
  284. return "Read commandref before use! -> Usage: set $name factoryReset yes"
  285. if(int(@a) != 1 || $a[0] !~ m/^(yes)$/);
  286. ZWDongle_Write($hash,"","0042");
  287. return "Reseted $name to factory default and assigned new random HomeId";
  288. }
  289. if($type eq "removeFailedNode" ||
  290. $type eq "replaceFailedNode" ||
  291. $type eq "createNode" ||
  292. $type eq "sendNIF") {
  293. $a[0] =~ s/^UNKNOWN_//;
  294. $a[0] = hex($defs{$a[0]}{nodeIdHex})
  295. if($defs{$a[0]} && $defs{$a[0]}{nodeIdHex});
  296. }
  297. my $cmd = $sets{$type}{cmd};
  298. my $fb = substr($cmd, 0, 2);
  299. if($fb =~ m/^[0-8A-F]+$/i &&
  300. ReadingsVal($name, "caps","") !~ m/\b$zw_func_id{$fb}\b/) {
  301. return "$type is unsupported by this controller";
  302. }
  303. if($type eq "addNode") {
  304. if($a[0] && $a[0] =~ m/sec/i) {
  305. $hash->{addSecure} = 1;
  306. } else {
  307. delete($hash->{addSecure});
  308. }
  309. if($a[0]) { # Remember the client for the failed message
  310. if($a[0] eq "off") {
  311. delete($hash->{addCL});
  312. } elsif($hash->{CL}) {
  313. $hash->{addCL} = $hash->{CL};
  314. }
  315. }
  316. }
  317. my $par = $sets{$type}{param};
  318. if($par && !$par->{noArg}) {
  319. return "Unknown argument for $type, choose one of ".join(" ",keys %{$par})
  320. if(!$a[0] || !defined($par->{$a[0]}));
  321. $a[0] = $par->{$a[0]};
  322. }
  323. if($cmd =~ m/\@/) {
  324. my $c = $hash->{CallbackNr}+1;
  325. $c = 1 if($c > 255);
  326. $hash->{CallbackNr} = $c;
  327. $c = sprintf("%02x", $c);
  328. $cmd =~ s/\@/$c/g;
  329. }
  330. my @ca = split("%", $cmd, -1);
  331. my $nargs = int(@ca)-1;
  332. return "set $name $type needs $nargs arguments" if($nargs != int(@a));
  333. ZWDongle_Write($hash, "", "00".sprintf($cmd, @a));
  334. return undef;
  335. }
  336. #####################################
  337. sub
  338. ZWDongle_Get($@)
  339. {
  340. my ($hash, @a) = @_;
  341. my $name = shift @a;
  342. return "\"get $name\" needs at least one parameter" if(@a < 1);
  343. my $cmd = shift @a;
  344. return "Unknown argument $cmd, choose one of " .
  345. join(" ", map { $gets{$_} =~ m/%/ ? $_ : "$_:noArg" } sort keys %gets)
  346. if(!defined($gets{$cmd}));
  347. my $fb = substr($gets{$cmd}, 0, 2);
  348. if($fb =~ m/^[0-8A-F]+$/i && $cmd ne "caps" &&
  349. ReadingsVal($name, "caps","") !~ m/\b$zw_func_id{$fb}\b/) {
  350. return "$cmd is unsupported by this controller";
  351. }
  352. if($cmd eq "raw") {
  353. if($a[0] =~ s/^42//) {
  354. Log3 $hash, 4, "ZWDongle *** get $name $cmd 42".join(" ",@a)." blocked";
  355. return "raw 0x42 (ZW_SET_DEFAULT) blocked. Read commandref first and ".
  356. "use instead: set $name factoryReset";
  357. }
  358. }
  359. Log3 $hash, 4, "ZWDongle *** get $name $cmd ".join(" ",@a);
  360. if($cmd eq "neighborList") {
  361. my @b;
  362. @b = grep(!/onlyRep/i, @a); my $onlyRep = (@b != @a); @a = @b;
  363. @b = grep(!/excludeDead/i, @a); my $exclDead = (@b != @a); @a = @b;
  364. $gets{neighborList} = "80%02x".($exclDead ?"00":"01").($onlyRep ?"01":"00");
  365. return "Usage: get $name $cmd [excludeDead] [onlyRep] nodeId"
  366. if(int(@a) != 1);
  367. }
  368. my @ga = split("%", $gets{$cmd}, -1);
  369. my $nargs = int(@ga)-1;
  370. return "get $name $cmd needs $nargs arguments" if($nargs != int(@a));
  371. return "No $cmd for dummies" if(IsDummy($name));
  372. my $a0 = $a[0];
  373. if($cmd eq "neighborList" ||
  374. $cmd eq "nodeInfo" ||
  375. $cmd eq "routeFor" ||
  376. $cmd eq "isFailedNode") {
  377. $a[0] =~ s/^UNKNOWN_//;
  378. $a[0] = hex($defs{$a[0]}{nodeIdHex})
  379. if($defs{$a[0]} && $defs{$a[0]}{nodeIdHex});
  380. }
  381. my $out = sprintf($gets{$cmd}, @a);
  382. ZWDongle_Write($hash, "", "00".$out);
  383. my $re = "^01".substr($out,0,2); # Start with <01><len><01><CMD>
  384. my ($err, $ret) = ZWDongle_ReadAnswer($hash, $cmd, $re);
  385. return $err if($err);
  386. my $msg="";
  387. $a[0] = $a0 if(defined($a0));
  388. $msg = $ret if($ret);
  389. my @r = map { ord($_) } split("", pack('H*', $ret)) if(defined($ret));
  390. if($cmd eq "nodeList") { ############################
  391. $msg =~ s/^.{10}(.{58}).*/$1/;
  392. $msg = zwlib_parseNeighborList($hash, $msg);
  393. } elsif($cmd eq "caps") { ############################
  394. $msg = sprintf("Vers:%d Rev:%d ", $r[2], $r[3]);
  395. $msg .= sprintf("ManufID:%02x%02x ", $r[4], $r[5]);
  396. $msg .= sprintf("ProductType:%02x%02x ", $r[6], $r[7]);
  397. $msg .= sprintf("ProductID:%02x%02x", $r[8], $r[9]);
  398. my @list;
  399. for my $byte (0..31) {
  400. my $bits = $r[10+$byte];
  401. for my $bit (0..7) {
  402. my $id = sprintf("%02x", $byte*8+$bit+1);
  403. push @list, ($zw_func_id{$id} ? $zw_func_id{$id} : "UNKNOWN_$id")
  404. if($bits & (1<<$bit));
  405. }
  406. }
  407. $msg .= " ".join(" ",@list);
  408. } elsif($cmd eq "homeId") { ############################
  409. $msg = sprintf("HomeId:%s CtrlNodeIdHex:%s",
  410. substr($ret,4,8), substr($ret,12,2));
  411. $hash->{homeId} = substr($ret,4,8);
  412. $hash->{nodeIdHex} = substr($ret,12,2);
  413. $attr{NAME}{homeId} = substr($ret,4,8);
  414. } elsif($cmd eq "version") { ############################
  415. $msg = join("", map { chr($_) } @r[2..13]);
  416. my @type = qw( STATIC_CONTROLLER CONTROLLER ENHANCED_SLAVE
  417. SLAVE INSTALLER NO_INTELLIGENT_LIFE BRIDGE_CONTROLLER);
  418. my $idx = $r[14]-1;
  419. $msg .= " $type[$idx]" if($idx >= 0 && $idx <= $#type);
  420. } elsif($cmd eq "ctrlCaps") { ############################
  421. my @type = qw(SECONDARY OTHER MEMBER PRIMARY SUC);
  422. my @list;
  423. for my $bit (0..7) {
  424. push @list, $type[$bit] if(($r[2] & (1<<$bit)) && $bit < @type);
  425. }
  426. $msg = join(" ", @list);
  427. } elsif($cmd eq "nodeInfo") { ############################
  428. if($r[6] == 0) {
  429. $msg = "node $a[0] is not present";
  430. } else {
  431. $msg = zwlib_parseNodeInfo(@r);
  432. }
  433. } elsif($cmd eq "random") { ############################
  434. return "$name: Cannot generate" if($ret !~ m/^011c01(..)(.*)$/);
  435. $msg = $2; @a = ();
  436. } elsif($cmd eq "isFailedNode") { ############################
  437. $msg = ($r[2]==1)?"yes":"no";
  438. } elsif($cmd eq "neighborList") { ############################
  439. $msg =~ s/^....//;
  440. $msg = zwlib_parseNeighborList($hash, $msg);
  441. } elsif($cmd eq "sucNodeId") { ############################
  442. $msg = ($r[2]==0)?"no":$r[2];
  443. } elsif($cmd eq "routeFor") { ############################
  444. my $homeId = $hash->{homeId};
  445. my @list;
  446. for(my $off=6; $off<16; $off+=2) {
  447. my $dec = hex(substr($msg, $off, 2));
  448. my $hex = sprintf("%02x", $dec);
  449. my $h = ($hex eq $hash->{nodeIdHex} ?
  450. $hash : $modules{ZWave}{defptr}{"$homeId $hex"});
  451. push @list, ($h ? $h->{NAME} : "UNKNOWN_$dec") if($dec);
  452. }
  453. my $f = substr($msg, 17, 1);
  454. push @list, ("at ".($f==1 ? "9.6": ($f==2 ? "40":"100"))."kbps")
  455. if(@list && $f =~ m/[123]/);
  456. $msg = (@list ? join(" ", @list) : "N/A");
  457. }
  458. $cmd .= "_".join("_", @a) if(@a);
  459. readingsSingleUpdate($hash, $cmd, $msg, 0);
  460. return "$name $cmd => $msg";
  461. }
  462. #####################################
  463. sub
  464. ZWDongle_Clear($)
  465. {
  466. my $hash = shift;
  467. # Clear the pipe
  468. for(;;) {
  469. my ($err, undef) = ZWDongle_ReadAnswer($hash, "Clear", "wontmatch");
  470. last if($err && ($err =~ m/^Timeout/ || $err =~ m/No FD/));
  471. }
  472. $hash->{PARTIAL} = "";
  473. }
  474. #####################################
  475. sub
  476. ZWDongle_DoInit($)
  477. {
  478. my $hash = shift;
  479. my $name = $hash->{NAME};
  480. DevIo_SetHwHandshake($hash) if($hash->{USBDev});
  481. $hash->{PARTIAL} = "";
  482. ZWDongle_Clear($hash);
  483. ZWDongle_Get($hash, $name, "caps");
  484. ZWDongle_Get($hash, $name, "ctrlCaps");
  485. ZWDongle_Get($hash, $name, "homeId");
  486. ZWDongle_Get($hash, $name, "sucNodeId");
  487. ZWDongle_Get($hash, $name, ("random", 32)); # Sec relevant
  488. ZWDongle_Set($hash, $name, ("timeouts", 100, 15)); # Sec relevant
  489. ZWDongle_ReadAnswer($hash, "timeouts", "^0106");
  490. # NODEINFO_LISTENING, Generic Static controller, Specific Static Controller, 0
  491. ZWDongle_Set($hash, $name, ("setNIF", 1, 2, 1, 0)); # Sec relevant (?)
  492. readingsSingleUpdate($hash, "state", "Initialized", 1);
  493. return undef;
  494. }
  495. #####################################
  496. # neighborUpdate special: have to serialize. Forum #54574
  497. my @nuStack;
  498. sub
  499. ZWDongle_NUCheck($$$$)
  500. {
  501. my($hash, $fn, $msg, $isWrite) = @_;
  502. if($isWrite) {
  503. return 0 if($msg !~ m/^0048/ || $hash->{calledFromNuCheck});
  504. push @nuStack, "$fn/$msg";
  505. if(@nuStack == 1) {
  506. InternalTimer(gettimeofday+20, sub { # ZME timeout is 9-11s
  507. ZWDongle_NUCheck($hash, undef, "0048xx23", 0); # simulate fail
  508. }, \@nuStack, 0);
  509. }
  510. return (@nuStack > 1);
  511. } else {
  512. return if($msg !~ m/^0048..(..)$/ || $1 eq "21"); # 21: started
  513. shift @nuStack;
  514. RemoveInternalTimer(\@nuStack);
  515. return if(@nuStack == 0);
  516. my @a = split("/", $nuStack[0]);
  517. $hash->{calledFromNuCheck} = 1;
  518. ZWDongle_Write($hash, $a[0], $a[1]);
  519. delete($hash->{calledFromNuCheck});
  520. InternalTimer(gettimeofday+20, sub {
  521. ZWDongle_NUCheck($hash, undef, "0048xx23", 0); # simulate fail
  522. }, \@nuStack, 0);
  523. }
  524. }
  525. #####################################
  526. sub
  527. ZWDongle_Write($$$)
  528. {
  529. my ($hash,$fn,$msg) = @_;
  530. return if(ZWDongle_NUCheck($hash, $fn, $msg, 1));
  531. Log3 $hash, 5, "ZWDongle_Write $msg ($fn)";
  532. # assemble complete message
  533. $msg = sprintf("%02x%s", length($msg)/2+1, $msg);
  534. $msg = "01$msg" . zwlib_checkSum_8($msg);
  535. push @{$hash->{SendStack}}, $msg;
  536. ZWDongle_ProcessSendStack($hash);
  537. }
  538. sub
  539. ZWDongle_shiftSendStack($$$$;$)
  540. {
  541. my ($hash, $reason, $loglevel, $txt, $cbId) = @_;
  542. my $ss = $hash->{SendStack};
  543. my $cmd = $ss->[0];
  544. if($cmd && $reason==0 && $cmd =~ m/^01..0013/) { # ACK for SEND_DATA
  545. Log3 $hash, $loglevel, "$txt, WaitForAck=>2 for $cmd"
  546. if($txt && $cmd);
  547. $hash->{WaitForAck}=2;
  548. } else {
  549. return if($cbId && $cmd && $cbId ne substr($cmd,-4,2));
  550. shift @{$ss};
  551. Log3 $hash, $loglevel, "$txt, removing $cmd from dongle sendstack"
  552. if($txt && $cmd);
  553. $hash->{WaitForAck}=0;
  554. $hash->{SendRetries}=0;
  555. $hash->{MaxSendRetries}=3;
  556. delete($hash->{GotCAN});
  557. }
  558. }
  559. sub
  560. ZWDongle_ProcessSendStack($)
  561. {
  562. my ($hash) = @_;
  563. #Log3 $hash, 1, "ZWDongle_ProcessSendStack: ".@{$hash->{SendStack}}.
  564. # " items on stack, waitForAck ".$hash->{WaitForAck};
  565. RemoveInternalTimer($hash);
  566. my $ts = gettimeofday();
  567. if($hash->{WaitForAck}){
  568. if($hash->{WaitForAck} == 1 && $ts-$hash->{SendTime} >= 1) {
  569. Log3 $hash, 2, "ZWDongle_ProcessSendStack: no ACK, resending message ".
  570. $hash->{SendStack}->[0];
  571. $hash->{SendRetries}++;
  572. $hash->{WaitForAck} = 0;
  573. } elsif($hash->{WaitForAck} == 2 && $ts-$hash->{SendTime} >= 2) {
  574. ZWDongle_shiftSendStack($hash, 1, 4, "no response from device");
  575. } else {
  576. InternalTimer($ts+1, "ZWDongle_ProcessSendStack", $hash, 0);
  577. return;
  578. }
  579. }
  580. if($hash->{SendRetries} > $hash->{MaxSendRetries}){
  581. ZWDongle_shiftSendStack($hash, 1, 1, "ERROR: max send retries reached");
  582. }
  583. return if(!@{$hash->{SendStack}} ||
  584. $hash->{WaitForAck} ||
  585. !DevIo_IsOpen($hash));
  586. my $msg = $hash->{SendStack}->[0];
  587. DevIo_SimpleWrite($hash, $msg, 1);
  588. $hash->{WaitForAck} = 1;
  589. $hash->{SendTime} = $ts;
  590. delete($hash->{GotCAN});
  591. InternalTimer($ts+1, "ZWDongle_ProcessSendStack", $hash, 0);
  592. }
  593. #####################################
  594. # called from the global loop, when the select for hash->{FD} reports data
  595. sub
  596. ZWDongle_Read($@)
  597. {
  598. my ($hash, $local, $regexp) = @_;
  599. my $buf = (defined($local) ? $local : DevIo_SimpleRead($hash));
  600. return "" if(!defined($buf));
  601. my $name = $hash->{NAME};
  602. $buf = unpack('H*', $buf);
  603. # The dongle looses data over USB for some commands(?), and dropping the old
  604. # buffer after a timeout is my only idea of solving this problem.
  605. my $ts = gettimeofday();
  606. my $data = ($hash->{ReadTime} && $ts-$hash->{ReadTime} > 1) ?
  607. $buf : $hash->{PARTIAL}.$buf;
  608. $hash->{ReadTime} = $ts;
  609. #Log3 $name, 5, "ZWDongle RAW buffer: $data";
  610. my $msg;
  611. while(length($data) > 0) {
  612. my $fb = substr($data, 0, 2);
  613. if($fb eq "06") { # ACK
  614. ZWDongle_shiftSendStack($hash, 0, 5, "ACK received");
  615. $data = substr($data, 2);
  616. next;
  617. }
  618. if($fb eq "15") { # NACK
  619. Log3 $name, 4, "ZWDongle_Read $name: NACK received";
  620. $hash->{WaitForAck} = 0;
  621. $hash->{SendRetries}++;
  622. $data = substr($data, 2);
  623. next;
  624. }
  625. if($fb eq "18") { # CAN
  626. Log3 $name, 4, "ZWDongle_Read $name: CAN received";
  627. $hash->{MaxSendRetries}++ if($hash->{MaxSendRetries}<7);
  628. $data = substr($data, 2);
  629. $hash->{GotCAN} = 1;
  630. if(!$init_done) { # InternalTimer wont work
  631. $hash->{WaitForAck} = 0;
  632. $hash->{SendRetries}++;
  633. select(undef, undef, undef, 0.1);
  634. }
  635. next;
  636. }
  637. if($fb ne "01") { # SOF
  638. Log3 $name, 1, "$name: SOF missing (got $fb instead of 01)";
  639. if(++$hash->{nrNAck} < 5){
  640. Log3 $name, 5, "ZWDongle_Read SOF Error -> sending NACK";
  641. DevIo_SimpleWrite($hash, "15", 1); # Send NACK
  642. }
  643. $data="";
  644. last;
  645. }
  646. my $len = substr($data, 2, 2);
  647. my $l = hex($len)*2;
  648. last if(!$l || length($data) < $l+4); # Message not yet complete
  649. $msg = substr($data, 4, $l-2);
  650. my $rcs = substr($data, $l+2, 2); # Received Checksum
  651. $data = substr($data, $l+4);
  652. my $ccs = zwlib_checkSum_8("$len$msg"); # Computed Checksum
  653. if($rcs ne $ccs) {
  654. Log3 $name, 1,
  655. "$name: wrong checksum: received $rcs, computed $ccs for $len$msg";
  656. if(++$hash->{nrNAck} < 5) {
  657. Log3 $name, 5, "ZWDongle_Read wrong checksum -> sending NACK";
  658. DevIo_SimpleWrite($hash, "15", 1);
  659. }
  660. $msg = undef;
  661. $data="";
  662. next;
  663. }
  664. $hash->{nrNAck} = 0;
  665. next if($msg !~ m/^(..)(..)/);
  666. my $ztp = ($1 eq "00" ? "request" : ($1 eq "01" ? "answer" : "unknown $1"));
  667. my $zfi = $zw_func_id{$2} ? $zw_func_id{$2} : "unknown $2";
  668. Log3 $name, 4, "ZWDongle_Read $name: rcvd $msg ($ztp $zfi), sending ACK";
  669. DevIo_SimpleWrite($hash, "06", 1);
  670. ZWDongle_shiftSendStack($hash, 1, 5, "device ack reveived", $1)
  671. if($msg =~ m/^0013(..)/);
  672. last if(defined($local) && (!defined($regexp) || ($msg =~ m/$regexp/)));
  673. $hash->{PARTIAL} = $data; # Recursive call by ZWave get, Forum #37418
  674. ZWDongle_Parse($hash, $name, $msg) if($init_done);
  675. $data = $hash->{PARTIAL};
  676. $msg = undef;
  677. }
  678. $hash->{PARTIAL} = $data;
  679. # trigger sending of next message
  680. ZWDongle_ProcessSendStack($hash) if(length($data) == 0);
  681. return $msg if(defined($local));
  682. return undef;
  683. }
  684. #####################################
  685. # This is a direct read for commands like get
  686. sub
  687. ZWDongle_ReadAnswer($$$)
  688. {
  689. my ($hash, $arg, $regexp) = @_;
  690. Log3 $hash, 4, "ZWDongle_ReadAnswer arg:$arg regexp:".($regexp ? $regexp:"");
  691. return ("No FD (dummy device?)", undef)
  692. if(!$hash || ($^O !~ /Win/ && !defined($hash->{FD})));
  693. my $to = ($hash->{RA_Timeout} ? $hash->{RA_Timeout} : 1);
  694. for(;;) {
  695. my $buf;
  696. if($^O =~ m/Win/ && $hash->{USBDev}) {
  697. $hash->{USBDev}->read_const_time($to*1000); # set timeout (ms)
  698. # Read anstatt input sonst funzt read_const_time nicht.
  699. $buf = $hash->{USBDev}->read(999);
  700. if(length($buf) == 0) {
  701. if($hash->{GotCAN}) {
  702. ZWDongle_ProcessSendStack($hash);
  703. next;
  704. }
  705. return ("Timeout reading answer for get $arg", undef);
  706. }
  707. } else {
  708. if(!$hash->{FD}) {
  709. Log3 $hash, 1, "ZWDongle_ReadAnswer: device lost";
  710. return ("Device lost when reading answer for get $arg", undef);
  711. }
  712. my $rin = '';
  713. vec($rin, $hash->{FD}, 1) = 1;
  714. my $nfound = select($rin, undef, undef, $to);
  715. if($nfound < 0) {
  716. my $err = $!;
  717. Log3 $hash, 5, "ZWDongle_ReadAnswer: nfound < 0 / err:$err";
  718. next if ($err == EAGAIN() || $err == EINTR() || $err == 0);
  719. DevIo_Disconnected($hash);
  720. return("ZWDongle_ReadAnswer $arg: $err", undef);
  721. }
  722. if($nfound == 0){
  723. Log3 $hash, 5, "ZWDongle_ReadAnswer: select timeout";
  724. if($hash->{GotCAN}) {
  725. ZWDongle_ProcessSendStack($hash);
  726. next;
  727. }
  728. return ("Timeout reading answer for get $arg", undef);
  729. }
  730. $buf = DevIo_SimpleRead($hash);
  731. if(!defined($buf)){
  732. Log3 $hash, 1,"ZWDongle_ReadAnswer: no data read";
  733. return ("No data", undef);
  734. }
  735. }
  736. my $ret = ZWDongle_Read($hash, $buf, $regexp);
  737. if(defined($ret)){
  738. Log3 $hash, 4, "ZWDongle_ReadAnswer for $arg: $ret";
  739. return (undef, $ret);
  740. }
  741. }
  742. }
  743. sub
  744. ZWDongle_Parse($$$)
  745. {
  746. my ($hash, $name, $rmsg) = @_;
  747. if(!defined($hash->{STATE}) ||
  748. ReadingsVal($name, "state", "") ne "Initialized"){
  749. Log3 $hash, 4,"ZWDongle_Parse $rmsg: dongle not yet initialized";
  750. return;
  751. }
  752. $hash->{"${name}_MSGCNT"}++;
  753. $hash->{"${name}_TIME"} = TimeNow();
  754. $hash->{RAWMSG} = $rmsg;
  755. $hash->{SendTime}-- # Retry sending after a "real" msg from the dongle
  756. if($hash->{GotCAN} && $rmsg !~ m/^(0113|0013)/);
  757. my %addvals = (RAWMSG => $rmsg);
  758. ZWDongle_NUCheck($hash, undef, $rmsg, 0);
  759. Dispatch($hash, $rmsg, \%addvals);
  760. }
  761. #####################################
  762. sub
  763. ZWDongle_Attr($$$$)
  764. {
  765. my ($cmd, $name, $attr, $value) = @_;
  766. my $hash = $defs{$name};
  767. $attr = "" if(!$attr);
  768. if($attr eq "disable") {
  769. if($cmd eq "set" && ($value || !defined($value))) {
  770. DevIo_CloseDev($hash) if(!AttrVal($name,"dummy",undef));
  771. readingsSingleUpdate($hash, "state", "disabled", 1);
  772. } else {
  773. if(AttrVal($name,"dummy",undef)) {
  774. readingsSingleUpdate($hash, "state", "dummy", 1);
  775. return;
  776. }
  777. DevIo_OpenDev($hash, 0, "ZWDongle_DoInit");
  778. }
  779. } elsif($attr eq "homeId" && $cmd eq "set") {
  780. $hash->{homeId} = $value;
  781. } elsif($attr eq "networkKey" && $cmd eq "set") {
  782. if(!$value || $value !~ m/^[0-9A-F]{32}$/i) {
  783. return "attr $name networkKey: not a hex string with a length of 32";
  784. }
  785. return;
  786. }
  787. return undef;
  788. }
  789. #####################################
  790. sub
  791. ZWDongle_Ready($)
  792. {
  793. my ($hash) = @_;
  794. return undef if (IsDisabled($hash->{NAME}));
  795. return DevIo_OpenDev($hash, 1, "ZWDongle_DoInit")
  796. if(ReadingsVal($hash->{NAME}, "state","") eq "disconnected");
  797. # This is relevant for windows/USB only
  798. my $po = $hash->{USBDev};
  799. if($po) {
  800. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  801. if(!defined($InBytes)) {
  802. DevIo_Disconnected($hash);
  803. return 0;
  804. }
  805. return ($InBytes>0);
  806. }
  807. return 0;
  808. }
  809. 1;
  810. =pod
  811. =item summary connection to standard ZWave controller
  812. =item summary_DE Anbindung von standard ZWave Controller
  813. =begin html
  814. <a name="ZWDongle"></a>
  815. <h3>ZWDongle</h3>
  816. <ul>
  817. This module serves a ZWave dongle, which is attached via USB or TCP/IP, and
  818. enables the use of ZWave devices (see also the <a href="#ZWave">ZWave</a>
  819. module). It was tested wit a Goodway WD6001, but since the protocol is
  820. standardized, it should work with other devices too. A notable exception is
  821. the USB device from Merten.
  822. <br><br>
  823. <a name="ZWDongledefine"></a>
  824. <b>Define</b>
  825. <ul>
  826. <code>define &lt;name&gt; ZWDongle &lt;device&gt;</code>
  827. <br>
  828. <br>
  829. Upon initial connection the module will get the homeId of the attached
  830. device. Since the DevIo module is used to open the device, you can also use
  831. devices connected via TCP/IP. See <a href="#CULdefine">this</a> paragraph on
  832. device naming details.
  833. <br>
  834. Example:
  835. <ul>
  836. <code>define zwdongle_1 ZWDongle /dev/cu.PL2303-000014FA@115200</code><br>
  837. </ul>
  838. </ul>
  839. <br>
  840. <a name="ZWDongleset"></a>
  841. <b>Set</b>
  842. <ul>
  843. <li>addNode on|onNw|onSec|onNwSec|off<br>
  844. Activate (or deactivate) inclusion mode. The controller (i.e. the dongle)
  845. will accept inclusion (i.e. pairing/learning) requests only while in this
  846. mode. After activating inclusion mode usually you have to press a switch
  847. three times within 1.5 seconds on the node to be included into the network
  848. of the controller. If autocreate is active, a fhem device will be created
  849. after inclusion. "on" activates standard inclusion. "onNw" activates network
  850. wide inclusion (only SDK 4.5-4.9, SDK 6.x and above).<br>
  851. If onSec/onNwSec is specified, the ZWDongle networkKey ist set, and the
  852. device supports the SECURITY class, then a secure inclusion is attempted.
  853. </li>
  854. <li>backupCreate 16k|32k|64k|128k|256k<br>
  855. read out the NVRAM of the ZWDongle, and store it in a file called
  856. &lt;ZWDongle_Name&gt;.bin in the modpath folder. Since the size of the
  857. NVRAM is currently unknown to FHEM, you have to specify the size. The
  858. ZWave.me ZME_UZB1 Stick seems to have 256k of NVRAM. Note: writing the file
  859. takes some time, usually about 10s for each 64k (and significantly longer
  860. on Windows), and FHEM is blocked during this time.
  861. </li>
  862. <li>backupRestore<br>
  863. Restore the file created by backupCreate. Restoring the file takes about
  864. the same time as saving it, and FHEM is blocked during this time.
  865. Note / Important: this function is not yet tested for older devices using
  866. the MEMORY functions.
  867. </li>
  868. <li>controllerChange on|stop|stopFailed<br>
  869. Add a controller to the current network and transfer role as primary to it.
  870. Invoking controller is converted to secondary.<br>
  871. stop: stop controllerChange<br>
  872. stopFailed: stop controllerChange and report an error
  873. </li>
  874. <li>createNewPrimary on|stop|stopFailed<br>
  875. Add a controller to the current network as a replacement for an old
  876. primary. Command can be invoked only by a secondary configured as basic
  877. SUC<br>
  878. stop: stop createNewPrimary<br>
  879. stopFailed: stop createNewPrimary and report an error
  880. </li>
  881. <li>createNode &lt;decimal nodeId&gt;<br>
  882. Request the class information for the specified node, and create
  883. a FHEM device upon reception of the answer. Used to create FHEM devices for
  884. nodes included with another software or if the fhem.cfg got lost. For the
  885. node id see the get nodeList command below. Note: the node must be "alive",
  886. i.e. for battery based devices you have to press the "wakeup" button 1-2
  887. seconds before entering this command in FHEM.
  888. </li>
  889. <li>factoryReset yes<br>
  890. Reset controller to default state.
  891. Erase all node and routing infos, assign a new random homeId.
  892. To control a device it must be re-included and re-configured.<br>
  893. !Use this with care AND only if You know what You do!<br>
  894. Note: the corresponding FHEM devices have to be deleted manually.
  895. </li>
  896. <li>learnMode on|onNw|disable<br>
  897. Add or remove controller to/from an other network.
  898. Assign a homeId, nodeId and receive/store nodeList and routing infos.
  899. </li>
  900. <li>removeFailedNode &lt;decimal nodeId&gt;<br>
  901. Remove non-responding node -that must be on the failed node list-
  902. from the routing table in controller. Instead, always use removeNode if
  903. possible. Note: the corresponding FHEM device have to be deleted manually.
  904. </li>
  905. <li>removeNode onNw|on|off<br>
  906. Activate (or deactivate) exclusion mode. "on" activates standard exclusion.
  907. "onNw" activates network wide exclusion (only SDK 4.5-4.9, SDK 6.x and
  908. above). Note: the corresponding FHEM device have to be deleted
  909. manually.
  910. </li>
  911. <li>reopen<br>
  912. First close and then open the device. Used for debugging purposes.
  913. </li>
  914. <li>replaceFailedNode &lt;decimal nodeId&gt;<br>
  915. Replace a non-responding node with a new one. The non-responding node
  916. must be on the failed node list.</li>
  917. <li>sucNodeId &lt;decimal nodeId&gt; &lt;sucState&gt;
  918. &lt;capabilities&gt;<br>
  919. &lt;Configure a controller node to be a SUC/SIS or not.<br>
  920. &lt;nodeId&gt;: decimal nodeId to be SUC/SIS<br>
  921. &lt;sucState&gt;: 0 = deactivate; 1 = activate<br>
  922. &lt;capabilities&gt;: 0 = basic SUC; 1 = SIS
  923. </li>
  924. <li>sucRequestUpdate &lt;decimal nodeId of SUC/SIS&gt;<br>
  925. Request network updates from SUC/SIS. Primary do not need it.
  926. </li>
  927. <li>sucSendNodeId &lt;decimal nodeId&gt;<br>
  928. Send SUC/SIS nodeId to the specified decimal controller nodeId.
  929. </li>
  930. </ul>
  931. <br>
  932. <a name="ZWDongleget"></a>
  933. <b>Get</b>
  934. <ul>
  935. <li>homeId<br>
  936. return the six hex-digit homeId of the controller.
  937. </li>
  938. <li>isFailedNode &lt;decimal nodeId&gt;<br>
  939. return if a node is stored in the failed node list.
  940. </li>
  941. <li>caps, ctrlCaps, version<br>
  942. return different controller specific information. Needed by developers
  943. only.
  944. </li>
  945. <li>neighborList [excludeDead] [onlyRep] &lt;decimal nodeId&gt;<br>
  946. return neighborList of the decimal nodeId.<br>
  947. With onlyRep the result will include only nodes with repeater
  948. functionality.
  949. </li>
  950. <li>nodeInfo &lt;decimal nodeId&gt;<br>
  951. return node specific information.
  952. Needed by developers only.
  953. </li>
  954. <li>nodeList<br>
  955. return the list of included nodenames or UNKNOWN_id (decimal id), if there
  956. is no corresponding device in FHEM. Can be used to recreate FHEM-nodes with
  957. the createNode command.
  958. </li>
  959. <li>random &lt;N&gt;<br>
  960. request &lt;N&gt; random bytes from the controller.
  961. </li>
  962. <li>raw &lt;hex&gt;<br>
  963. Send raw data &lt;hex&gt; to the controller. Developer only.
  964. </li>
  965. <li>routeFor node<br>
  966. request priority routing for node
  967. </li>
  968. <li>sucNodeId<br>
  969. return the currently registered decimal SUC nodeId.
  970. </li>
  971. </ul>
  972. <br>
  973. <a name="ZWDongleattr"></a>
  974. <b>Attributes</b>
  975. <ul>
  976. <li><a href="#dummy">dummy</a></li>
  977. <li><a href="#do_not_notify">do_not_notify</a></li>
  978. <li><a href="#model">model</a></li>
  979. <li><a href="#disable">disable</a></li>
  980. <li><a name="helpSites">helpSites</a><br>
  981. Comma separated list of Help Sites to get device pictures from or to
  982. show a link to in the detailed window. Valid values are pepper
  983. and alliance.
  984. </li>
  985. <li><a name="homeId">homeId</a><br>
  986. Stores the homeId of the dongle. Is a workaround for some buggy dongles,
  987. wich sometimes report a wrong/nonexisten homeId (Forum #35126)</li>
  988. <li><a name="networkKey">networkKey</a><br>
  989. Needed for secure inclusion, hex string with length of 32
  990. </li>
  991. <li><a name="neighborListPos">neighborListPos</a><br>
  992. Used by the "Show neighbor map" function in the FHEMWEB ZWDongle detail
  993. screen to store the position of the box.
  994. </li>
  995. <li><a name="neighborListFmt">neighborListFmt</a><br>
  996. Used by the "Show neighbor map" function in the FHEMWEB ZWDongle detail
  997. screen. The value is a perl hash, specifiying the values for the keys
  998. txt, img and title. In the value each word is replaced by the
  999. corresponding Internal, Reading or Attribute of the device, if there is
  1000. one to replace. Default is
  1001. <ul><code>
  1002. { txt=>"NAME", img=>"IMAGE", title=>"Time to ack: timeToAck" }
  1003. </code></ul>
  1004. </li>
  1005. </ul>
  1006. <br>
  1007. <a name="ZWDongleevents"></a>
  1008. <b>Generated events:</b>
  1009. <ul>
  1010. <br><b>General</b>
  1011. <li>UNDEFINED ZWave_${type6}_$id ZWave $homeId $id $classes</li>
  1012. <li>ZW_APPLICATION_UPDATE addDone $nodeId</li>
  1013. <li>ZW_APPLICATION_UPDATE deleteDone $nodeId</li>
  1014. <li>ZW_APPLICATION_UPDATE sudId $nodeId</li>
  1015. <br><b>addNode</b>
  1016. <li>ZW_ADD_NODE_TO_NETWORK [learnReady|nodeFound|slave|controller|
  1017. done|failed]</li>
  1018. <br><b>controllerChange</b>
  1019. <li>ZW_CONTROLLER_CHANGE [learnReady|nodeFound|controller|done|failed]</li>
  1020. <br><b>createNewPrimary</b>
  1021. <li>ZW_CREATE_NEW_PRIMARY [learnReady|nodeFound|controller|done|failed]</li>
  1022. <br><b>factoryReset</b>
  1023. <li>ZW_SET_DEFAULT [done]</li>
  1024. <br><b>learnMode</b>
  1025. <li>ZW_SET_LEARN_MODE [started|done|failed|deleted]</li>
  1026. <br><b>neighborUpdate</b>
  1027. <li>ZW_REQUEST_NODE_NEIGHBOR_UPDATE [started|done|failed]</li>
  1028. <br><b>removeFailedNode</b>
  1029. <li>ZW_REMOVE_FAILED_NODE_ID
  1030. [failedNodeRemoveStarted|notPrimaryController|noCallbackFunction|
  1031. failedNodeNotFound|failedNodeRemoveProcessBusy|
  1032. failedNodeRemoveFail|nodeOk|nodeRemoved|nodeNotRemoved]</li>
  1033. <br><b>removeNode</b>
  1034. <li>ZW_REMOVE_NODE_FROM_NETWORK
  1035. [learnReady|nodeFound|slave|controller|done|failed]</li>
  1036. <br><b>replaceFailedNode</b>
  1037. <li>ZW_REPLACE_FAILED_NODE
  1038. [failedNodeRemoveStarted|notPrimaryController|noCallbackFunction|
  1039. failedNodeNotFound|failedNodeRemoveProcessBusy|
  1040. failedNodeRemoveFail|nodeOk|failedNodeReplace|
  1041. failedNodeReplaceDone|failedNodeRemoveFailed]</li>
  1042. <br><b>sucNetworkUpdate</b>
  1043. <li>ZW_REQUEST_NETWORK_UPDATE [started|selfOrNoSUC|done|abort|wait|diabled|
  1044. overflow]</li>
  1045. <br><b>sucNodeId</b>
  1046. <li>ZW_SET_SUC_NODE_ID [ok|failed|callbackSucceeded|callbackFailed]</li>
  1047. <br><b>sucRouteAdd</b>
  1048. <li>ZW_ASSIGN_SUC_RETURN_ROUTE [started|alreadyActive|transmitOk|
  1049. transmitNoAck|transmitFail|transmitNotIdle|
  1050. transmitNoRoute]</li>
  1051. <br><b>sucRouteDel</b>
  1052. <li>ZW_DELETE_SUC_RETURN_ROUTE [started|alreadyActive|transmitOk|
  1053. transmitNoAck|transmitFail|transmitNotIdle|
  1054. transmitNoRoute]</li>
  1055. <br><b>sucSendNodeId</b>
  1056. <li>ZW_SEND_SUC_ID [started|alreadyActive|transmitOk|
  1057. transmitNoAck|transmitFail|transmitNotIdle|
  1058. transmitNoRoute]</li>
  1059. </ul>
  1060. </ul>
  1061. =end html
  1062. =cut