wifinetwork.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 'use strict';
  2. goog.provide('Blockly.Blocks.wifinetwork');
  3. goog.require('Blockly.Blocks');
  4. goog.require('Blockly.Types');
  5. Blockly.Blocks.wifinetwork.HUE = "#572b7a";
  6. /*************************
  7. * version 1 *
  8. *************************/
  9. Blockly.Blocks['wifiNetwork_connect_setup'] = {
  10. init: function() {
  11. this.appendDummyInput()
  12. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  13. .appendField(new Blockly.FieldImage("./../blockly/media/wifi-network.png", 50, 40, "0"));
  14. this.appendDummyInput()
  15. .appendField(Blockly.Msg.WIFINETWORK_CONNECT)
  16. this.appendValueInput("SSID")
  17. .setCheck("Text")
  18. .appendField(Blockly.Msg.WIFINETWORK_CONNECT_SSID)
  19. this.appendValueInput("PW")
  20. .setCheck("Text")
  21. .appendField(Blockly.Msg.WIFINETWORK_CONNECT_PW);
  22. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  23. // this.setPreviousStatement(true, null);
  24. // this.setNextStatement(true, null);
  25. // this.setInputsInline(true);
  26. this.setTooltip("");
  27. this.setHelpUrl("");
  28. },
  29. }
  30. /*get device mac*/
  31. Blockly.Blocks['wifiNetwork_getMacAddr'] = {
  32. init: function() {
  33. this.appendDummyInput()
  34. .appendField(Blockly.Msg.WIFINETWORK_GETMACADDR);
  35. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  36. this.setOutput(true, Blockly.Types.TEXT.output);
  37. this.setTooltip("");
  38. this.setHelpUrl("");
  39. },
  40. };
  41. /*get gateway ip*/
  42. Blockly.Blocks['wifiNetwork_getGatewayIp'] = {
  43. init: function() {
  44. this.appendDummyInput()
  45. .appendField(Blockly.Msg.WIFINETWORK_GETGATEWAYIP);
  46. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  47. this.setOutput(true, Blockly.Types.TEXT.output);
  48. this.setTooltip("");
  49. this.setHelpUrl("");
  50. },
  51. };
  52. /*
  53. *ESP8266 wifi Access Point
  54. *provide a LAN with SSID and PW set in advance
  55. */
  56. Blockly.Blocks['wifiNetwork_AP_setup'] = {
  57. init: function() {
  58. this.appendDummyInput()
  59. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  60. .appendField(new Blockly.FieldImage("./../blockly/media/wifi-network.png", 50, 40, "0"));
  61. this.appendDummyInput()
  62. .appendField(Blockly.Msg.WIFINETWORK_AP_SETUP)
  63. this.appendValueInput("SSID")
  64. .setCheck("Text")
  65. .appendField(Blockly.Msg.WIFINETWORK_AP_SSID)
  66. this.appendValueInput("PW")
  67. .setCheck("Text")
  68. .appendField(Blockly.Msg.WIFINETWORK_AP_PW);
  69. this.setColour(50);
  70. // this.setPreviousStatement(true, null);
  71. // this.setNextStatement(true, null);
  72. // this.setInputsInline(true);
  73. this.setTooltip("");
  74. this.setHelpUrl("");
  75. },
  76. };
  77. /*************************
  78. * version 2 *
  79. * eaysmode *
  80. *************************/
  81. /*wifi easymode
  82. *setup for WiFi network
  83. */
  84. Blockly.Blocks['wifiNetwork_network'] = {
  85. init: function() {
  86. this.appendDummyInput()
  87. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  88. .appendField(new Blockly.FieldImage("./../blockly/media/main-wifi.png", 50, 40, "0"));
  89. this.appendDummyInput()
  90. .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_TITLE)
  91. this.appendDummyInput()
  92. .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_SSID)
  93. .appendField(new Blockly.FieldTextInput("ENTER_YOUR_SSID"), "wifi_ssid")
  94. this.appendDummyInput()
  95. .appendField(" " + Blockly.Msg.WIFIEASYMODE_NETWORK_PW)
  96. .appendField(new Blockly.FieldTextInput("ENTER_YOUR_PASSWORD"), "wifi_pw")
  97. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  98. this.setTooltip("");
  99. this.setHelpUrl("");
  100. },
  101. };
  102. Blockly.Blocks['wifiNetwork_AP'] = {
  103. init: function() {
  104. this.appendDummyInput()
  105. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  106. .appendField(new Blockly.FieldImage("./../blockly/media/wifi-network.png", 50, 40, "0"));
  107. this.appendDummyInput()
  108. .appendField(Blockly.Msg.WIFINETWORK_AP_SETUP)
  109. this.appendDummyInput()
  110. .appendField(" " + Blockly.Msg.WIFINETWORK_AP_SSID)
  111. .appendField(new Blockly.FieldTextInput("ENTER_YOUR_SSID"), "SSID")
  112. this.appendDummyInput()
  113. .appendField(" " + Blockly.Msg.WIFINETWORK_AP_PW)
  114. .appendField(new Blockly.FieldTextInput("ENTER_YOUR_PASSWORD"), "PW")
  115. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  116. this.setTooltip("");
  117. this.setHelpUrl("");
  118. },
  119. /**
  120. * Called whenever anything on the workspace changes.
  121. * It checks the number of password and warn if the number is less than eight
  122. * @this Blockly.Block
  123. */
  124. onchange: function() {
  125. let len = this.getFieldValue("PW").length;
  126. if (len > 0) {
  127. if (len < 8) {
  128. this.setWarningText(Blockly.Msg.WIFINETWORK_PW_WARN, 'network_pw');
  129. } else {
  130. this.setWarningText(null, 'network_pw');
  131. }
  132. } else if (len == 0) {
  133. if (len == 0) this.setFieldValue("ENTER_YOUR_PASSWORD", "PW");
  134. }
  135. }
  136. };
  137. /*get device ip*/
  138. Blockly.Blocks['wifiNetwork_getLocalIp'] = {
  139. init: function() {
  140. this.appendDummyInput()
  141. .appendField(Blockly.Msg.WIFINETWORK_GETLOCALIP);
  142. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  143. this.setOutput(true, Blockly.Types.TEXT.output);
  144. this.setTooltip("");
  145. this.setHelpUrl("");
  146. },
  147. };
  148. /*check if wifi is connected */
  149. Blockly.Blocks['wifiNetwork_isConnected'] = {
  150. init: function() {
  151. this.appendDummyInput()
  152. .appendField(Blockly.Msg.WIFINETWORK_ISCONNECTED);
  153. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  154. this.setOutput(true, Blockly.Types.BOOLEAN.output);
  155. this.setTooltip("");
  156. this.setHelpUrl("");
  157. },
  158. };
  159. /**wifi
  160. * number of connected client
  161. */
  162. Blockly.Blocks['wifiNetwork_getStationNum'] = {
  163. init:function() {
  164. this.appendDummyInput()
  165. .appendField(Blockly.Msg.WIFINETWORK_GETSTATIONNUM);
  166. this.setColour(Blockly.Blocks.wifinetwork.HUE);
  167. this.setOutput(true);
  168. this.setTooltip("");
  169. this.setHelpUrl("");
  170. }
  171. }