MESH SDK Custom Tag "IRKit" Data

Object
keyvalue
formatVersion"1.0"
tagData
Object
keyvalue
name"IRKit"
icon"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAdIklEQVR4X..."
description"MESH IRKit Control Tag"
functions
Array(2)
indexvalue
0
Object
keyvalue
id"function_0"
name"Local"
connector
Object
keyvalue
inputs
Array(2)
indexvalue
0
Object
keyvalue
label"Learn"
1
Object
keyvalue
label"Send"
outputs
Array(1)
indexvalue
0
Object
keyvalue
label""
properties
Array(1)
indexvalue
0
Object
keyvalue
name"IP Address"
referenceName"ip_addr"
type"string"
defaultValue"192.168.0.100"
extension
Object
keyvalue
initialize
  1.  
  2. /* Runtime Values */
  3.  
  4. // Definitions
  5. var _IRKitTag_defines = new Array();
  6. _IRKitTag_defines.inputTypeLearn = 0;
  7. _IRKitTag_defines.inputTypeSend = 1;
  8.  
  9. // Register runtimeValues
  10. var _runtimeValues = {
  11. IRData : "",
  12. inputType : _IRKitTag_defines.inputTypeLearn,
  13. IRKitTag_defines : _IRKitTag_defines
  14. };
  15.  
  16. return {
  17. runtimeValues : _runtimeValues
  18. }
receive
  1.  
  2. /* For Connectors */
  3.  
  4. // Save input type.
  5. if ( index == runtimeValues.IRKitTag_defines.inputTypeLearn ) {
  6. // input from "Learn" connector
  7. // log( "[IRKit] input from \"Learn\" connector" );
  8. runtimeValues.inputType = runtimeValues.IRKitTag_defines.inputTypeLearn;
  9. }else if ( index == runtimeValues.IRKitTag_defines.inputTypeSend ) {
  10. // input from "Send" connector
  11. // log( "[IRKit] input from \"Send\" connector" );
  12. runtimeValues.inputType = runtimeValues.IRKitTag_defines.inputTypeSend;
  13. }else{
  14. // Illegal Input
  15. // log( "[IRKit] Illegal Input : index [" + index + "]" );
  16. }
  17.  
execute
  1.  
  2. var irkit_ip_addr = properties.ip_addr;
  3.  
  4. switch( runtimeValues.inputType ){
  5. default: // Fall through.
  6. case runtimeValues.IRKitTag_defines.inputTypeLearn:
  7. // log( "[IRKit] Learn method is specified." );
  8. learn_ir_data( irkit_ip_addr, runtimeValues );
  9. break;
  10. case runtimeValues.IRKitTag_defines.inputTypeSend:
  11. // log( "[IRKit] Send method is specified" );
  12. if( runtimeValues.IRData != "" ){
  13. send_ir_data( irkit_ip_addr, runtimeValues.IRData );
  14. }else{
  15. log( "[IRKit] Since IR data is vacant, send request was ignored." );
  16. }
  17. break;
  18. }
  19.  
  20. function learn_ir_data( ip_addr, data ){
  21. // GET
  22. ajax({
  23. url:"http://" + ip_addr + "/messages",
  24. type:"get",
  25. success:function( contents ) {
  26. // log( "[IRKit] GET success. contents is " + contents );
  27. data.IRData = contents;
  28. callbackSuccess();
  29. },
  30. headers: {'X-Requested-With': 'curl'},
  31. error:function( request, errorMessage ) {
  32. log( "[IRKit] GET error." + errorMessage ) ;
  33. callbackError({});
  34. }
  35. });
  36. }
  37.  
  38. function send_ir_data( ip_addr, ir_data ){
  39. ajax({
  40. url:"http://" + ip_addr + "/messages",
  41. data:ir_data,
  42. type:"post",
  43.  
  44. success:function( contents ) {
  45. // log( "[IRKit] POST success." );
  46. callbackSuccess();
  47. },
  48. headers: {'X-Requested-With': 'curl'},
  49. error:function( request, errorMessage ) {
  50. log( "[IRKit] POST error." + errorMessage );
  51. callbackError({});
  52. }
  53. });
  54. }
  55.  
  56. return {
  57. resultType:"pause"
  58. }
result
  1.  
1
Object
keyvalue
id"function_1"
name"Internet"
connector
Object
keyvalue
inputs
Array(3)
indexvalue
0
Object
keyvalue
label"Register"
1
Object
keyvalue
label"Learn"
2
Object
keyvalue
label"Send"
outputs
Array(1)
indexvalue
0
Object
keyvalue
label""
properties
Array(1)
indexvalue
0
Object
keyvalue
name"IP Address"
referenceName"ip_addr"
type"string"
defaultValue"192.168.0.100"
extension
Object
keyvalue
initialize
  1.  
  2. /* Runtime Values */
  3.  
  4. // Definitions
  5. var _IRKitTag_defines = new Array();
  6. _IRKitTag_defines.inputTypeRegister = 0;
  7. _IRKitTag_defines.inputTypeLearn = 1;
  8. _IRKitTag_defines.inputTypeSend = 2;
  9.  
  10. // Register runtimeValues
  11. var _runtimeValues = {
  12. IRData : "",
  13. inputType : _IRKitTag_defines.inputTypeLearn,
  14. clienttoken : "",
  15. deviceid : "",
  16. clientkey : "",
  17. IRKitTag_defines : _IRKitTag_defines
  18. };
  19.  
  20. return {
  21. runtimeValues : _runtimeValues
  22. }
receive
  1.  
  2. /* For Connectors */
  3.  
  4. // Save input type.
  5. if ( index == runtimeValues.IRKitTag_defines.inputTypeLearn ) {
  6. // input from "Learn" connector
  7. // log( "[IRKit] input from \"Learn\" connector" );
  8. runtimeValues.inputType = runtimeValues.IRKitTag_defines.inputTypeLearn;
  9. }else if ( index == runtimeValues.IRKitTag_defines.inputTypeSend ) {
  10. // input from "Send" connector
  11. // log( "[IRKit] input from \"Send\" connector" );
  12. runtimeValues.inputType = runtimeValues.IRKitTag_defines.inputTypeSend;
  13. }else if ( index == runtimeValues.IRKitTag_defines.inputTypeRegister ) {
  14. // input from "Register" connector
  15. // log( "[IRKit] input from \"Register\" connector" );
  16. runtimeValues.inputType = runtimeValues.IRKitTag_defines.inputTypeRegister;
  17. }else{
  18. // Illegal Input
  19. // log( "[IRKit] Illegal Input : index [" + index + "]" );
  20. }
  21.  
execute
  1.  
  2. var irkit_ip_addr = properties.ip_addr;
  3.  
  4. switch( runtimeValues.inputType ){
  5. default: // Fall through.
  6. case runtimeValues.IRKitTag_defines.inputTypeLearn:
  7. // log( "[IRKit] Learn method is specified." );
  8. learn_ir_data( irkit_ip_addr, runtimeValues );
  9. break;
  10. case runtimeValues.IRKitTag_defines.inputTypeRegister:
  11. // log( "[IRKit] Register method is specified." );
  12. register_for_internet_api( irkit_ip_addr, runtimeValues );
  13. break;
  14. case runtimeValues.IRKitTag_defines.inputTypeSend:
  15. // log( "[IRKit] Send method is specified" );
  16. if( runtimeValues.IRData != "" ){
  17. send_ir_data( irkit_ip_addr, runtimeValues.IRData );
  18. }else{
  19. log( "[IRKit] Since IR data is vacant, send request was ignored." );
  20. }
  21. break;
  22. }
  23.  
  24. function learn_ir_data( ip_addr, data ){
  25. // GET
  26. ajax({
  27. url:"https://api.getirkit.com/1/messages",
  28. type:"get",
  29. data: {
  30. clientkey: runtimeValues.clientkey,
  31. clear: 1
  32. },
  33. success:function( contents ) {
  34. // log( "[IRKit] GET success. contents is " + JSON.stringify( contents ) );
  35. // log( "[IRKit] gotten IR data is " + JSON.stringify( contents.message ) );
  36. data.IRData = contents.message;
  37. callbackSuccess();
  38. },
  39. error:function( request, errorMessage ) {
  40. log( "[IRKit] GET error." + errorMessage ) ;
  41. callbackError({});
  42. }
  43. });
  44. }
  45.  
  46. function send_ir_data( ip_addr, ir_data ){
  47. ajax({
  48. url:"https://api.getirkit.com/1/messages",
  49. type:"post",
  50. data: {
  51. clientkey: runtimeValues.clientkey,
  52. deviceid: runtimeValues.deviceid,
  53. message: JSON.stringify( ir_data )
  54. },
  55. success:function( contents ) {
  56. // log( "[IRKit] POST success." );
  57. callbackSuccess();
  58. },
  59. error:function( request, errorMessage ) {
  60. log( "[IRKit] POST error." + errorMessage );
  61. callbackError({});
  62. }
  63. });
  64. }
  65.  
  66. function register_for_internet_api( ip_addr, data ){
  67. ajax({
  68. url:"http://" + ip_addr + "/keys",
  69. data:'',
  70. type:"post",
  71.  
  72. success:function( contents ) {
  73. // log( "[IRKit] /keys POST success. response is " + contents );
  74. // log( "[IRKit] clienttoken is " + JSON.parse(contents).clienttoken );
  75. runtimeValues.clienttoken = JSON.parse(contents).clienttoken;
  76. ajax({
  77. url:"https://api.getirkit.com/1/keys",
  78. data:'clienttoken=' + runtimeValues.clienttoken,
  79. type:"post",
  80.  
  81. success:function( contents ) {
  82. // log( "[IRKit] api.getirkit.com/1/keys POST success. response is " + JSON.stringify( contents ) );
  83. // log( "[IRKit] deviceid is " + contents.deviceid );
  84. runtimeValues.deviceid = contents.deviceid;
  85. // log( "[IRKit] clientkey is " + contents.clientkey );
  86. runtimeValues.clientkey = contents.clientkey;
  87. callbackSuccess();
  88. },
  89. error:function( request, errorMessage ) {
  90. log( "[IRKit] api.getirkit.com/1/keys POST error." + errorMessage );
  91. callbackError({});
  92. }
  93. });
  94. },
  95. headers: {'X-Requested-With': 'curl'},
  96. error:function( request, errorMessage ) {
  97. log( "[IRKit] /keys POST error." + errorMessage );
  98. callbackError({});
  99. }
  100. });
  101. }
  102.  
  103. return {
  104. resultType:"pause"
  105. }
result
  1.