"use strict"; Blockly.Blocks.math_degrad = { init: function () { this.appendValueInput("convert").setCheck(null).appendField(new Blockly.FieldDropdown([[Blockly.Msg.math_degrad_rad, "radians"], [Blockly.Msg.math_degrad_deg, "degrees"]]), "rad_deg"), this.setOutput(!0, null), this.setColour("#5472ea"), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('rad_deg'); var TOOLTIPS = { 'radians': Blockly.Msg.Math_Degrad_RAD_TOOLTIP, 'degrees': Blockly.Msg.Math_Degrad_DEG_TOOLTIP }; return TOOLTIPS[mode]; }); } }, Blockly.Python.math_degrad = function (t) { var e = t.getFieldValue("rad_deg"), n = Blockly.Python.valueToCode(t, "convert", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.definitions_.import_math = "import math\n", ["math." + e + "(" + n + ")", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.serial_comm_print = { init: function () { this.appendValueInput("serial_comm_input").setCheck("String").appendField(Blockly.Msg.serialcomm_print), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#22b845"), this.setTooltip(Blockly.Msg.serial_Comm_Print_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.serial_comm_print = function (t) { return "print(" + Blockly.Python.valueToCode(t, "serial_comm_input", Blockly.Python.ORDER_ATOMIC) + ")\n" }; var ESP32_IO_COLOR = "#ff8027"; Blockly.Blocks.esp32_main_controller_text_print = { init: function () { this.jsonInit({ message0: Blockly.Msg.TEXT_PRINT_TITLE, args0: [{ type: "input_value", name: "TEXT" }], previousStatement: null, nextStatement: null, colour: "#33cc99", tooltip: Blockly.Msg.TEXT_PRINT_TOOLTIP, helpUrl: Blockly.Msg.TEXT_PRINT_HELPURL }) } }, Blockly.Python.esp32_main_controller_text_print = function (t) { return "print(" + (Blockly.Python.valueToCode(t, "TEXT", Blockly.Python.ORDER_NONE) || "___") + ")\n" }, Blockly.Blocks.esp32_main_controller_text = { init: function () { this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL), this.setColour("#33cc99"), this.appendDummyInput().appendField(this.newQuote_(!0)).appendField(new Blockly.FieldTextInput(""), "TEXT").appendField(this.newQuote_(!1)), this.setOutput(!0, "String"); var e = this; this.setTooltip(function () { var t = e.getParent(); return t && t.getInputsInline() && t.tooltip || Blockly.Msg.TEXT_TEXT_TOOLTIP }) }, newQuote_: function (t) { if (t == this.RTL) var e = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg=="; else e = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC"; return new Blockly.FieldImage(e, 12, 12, '"') } }, Blockly.Python.esp32_main_controller_text = function (t) { return [Blockly.Python.quote_(t.getFieldValue("TEXT")), Blockly.Python.ORDER_ATOMIC] }, Blockly.Blocks.esp32_main_controller_io_from_digital_pin = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "1"], [Blockly.Msg.time_ai_module, "2"]]), "digital_get_type").appendField(Blockly.Msg.digital_get), this.appendValueInput("digital_pin_input").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.digital_get_value), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(ESP32_IO_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('digital_get_type'); var TOOLTIPS = { '1': Blockly.Msg.Esp32_Main_Controller_Io_From_Digital_Pin_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), '2': Blockly.Msg.Esp32_Main_Controller_Io_From_Digital_Pin_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_io_from_digital_pin = function (t) { var e = Blockly.Python.valueToCode(t, "digital_pin_input", Blockly.Python.ORDER_ATOMIC), n = t.getFieldValue("digital_get_type"), i = ""; if (2 == n) { Blockly.Python.definitions_.import_setup = "from fpioa_manager import *\nfrom Maix import FPIOA,GPIO\n"; var l = "FPIOA().set_function(" + e + ",fm.fpioa.GPIOHS" + e + ")\n_read_ai_ext_pin" + e + " = GPIO(GPIO.GPIOHS" + e + ", GPIO.IN,GPIO.PULL_UP)\n"; Blockly.Python.addVariable("_read_ai_ext_pin" + e, l, !0), i = "_read_ai_ext_pin" + e + ".value()" } else if (1 == n) { Blockly.Python.definitions_.import_setup = "from machine import Pin\n"; var o = "_PIN_IN_" + e + " = Pin(" + e + ", Pin.IN)\n"; Blockly.Python.addVariable("_PIN_IN_" + e, o, !0), i = "_PIN_IN_" + e + ".value()" } return [i, Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_io_high_low = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldDropdown([[Blockly.Msg.io_high, "1"], [Blockly.Msg.io_low, "0"]]), "high_low"), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(ESP32_IO_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('high_low'); var TOOLTIPS = { '1': Blockly.Msg.Esp32_Main_Controller_Io_High_Low_TOOLTIP.replace('%1', Blockly.Msg.io_high), '0': Blockly.Msg.Esp32_Main_Controller_Io_High_Low_TOOLTIP.replace('%1', Blockly.Msg.io_low) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_io_high_low = function (t) { return [t.getFieldValue("high_low"), Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_main_controller_io_set_digital_pin = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "1"], [Blockly.Msg.time_ai_module, "2"]]), "digital_set_type").appendField(Blockly.Msg.digital_set), this.appendValueInput("digital_pin_input").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.digital_set_as), this.appendValueInput("high_low").setCheck(null), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_IO_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('digital_set_type'); var TOOLTIPS = { '1': Blockly.Msg.Esp32_Main_Controller_Io_Set_Digital_Pin_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), '2': Blockly.Msg.Esp32_Main_Controller_Io_Set_Digital_Pin_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_io_set_digital_pin = function (t) { var e = Blockly.Python.valueToCode(t, "digital_pin_input", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "high_low", Blockly.Python.ORDER_ATOMIC), i = t.getFieldValue("digital_set_type"), l = ""; if (1 == i) { Blockly.Python.definitions_.import_setup = "from machine import Pin\n"; var o = "_PIN_OUT_" + e + " = Pin(" + e + ", Pin.OUT)\n"; Blockly.Python.addVariable("_PIN_OUT_" + e, o, !0), l = "_PIN_OUT_" + e + ".value" + n + "\n" } else if (2 == i) { Blockly.Python.definitions_.import_setup = "from fpioa_manager import *\nfrom Maix import GPIO\n"; var _ = "fm.register(" + e + ",fm.fpioa.GPIOHS" + e + ")\n_set_ai_ext_pin" + e + " = GPIO(GPIO.GPIOHS" + e + ", GPIO.OUT)\n"; Blockly.Python.addVariable("_set_ai_ext_pin" + e, _, !0), l = "_set_ai_ext_pin" + e + ".value(" + n + ")\n" } return l }, Blockly.Blocks.esp32_main_controller_io_from_analog_pin = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.analog_get), this.appendValueInput("analog_pin_input").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.analog_get_value), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(ESP32_IO_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Io_From_Analog_Pin_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_io_from_analog_pin = function (t) { var e = Blockly.Python.valueToCode(t, "analog_pin_input", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.addVariable("_PWM_PIN_IN_" + e, "", !0), Blockly.Python.definitions_.import_setup = "from machine import Pin, ADC\n\n_PWM_PIN_IN_" + e + " = ADC(Pin(" + e + "))\n_PWM_PIN_IN_" + e + ".atten(ADC.ATTN_11DB)\n", ["_PWM_PIN_IN_" + e + ".read()", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_io_set_analog_pin = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.analog_set), this.appendValueInput("analog_pin_input").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.analog_set_freq), this.appendValueInput("frequency").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.analog_set_pwm), this.appendValueInput("pwm").setCheck(null), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_IO_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('LED'); var TOOLTIPS = { 'LED': Blockly.Msg.Esp32_Main_Controller_Io_Set_Analog_Pin_TOOLTIP.replace('%1', Blockly.Msg.led) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_io_set_analog_pin = function (t) { var e = Blockly.Python.valueToCode(t, "analog_pin_input", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "pwm", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "frequency", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.addVariable("_PWM_PIN_OUT_" + e, "", !0), Blockly.Python.definitions_.import_setup = "from machine import Pin, PWM\n_PWM_PIN_OUT_" + e + " = PWM(Pin(" + e + "), freq=" + i + ")\n", "_PWM_PIN_OUT_" + e + ".freq(" + i + ")\n_PWM_PIN_OUT_" + e + ".duty(" + n + ")\n" }, Blockly.Blocks.esp32_main_controller_button_read_pressed = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32BUTTON).appendField(new Blockly.FieldDropdown([["P1", "button_type_1"], ["P2", "button_type_2"]]), "button_type").appendField(Blockly.Msg.ESP32PRESSED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('button_type'); var TOOLTIPS = { 'button_type_1': Blockly.Msg.Esp32_Main_Controller_Button_Read_Pressed_TOOLTIP.replace('%1', "P1"), 'button_type_2': Blockly.Msg.Esp32_Main_Controller_Button_Read_Pressed_TOOLTIP.replace('%1', "P2") }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_button_read_pressed = function (t) { Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getField("button_type").text_, n = (t.getFieldValue("button_state"), "P1" == e ? "34" : "35"), i = ""; return "P2" == e && (i = ",Pin.PULL_UP"), Blockly.Python.addVariable("_" + e, "_" + e + " = Pin(" + n + ", Pin.IN" + i + ")", !0), ["(_" + e + ".value() == 1)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_button_read_released = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32BUTTON).appendField(new Blockly.FieldDropdown([["P1", "button_type_1"], ["P2", "button_type_2"]]), "button_type").appendField(Blockly.Msg.ESP32RELEASED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('button_type'); var TOOLTIPS = { 'button_type_1': Blockly.Msg.Esp32_Main_Controller_Button_Read_Released_TOOLTIP.replace('%1', "P1"), 'button_type_2': Blockly.Msg.Esp32_Main_Controller_Button_Read_Released_TOOLTIP.replace('%1', "P2") }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_button_read_released = function (t) { Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getField("button_type").text_, n = (t.getFieldValue("button_state"), "P1" == e ? "34" : "35"), i = ""; return "P2" == e && (i = ",Pin.PULL_UP"), Blockly.Python.addVariable("_" + e, "_" + e + " = Pin(" + n + ", Pin.IN" + i + ")", !0), ["(_" + e + ".value() == 0)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_button_read_value = {init: function () {this.appendDummyInput().appendField(Blockly.Msg.basic_button_read_value).appendField(new Blockly.FieldDropdown([["P1", "button_type_1"], ["P2", "button_type_2"]]), "button_type").appendField(Blockly.Msg.basic_button_read_value_after), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () {var mode = thisBlock.getFieldValue('button_type'); var TOOLTIPS = {'button_type_1': Blockly.Msg.Esp32_Main_Controller_Button_Read_Value_TOOLTIP.replace('%1', "P1"),'button_type_2': Blockly.Msg.Esp32_Main_Controller_Button_Read_Value_TOOLTIP.replace('%1', "P2")}; return TOOLTIPS[mode];});}}, Blockly.Python.esp32_main_controller_button_read_value = function (t) { Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getField("button_type").text_, n = "P1" == e ? "34" : "35", i = ""; return "P2" == e && (i = ",Pin.PULL_UP"), Blockly.Python.addVariable("_" + e, "_" + e + " = Pin(" + n + ", Pin.IN" + i + ")", !0), ["_" + e + ".value()", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_main_controller_dial_switch_read_pressed = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32DIALSWITCH).appendField(new Blockly.FieldDropdown([[Blockly.Msg.ESP32DIALER_LEFT, "switch_type_left"], [Blockly.Msg.ESP32DIALER_MIDDLE, "switch_type_middle"], [Blockly.Msg.ESP32DIALER_RIGHT, "switch_type_right"]]), "switch_type").appendField(Blockly.Msg.ESP32PRESSED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_dial_switch_read_pressed = function (t) { Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getFieldValue("switch_type"), n = ""; if ("switch_type_left" == e) { n = "Left" } else if ("switch_type_middle" == e) { ", Pin.PULL_UP", n = "Middle" } else if ("switch_type_right" == e) { n = "Right" } return Blockly.Python.addVariable("pLeft", "pLeft = Pin(38, Pin.IN)"), Blockly.Python.addVariable("pMiddle", "pMiddle = Pin(19, Pin.IN)"), Blockly.Python.addVariable("pRight", "pRight = Pin(35, Pin.IN)"), ["(p" + n + ".value() == 1)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_dial_switch_read_released = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32DIALSWITCH).appendField(new Blockly.FieldDropdown([[Blockly.Msg.ESP32DIALER_LEFT, "switch_type_left"], [Blockly.Msg.ESP32DIALER_MIDDLE, "switch_type_middle"], [Blockly.Msg.ESP32DIALER_RIGHT, "switch_type_right"]]), "switch_type").appendField(Blockly.Msg.ESP32RELEASED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_dial_switch_read_released = function (t) { Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getFieldValue("switch_type"), n = (t.getFieldValue("switch_state"), "34"), i = "", l = ""; if ("switch_type_left" == e) { n = "34"; l = "Left" } else if ("switch_type_middle" == e) { n = "19"; i = ", Pin.PULL_UP", l = "Middle" } else if ("switch_type_right" == e) { n = "35"; l = "Right" } return Blockly.Python.addVariable("p" + l, "p" + l + " = Pin(" + n + ", Pin.IN" + i + ")"), ["(p" + l + ".value() == 0)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_set_led_turnon = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32TURN + Blockly.Msg.ESP32LED_MONO_TEXT_NO), this.appendValueInput("led_type").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_MONO_TEXT_AFTER + Blockly.Msg.ESP32LED + Blockly.Msg.ESP32LED_TURNON), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Set_Led_Turnon_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_set_led_turnon = function (t) { Blockly.Python.definitions_.import_led_Pin = "from machine import Pin"; var e = Blockly.Python.valueToCode(t, "led_type", Blockly.Python.ORDER_ATOMIC); t.getFieldValue("led_state"); if ("1" == e); else if ("2" == e); else if ("3" == e); else if ("4" == e); else if ("5" == e); else if ("6" == e); else if ("7" == e); else if ("8" == e); else if ("9" == e); else; return Blockly.Python.addSetup("iot_led_light_setup", "_light = [0,2,12,5,13,14,15,18,19,23]\n\n_light_1 = Pin(_light[1], Pin.OUT, value=0)\n_light_2 = Pin(_light[2], Pin.OUT, value=0)\n_light_3 = Pin(_light[3], Pin.OUT, value=0)\n_light_4 = Pin(_light[4], Pin.OUT, value=0)\n_light_5 = Pin(_light[5], Pin.OUT, value=0)\n_light_6 = Pin(_light[6], Pin.OUT, value=0)\n_light_7 = Pin(_light[7], Pin.OUT, value=0)\n_light_8 = Pin(_light[8], Pin.OUT, value=0)\n_light_9 = Pin(_light[9], Pin.OUT, value=0)\n\ndef _led_light(state, pin):\n if (state == True):\n if pin == 1: _light_1.value(1)\n if pin == 2: _light_2.value(1)\n if pin == 3: _light_3.value(1)\n if pin == 4: _light_4.value(1)\n if pin == 5: _light_5.value(1)\n if pin == 6: _light_6.value(1)\n if pin == 7: _light_7.value(1)\n if pin == 8: _light_8.value(1)\n if pin == 9: _light_9.value(1)\n elif (state == False):\n if pin == 1: _light_1.value(0)\n if pin == 2: _light_2.value(0)\n if pin == 3: _light_3.value(0)\n if pin == 4: _light_4.value(0)\n if pin == 5: _light_5.value(0)\n if pin == 6: _light_6.value(0)\n if pin == 7: _light_7.value(0)\n if pin == 8: _light_8.value(0)\n if pin == 9: _light_9.value(0)\n"), "_led_light(True," + e + ")\n" }, Blockly.Blocks.esp32_main_controller_set_led_turnoff = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32TURN + Blockly.Msg.ESP32LED_MONO_TEXT_NO), this.appendValueInput("led_type").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_MONO_TEXT_AFTER + Blockly.Msg.ESP32LED + Blockly.Msg.ESP32LED_TURNOFF), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Set_Led_Turnoff_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_set_led_turnoff = function (t) { Blockly.Python.definitions_.import_led_Pin = "from machine import Pin"; var e = Blockly.Python.valueToCode(t, "led_type", Blockly.Python.ORDER_ATOMIC); t.getFieldValue("led_state"); if ("1" == e); else if ("2" == e); else if ("3" == e); else if ("4" == e); else if ("5" == e); else if ("6" == e); else if ("7" == e); else if ("8" == e); else if ("9" == e); else; return Blockly.Python.addSetup("iot_led_light_setup", "_light = [0,2,12,5,13,14,15,18,19,23]\n\n_light_1 = Pin(_light[1], Pin.OUT, value=0)\n_light_2 = Pin(_light[2], Pin.OUT, value=0)\n_light_3 = Pin(_light[3], Pin.OUT, value=0)\n_light_4 = Pin(_light[4], Pin.OUT, value=0)\n_light_5 = Pin(_light[5], Pin.OUT, value=0)\n_light_6 = Pin(_light[6], Pin.OUT, value=0)\n_light_7 = Pin(_light[7], Pin.OUT, value=0)\n_light_8 = Pin(_light[8], Pin.OUT, value=0)\n_light_9 = Pin(_light[9], Pin.OUT, value=0)\n\ndef _led_light(state, pin):\n if (state == True):\n if pin == 1: _light_1.value(1)\n if pin == 2: _light_2.value(1)\n if pin == 3: _light_3.value(1)\n if pin == 4: _light_4.value(1)\n if pin == 5: _light_5.value(1)\n if pin == 6: _light_6.value(1)\n if pin == 7: _light_7.value(1)\n if pin == 8: _light_8.value(1)\n if pin == 9: _light_9.value(1)\n elif (state == False):\n if pin == 1: _light_1.value(0)\n if pin == 2: _light_2.value(0)\n if pin == 3: _light_3.value(0)\n if pin == 4: _light_4.value(0)\n if pin == 5: _light_5.value(0)\n if pin == 6: _light_6.value(0)\n if pin == 7: _light_7.value(0)\n if pin == 8: _light_8.value(0)\n if pin == 9: _light_9.value(0)\n"), "_led_light(False," + e + ")\n" }, Blockly.Blocks.esp32_main_controller_set_led_drawpixel_on = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHTUP + Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_INIT_TEXT), this.appendValueInput("x").setCheck(null), this.appendValueInput("y").setCheck(null).appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_MIDDLE_TEXT), this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_END_TEXT), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Set_Led_Drawpixel_On_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_set_led_drawpixel_on = function (t) { var e = Blockly.Python.valueToCode(t, "x", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "y", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.definitions_.import_led_Pin = "from machine import Pin", Blockly.Python.addSetup("iot_led_light_setup", "_light = [0,2,12,5,13,14,15,18,19,23]\n\n_light_1 = Pin(_light[1], Pin.OUT, value=0)\n_light_2 = Pin(_light[2], Pin.OUT, value=0)\n_light_3 = Pin(_light[3], Pin.OUT, value=0)\n_light_4 = Pin(_light[4], Pin.OUT, value=0)\n_light_5 = Pin(_light[5], Pin.OUT, value=0)\n_light_6 = Pin(_light[6], Pin.OUT, value=0)\n_light_7 = Pin(_light[7], Pin.OUT, value=0)\n_light_8 = Pin(_light[8], Pin.OUT, value=0)\n_light_9 = Pin(_light[9], Pin.OUT, value=0)\n\ndef _led_light(state, pin):\n if (state == True):\n if pin == 1: _light_1.value(1)\n if pin == 2: _light_2.value(1)\n if pin == 3: _light_3.value(1)\n if pin == 4: _light_4.value(1)\n if pin == 5: _light_5.value(1)\n if pin == 6: _light_6.value(1)\n if pin == 7: _light_7.value(1)\n if pin == 8: _light_8.value(1)\n if pin == 9: _light_9.value(1)\n elif (state == False):\n if pin == 1: _light_1.value(0)\n if pin == 2: _light_2.value(0)\n if pin == 3: _light_3.value(0)\n if pin == 4: _light_4.value(0)\n if pin == 5: _light_5.value(0)\n if pin == 6: _light_6.value(0)\n if pin == 7: _light_7.value(0)\n if pin == 8: _light_8.value(0)\n if pin == 9: _light_9.value(0)\n"), Blockly.Python.addSetup("drawpixel_setup", "def _led_draw_pixel(state, x, y):\n real_pin = (3*y-3+x)\n _led_light(state,real_pin)\n\n"), "_led_draw_pixel(True," + e + "," + n + ")\n" }, Blockly.Blocks.esp32_main_controller_set_led_drawpixel_off = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHTOFF + Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_INIT_TEXT), this.appendValueInput("x").setCheck(null), this.appendValueInput("y").setCheck(null).appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_MIDDLE_TEXT), this.appendDummyInput().appendField(Blockly.Msg.ESP32LED_CORD_DRAWPIXEL_LIGHT_END_TEXT), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Set_Led_Drawpixel_Off_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_set_led_drawpixel_off = function (t) { var e = Blockly.Python.valueToCode(t, "x", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "y", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.definitions_.import_led_Pin = "from machine import Pin", Blockly.Python.addSetup("iot_led_light_setup", "_light = [0,2,12,5,13,14,15,18,19,23]\n\n_light_1 = Pin(_light[1], Pin.OUT, value=0)\n_light_2 = Pin(_light[2], Pin.OUT, value=0)\n_light_3 = Pin(_light[3], Pin.OUT, value=0)\n_light_4 = Pin(_light[4], Pin.OUT, value=0)\n_light_5 = Pin(_light[5], Pin.OUT, value=0)\n_light_6 = Pin(_light[6], Pin.OUT, value=0)\n_light_7 = Pin(_light[7], Pin.OUT, value=0)\n_light_8 = Pin(_light[8], Pin.OUT, value=0)\n_light_9 = Pin(_light[9], Pin.OUT, value=0)\n\ndef _led_light(state, pin):\n if (state == True):\n if pin == 1: _light_1.value(1)\n if pin == 2: _light_2.value(1)\n if pin == 3: _light_3.value(1)\n if pin == 4: _light_4.value(1)\n if pin == 5: _light_5.value(1)\n if pin == 6: _light_6.value(1)\n if pin == 7: _light_7.value(1)\n if pin == 8: _light_8.value(1)\n if pin == 9: _light_9.value(1)\n elif (state == False):\n if pin == 1: _light_1.value(0)\n if pin == 2: _light_2.value(0)\n if pin == 3: _light_3.value(0)\n if pin == 4: _light_4.value(0)\n if pin == 5: _light_5.value(0)\n if pin == 6: _light_6.value(0)\n if pin == 7: _light_7.value(0)\n if pin == 8: _light_8.value(0)\n if pin == 9: _light_9.value(0)\n"), Blockly.Python.addSetup("drawpixel_setup", "def _led_draw_pixel(state, x, y):\n real_pin = (3*y-3+x)\n _led_light(state,real_pin)\n\n"), "_led_draw_pixel(False," + e + "," + n + ")\n" }, Blockly.Blocks.esp32_main_controller_set_buzzer = { init: function () { this.appendDummyInput().appendField(), this.appendValueInput("esp32_var_num").setCheck("Number").appendField(Blockly.Msg.basic_buzzer_set), this.setInputsInline(!0), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Set_Buzzer_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_set_buzzer = function (t) { Blockly.Python.definitions_.import_PWM = "from machine import PWM", Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = Blockly.Python.valueToCode(t, "esp32_var_num", Blockly.Python.ORDER_ATOMIC) || "0"; return Blockly.Python.definitions_.buzzer_operation = "beeper = PWM(Pin(26, Pin.OUT), freq=440, duty=512)\nbeeper.deinit()\n\n", "beeper.init()\nbeeper.freq(" + e + ")\n" }, Blockly.Blocks.esp32_main_controller_turn_off_buzzer = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32TURNOB), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Turn_Off_Buzzer_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_turn_off_buzzer = function (t) { Blockly.Python.definitions_.import_PWM = "from machine import PWM", Blockly.Python.definitions_.buzzer_operation = "beeper = PWM(Pin(26, Pin.OUT), freq=440, duty=512)\nbeeper.deinit()\n\n"; return "beeper.deinit()\n" }, Blockly.Blocks.esp32_main_controller_touch_read_touched = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32TA).appendField(new Blockly.FieldDropdown([["A", "touch_area_type_a"], ["B", "touch_area_type_b"]]), "touch_area_type").appendField(Blockly.Msg.ESP32_TOUCHED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_touch_read_touched = function (t) { Blockly.Python.definitions_.import_TouchPad = "from machine import TouchPad", Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getFieldValue("touch_area_type"), n = (t.getFieldValue("touch_area_state"), "4"); if ("touch_area_type_a" == e) n = "4"; else if ("touch_area_type_b" == e) n = "27"; return Blockly.Python.addVariable("t" + t.getField("touch_area_type").text_, "_TOUCH_" + t.getField("touch_area_type").text_ + " = TouchPad(Pin(" + n + "))"), ["_TOUCH_" + t.getField("touch_area_type").text_ + ".read() < 100", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_touch_read_untouched = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32TA).appendField(new Blockly.FieldDropdown([["A", "touch_area_type_a"], ["B", "touch_area_type_b"]]), "touch_area_type").appendField(Blockly.Msg.ESP32_UNTOUCHED), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_touch_read_untouched = function (t) { Blockly.Python.definitions_.import_TouchPad = "from machine import TouchPad", Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getFieldValue("touch_area_type"), n = (t.getFieldValue("touch_area_state"), "4"); if ("touch_area_type_a" == e) n = "4"; else if ("touch_area_type_b" == e) n = "27"; return Blockly.Python.addVariable("t" + t.getField("touch_area_type").text_, "_TOUCH_" + t.getField("touch_area_type").text_ + " = TouchPad(Pin(" + n + "))"), ["_TOUCH_" + t.getField("touch_area_type").text_ + ".read() >= 100", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_touch_read_value = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32_READ).appendField(new Blockly.FieldDropdown([["A", "touch_area_type_a"], ["B", "touch_area_type_b"]]), "touch_area_type").appendField(Blockly.Msg.ESP32_READ_VALUE), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_touch_read_value = function (t) { Blockly.Python.definitions_.import_TouchPad = "from machine import TouchPad", Blockly.Python.definitions_.import_Pin = "from machine import Pin"; var e = t.getFieldValue("touch_area_type"), n = (t.getFieldValue("touch_area_state"), "4"); if ("touch_area_type_a" == e) n = "4"; else if ("touch_area_type_b" == e) n = "27"; return Blockly.Python.addVariable("t" + t.getField("touch_area_type").text_, "_TOUCH_" + t.getField("touch_area_type").text_ + " = TouchPad(Pin(" + n + "))"), ["_TOUCH_" + t.getField("touch_area_type").text_ + ".read() ", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_get_environmental_value = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.ESP32_ENV_GET_TEXT).appendField(new Blockly.FieldDropdown([[Blockly.Msg.basic_temperature, "temperature"], [Blockly.Msg.basic_humidity, "humidity"]]), "env_get_type").appendField(Blockly.Msg.basic_env_value), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('env_get_type');var TOOLTIPS = {'temperature': Blockly.Msg.Esp32_Main_Controller_Get_Environmental_Value_TOOLTIP.replace('%1', Blockly.Msg.basic_temperature),'humidity': Blockly.Msg.Esp32_Main_Controller_Get_Environmental_Value_TOOLTIP.replace('%1', Blockly.Msg.basic_humidity)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_get_environmental_value = function (t) { var e = t.getFieldValue("env_get_type"); if (Blockly.Python.definitions_.import_bme280 = "from machine import Pin, I2C\nfrom aht10 import AHT10\n\n_aht10_i2c = I2C(sda=Pin(32), scl=Pin(33))\n_aht10_sensor = AHT10(_aht10_i2c)\n_aht10_sensor.sensor_init()\n_aht10_sensor.is_calibration_enabled()\n", Blockly.Python.addVariable("_BME", ""), "temperature" == e) var n = "_aht10_sensor.read_" + e + "()"; else if ("humidity" == e) n = "_aht10_sensor.read_" + e + "()"; else n = e; return [n, Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_motion_init = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_motion_use), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_motion_init = function (t) { Blockly.Python.definitions_.import_mpu6050 = "from machine import I2C, Pin\nimport math\nimport mpu6050\n_SENSOR_MPU_PINS = I2C(scl=Pin(22), sda=Pin(21))\n"; return "_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n_MPU_ACCL_X = _MPU.get_values()['AcX']\n_MPU_ACCL_Y = _MPU.get_values()['AcY']\n_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n_MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE('X')\n_MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE('Y')\n_MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE('Z')\n" }, Blockly.Blocks.esp32_main_controller_motion_when_shaking = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_when_shaking), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_motion_when_shaking = function (t) { Blockly.Python.definitions_.shaking_def = "def _CHECK_SHAKING():\n if _MPU_SHAKING_OFFSET < 0 and _SSTATE == 0:\n _SSTATE = 1\n return True\n elif _MPU_SHAKING_OFFSET > 0 and _SSTATE == 1:\n _SSTATE = 0\n return False\n"; return ["(_CHECK_SHAKING() == True)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_motion_when_shaking_STATEMENT = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_when_shaking_when_module).appendField(new Blockly.FieldDropdown([[Blockly.Msg.basic_when_shaking_when_is_in, "True"], [Blockly.Msg.basic_when_shaking_when_is_not_in, "False"]]), "status").appendField(Blockly.Msg.basic_when_shaking_when_shaking), this.appendStatementInput("input").setCheck(null).appendField(Blockly.Msg.basic_motion_statement_exec), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('status');var TOOLTIPS = {'True': Blockly.Msg.Esp32_Main_Controller_Motion_When_Shaking_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_shaking_when_is_in),'False': Blockly.Msg.Esp32_Main_Controller_Motion_When_Shaking_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_shaking_when_is_not_in)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_motion_when_shaking_STATEMENT = function (t) { var e = t.getFieldValue("status"), n = Blockly.Python.statementToCode(t, "input"); return Blockly.Python.definitions_.import_mpu6050 = "from machine import I2C, Pin\nimport math\nimport mpu6050\n_SENSOR_MPU_PINS = I2C(scl=Pin(22), sda=Pin(21))\n", Blockly.Python.definitions_.mpu6050_standard_def = "_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n", Blockly.Python.definitions_.shaking_def = "def _CHECK_SHAKING():\n _MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n _MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n _MPU_ACCL_Z = _MPU.get_values()['AcZ']\n _SSTATE = 0\n if _MPU_SHAKING_OFFSET < 0:\n _SSTATE = 1\n return True\n elif _MPU_SHAKING_OFFSET > 0:\n _SSTATE = 0\n return False\n", "if (_CHECK_SHAKING() == " + e + "):\n\t_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n\t_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n\t_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n" + n + "\n" }, Blockly.Blocks.esp32_main_controller_motion_when_tilting = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_when_tilting_get).appendField(new Blockly.FieldDropdown([[Blockly.Msg.basic_when_tilting_get_left, "L"], [Blockly.Msg.basic_when_tilting_get_right, "R"], [Blockly.Msg.basic_when_tilting_get_forward, "F"], [Blockly.Msg.basic_when_tilting_get_backward, "B"]]), "tilt_type").appendField(Blockly.Msg.basic_when_tilting_get_when), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_motion_when_tilting = function (t) { var e = t.getFieldValue("tilt_type"); return Blockly.Python.definitions_.tilting_def = 'def _CHECK_TILT_LR():\n if _MPU_OFFSET_TILT_X < 160 and _MPU_OFFSET_TILT_X > 0:\n return "R"\n elif _MPU_OFFSET_TILT_X > 200 and _MPU_OFFSET_TILT_X < 360:\n return "L"\n else:\n return None\n\ndef _CHECK_TILT_FB():\n if _MPU_OFFSET_TILT_Y < 160 and _MPU_OFFSET_TILT_Y > 0:\n return "F"\n elif _MPU_OFFSET_TILT_Y > 200 and _MPU_OFFSET_TILT_Y < 360:\n return "B"\n else:\n return None\n', "L" == e || "R" == e ? _check_function = '(_CHECK_TILT_LR() == "' : "F" != e && "B" != e || (_check_function = '(_CHECK_TILT_FB() == "'), [_check_function + e + '")', Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_motion_when_tilting_STATEMENT = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_when_tilting_get).appendField(new Blockly.FieldDropdown([[Blockly.Msg.basic_when_tilting_get_left, "L"], [Blockly.Msg.basic_when_tilting_get_right, "R"], [Blockly.Msg.basic_when_tilting_get_forward, "F"], [Blockly.Msg.basic_when_tilting_get_backward, "B"], [Blockly.Msg.basic_when_tilting_not_tilting, "N"]]), "tilt_type").appendField(Blockly.Msg.basic_when_tilting_get_when), this.appendStatementInput("input").setCheck(null).appendField(Blockly.Msg.basic_motion_statement_exec), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#e8795b"), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('tilt_type');var TOOLTIPS = {'L': Blockly.Msg.Esp32_Main_Controller_Motion_When_Tilting_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_tilting_get_left),'R': Blockly.Msg.Esp32_Main_Controller_Motion_When_Tilting_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_tilting_get_right),'F': Blockly.Msg.Esp32_Main_Controller_Motion_When_Tilting_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_tilting_get_forward),'B': Blockly.Msg.Esp32_Main_Controller_Motion_When_Tilting_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_tilting_get_backward),'N': Blockly.Msg.Esp32_Main_Controller_Motion_When_Tilting_STATEMENT_TOOLTIP.replace('%1', Blockly.Msg.basic_when_tilting_not_tilting)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_motion_when_tilting_STATEMENT = function (t) { var e = t.getFieldValue("tilt_type"), n = Blockly.Python.statementToCode(t, "input"); Blockly.Python.definitions_.import_mpu6050 = "from machine import I2C, Pin\nimport math\nimport mpu6050\n_SENSOR_MPU_PINS = I2C(scl=Pin(22), sda=Pin(21))\n", Blockly.Python.definitions_.mpu6050_standard_def = "_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n", Blockly.Python.definitions_.tilting_def = 'def _CHECK_TILT_DIRECTION():\n _MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n _MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE(\'X\')\n _MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE(\'Y\')\n _MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE(\'Z\')\n if _MPU_OFFSET_TILT_X < 150 and _MPU_OFFSET_TILT_X > 0:\n return "L"\n elif _MPU_OFFSET_TILT_X > 210 and _MPU_OFFSET_TILT_X < 360:\n return "R"\n if _MPU_OFFSET_TILT_Y < 150 and _MPU_OFFSET_TILT_Y > 0:\n return "B"\n elif _MPU_OFFSET_TILT_Y > 210 and _MPU_OFFSET_TILT_Y < 360:\n return "F"\n else:\n return "N"\n'; return 'if (_CHECK_TILT_DIRECTION() == "' + e + '"):\n\t_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n' + n + "\n\n" }, Blockly.Blocks.esp32_main_controller_motion_acceleration = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_motion_get).appendField(new Blockly.FieldDropdown([["X", "X"], ["Y", "Y"], ["Z", "Z"]]), "accel_type").appendField(Blockly.Msg.basic_motion_accel), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl(""); var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('accel_type');var TOOLTIPS = {'X': Blockly.Msg.Esp32_Main_Controller_Motion_Acceleration_TOOLTIP.replace('%1', 'X'),'Y': Blockly.Msg.Esp32_Main_Controller_Motion_Acceleration_TOOLTIP.replace('%1', 'Y'),'Z': Blockly.Msg.Esp32_Main_Controller_Motion_Acceleration_TOOLTIP.replace('%1', 'Z')};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_motion_acceleration = function (t) { var e = t.getFieldValue("accel_type"); return Blockly.Python.definitions_.import_mpu6050 = "from machine import I2C, Pin\nimport math\nimport mpu6050\n_SENSOR_MPU_PINS = I2C(scl=Pin(22), sda=Pin(21))\n", Blockly.Python.definitions_.mpu6050_standard_def = "_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n_MPU_ACCL_X = _MPU.get_values()['AcX']\n_MPU_ACCL_Y = _MPU.get_values()['AcY']\n_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n_MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE('X')\n_MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE('Y')\n_MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE('Z')\n", Blockly.Python.definitions_.mpu6050_get_accel = "def mpu6050_get_accel(type):\n\t_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n\t_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n\t_MPU_ACCL_X = _MPU.get_values()['AcX']\n\t_MPU_ACCL_Y = _MPU.get_values()['AcY']\n\t_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n\t_MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE('X')\n\t_MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE('Y')\n\t_MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE('Z')\n\tif type == 'X':\n\t\treturn _MPU_ACCL_X\n\tif type == 'Y':\n\t\treturn _MPU_ACCL_Y\n\tif type == 'Z':\n\t\treturn _MPU_ACCL_Z\n", ["mpu6050_get_accel('" + e + "')", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_motion_tilt_angle = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_motion_get).appendField(new Blockly.FieldDropdown([["X", "X"], ["Y", "Y"], ["Z", "Z"]]), "tilt_angle_type").appendField(Blockly.Msg.basic_motion_angle), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('tilt_angle_type');var TOOLTIPS = {'X': Blockly.Msg.Esp32_Main_Controller_Motion_Tilt_Angle_TOOLTIP.replace('%1', 'X'),'Y': Blockly.Msg.Esp32_Main_Controller_Motion_Tilt_Angle_TOOLTIP.replace('%1', 'Y'),'Z': Blockly.Msg.Esp32_Main_Controller_Motion_Tilt_Angle_TOOLTIP.replace('%1', 'Z')};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_motion_tilt_angle = function (t) { var e = t.getFieldValue("tilt_angle_type"); return Blockly.Python.definitions_.import_mpu6050 = "from machine import I2C, Pin\nimport math\nimport mpu6050\n_SENSOR_MPU_PINS = I2C(scl=Pin(22), sda=Pin(21))\n", Blockly.Python.definitions_.mpu6050_standard_def = "_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n_MPU_ACCL_X = _MPU.get_values()['AcX']\n_MPU_ACCL_Y = _MPU.get_values()['AcY']\n_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n_MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE('X')\n_MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE('Y')\n_MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE('Z')\n", Blockly.Python.definitions_.mpu6050_get_angle = "def mpu6050_get_tilt_angle(type):\n\t_MPU = mpu6050.accel(_SENSOR_MPU_PINS)\n\t_MPU_SHAKING_OFFSET = _MPU.get_values()['AcZ']\n\t_MPU_ACCL_X = _MPU.get_values()['AcX']\n\t_MPU_ACCL_Y = _MPU.get_values()['AcY']\n\t_MPU_ACCL_Z = _MPU.get_values()['AcZ']\n\t_MPU_OFFSET_TILT_X = _MPU_GET_TILT_ANGLE('X')\n\t_MPU_OFFSET_TILT_Y = _MPU_GET_TILT_ANGLE('Y')\n\t_MPU_OFFSET_TILT_Z = _MPU_GET_TILT_ANGLE('Z')\n\tif type == 'X':\n\t\treturn _MPU_OFFSET_TILT_X\n\tif type == 'Y':\n\t\treturn _MPU_OFFSET_TILT_Y\n\tif type == 'Z':\n\t\treturn _MPU_OFFSET_TILT_Z\n", ["mpu6050_get_tilt_angle('" + e + "')", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_get_light = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.basic_light_get), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#e8795b"), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Get_Light_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_get_light = function (t) { Blockly.Python.definitions_.light_import_def = "from machine import Pin, ADC\n_PHOTONRESISTOR = machine.ADC(Pin(39))\n_PHOTONRESISTOR.atten(ADC.ATTN_11DB)\n_PHOTONRESISTOR.width(ADC.WIDTH_10BIT)\n", Blockly.Python.addVariable("_PHOTONRESISTOR"); return ["_PHOTONRESISTOR.read()", Blockly.Python.ORDER_CONDITIONAL] }; var ESP32_TIME_COLOR = "#fabe23"; Blockly.Blocks.esp32_main_controller_time_timer_init = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "on_esp32"], [Blockly.Msg.time_ai_module, "on_ai"]]), "type").appendField(Blockly.Msg.time_init_timer), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { 'on_esp32': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Init_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), 'on_ai': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Init_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_time_timer_init = function (t) { var e = t.getFieldValue("type"); if ("on_esp32" == e) { Blockly.Python.definitions_.import_def = "import machine, time\n_TIMER = machine.Timer(0)\n"; var n = "_TIMER.init()\n" } else if ("on_ai" == e) { Blockly.Python.definitions_.import_def = "import time\nfrom machine import Timer\n\ndef _timer_on_timer(timer):\n global _timer_current_time_elapsed\n _timer_current_time_elapsed = _timer_current_time_elapsed + 1\n\n_timer_current_time_elapsed = 0\n_timer_tim = Timer(Timer.TIMER1, Timer.CHANNEL1, mode=Timer.MODE_PERIODIC, period=1, callback=_timer_on_timer)\n"; n = "_timer_tim.start()\n" } return n }, Blockly.Blocks.esp32_main_controller_time_timer_get_current = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "on_esp32"], [Blockly.Msg.time_ai_module, "on_ai"]]), "type").appendField(Blockly.Msg.time_timer_get_time), this.setOutput(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { 'on_esp32': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Get_Current_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), 'on_ai': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Get_Current_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_time_timer_get_current = function (t) { var e = t.getFieldValue("type"); if ("on_esp32" == e) var n = "_TIMER.value()"; else if ("on_ai" == e) n = "_timer_current_time_elapsed"; return [n, Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_time_timer_clear = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "on_esp32"], [Blockly.Msg.time_ai_module, "on_ai"]]), "type").appendField(Blockly.Msg.time_timer_clear), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { 'on_esp32': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Clear_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), 'on_ai': Blockly.Msg.Esp32_Main_Controller_Time_Timer_Clear_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_time_timer_clear = function (t) { var e = t.getFieldValue("type"); if ("on_esp32" == e) var n = "_TIMER.deinit()\n"; else if ("on_ai" == e) n = "_timer_tim.stop()\n"; return n }, Blockly.Blocks.esp32_main_controller_time_period_timer = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "on_esp32"], [Blockly.Msg.time_ai_module, "on_ai"]]), "type").appendField(Blockly.Msg.time_timer_periodically), this.appendDummyInput().appendField(Blockly.Msg.time_timer_every).appendField(new Blockly.FieldTextInput("500"), "period_timer_count").appendField(Blockly.Msg.time_timer_ms), this.appendStatementInput("exec_period_timer").setCheck(null).appendField(Blockly.Msg.time_execution), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { 'on_esp32': Blockly.Msg.Esp32_Main_Controller_Time_Period_Timer_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), 'on_ai': Blockly.Msg.Esp32_Main_Controller_Time_Period_Timer_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_time_period_timer = function (t) { var e = t.getFieldValue("type"), n = t.getFieldValue("period_timer_count"), i = Blockly.Python.statementToCode(t, "exec_period_timer"); "on_esp32" == e ? Blockly.Python.definitions_.import_def = "from machine import Timer\n\ndef _PRD_EXEC_tick(_):\n global _ControlTopic, _ReportTopic\n" + i + "\n_PRD_EXEC_TIMER = Timer(0)\n_PRD_EXEC_TIMER.deinit()\n_PRD_EXEC_TIMER.init(period=" + n + ", mode=Timer.PERIODIC, callback=_PRD_EXEC_tick)\n" : "on_ai" == e && (Blockly.Python.definitions_.import_def = "import time\nfrom machine import Timer\n\ndef _on_timer(timer):\n" + i + "\nfrom machine import Timer\n_periodic_tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=" + n + ", callback=_on_timer, arg=_on_timer)\n\n_periodic_tim.start()\n"); return "" }, Blockly.Blocks.esp32_main_controller_time_period_timer_clear = { init: function () { this.appendDummyInput().appendField("").appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_iot_module, "on_esp32"], [Blockly.Msg.time_ai_module, "on_ai"]]), "type").appendField(Blockly.Msg.time_timer_periodically_clear), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { 'on_esp32': Blockly.Msg.Esp32_Main_Controller_Time_Period_Timer_Clear_TOOLTIP.replace('%1', Blockly.Msg.time_iot_module), 'on_ai': Blockly.Msg.Esp32_Main_Controller_Time_Period_Timer_Clear_TOOLTIP.replace('%1', Blockly.Msg.time_ai_module) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_main_controller_time_period_timer_clear = function (t) { var e = t.getFieldValue("type"); if ("on_esp32" == e) var n = "_PRD_EXEC_TIMER.deinit()\n"; else if ("on_ai" == e) n = "_periodic_tim.stop()\n"; return n }, Blockly.Blocks.esp32_get_current_date = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.time_get_current_date_title).appendField(new Blockly.FieldDropdown([[Blockly.Msg.time_get_current_date_y, "0"], [Blockly.Msg.time_get_current_date_m, "1"], [Blockly.Msg.time_get_current_date_d, "2"], [Blockly.Msg.time_get_current_date_hour, "3"], [Blockly.Msg.time_get_current_date_min, "4"], [Blockly.Msg.time_get_current_date_sec, "5"]]), "type"), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour(ESP32_TIME_COLOR), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('type'); var TOOLTIPS = { '0': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_y), '1': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_m), '2': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_d), '3': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_hour), '4': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_min), '5': Blockly.Msg.Esp32_Get_Current_Date_TOOLTIP.replace('%1', Blockly.Msg.time_get_current_date_sec) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.esp32_get_current_date = function (t) { var e = t.getFieldValue("type"); return Blockly.Python.definitions_.get_date_current_ntp = "import time\n\n", ["time.localtime()[" + e + "]", Blockly.Python.ORDER_NONE] }; var ESP32_SCREEN_COLOR = "#5bb2d6"; Blockly.Blocks.esp32_main_controller_lcd_rotation = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.OLCD_SETROTATION).appendField(new Blockly.FieldDropdown([["0°", "1"], ["90°", "2"], ["180°", "3"], ["270°", "0"]]), "DEGREE").appendField(Blockly.Msg.OLCD_SETROTATION_DEGREE), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_rotation = function (t) { return "tft.rotation(" + t.getFieldValue("DEGREE") + ")\n" }, Blockly.Blocks.esp32_main_controller_clear_screen = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.display_clear_screen), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_SCREEN_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_clear_screen = function (t) { return "tft.fill(TFT.BLACK)\n" }, Blockly.Blocks.esp32_main_controller_lcd_screen_fill = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.display_fill_screen), this.appendValueInput("COLOR").setCheck(null), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_SCREEN_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_screen_fill = function (t) { var e = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); if ("#" != e.charAt(0)) var n = "tft.fill(_TFTColor" + e + ")\n"; else if ("#" == e.charAt(0)) { var i = 0, l = 0, o = 0; try { 7 == color.length && (i = parseInt(color.substring(1, 3), 16), l = parseInt(color.substring(3, 5), 16), o = parseInt(color.substring(5, 7), 16)) } catch (t) { } n = "tft.fill(_TFTColor" + i + "," + l + "," + o + ")\n" } return n }, Blockly.Blocks.esp32_main_controller_lcd_drawpixel = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_pixel.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.display_draw_pixel), this.appendValueInput("COLOR").setCheck("String").appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POS").setCheck("String").appendField(Blockly.Msg.OLCD_COORDINATE), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawpixel = function (t) { var e = Blockly.Python.valueToCode(t, "POS", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); if ("#" == n.charAt(0)) { var i = 0, l = 0, o = 0; try { 7 == n.length && (i = parseInt(n.substring(1, 3), 16), l = parseInt(n.substring(3, 5), 16), o = parseInt(n.substring(5, 7), 16)) } catch (t) { } code = "tft.pixel((" + e + "), _TFTColor" + i + "," + l + "," + o + ")\n" } else "#" != n.charAt(0) && (code = "tft.pixel((" + e + "), _TFTColor" + n + ")\n"); return code }, Blockly.Blocks.esp32_main_controller_lcd_drawline = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_line.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.OLCD_LINE), this.appendValueInput("COLOR").setCheck("String").appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POSA").setCheck("String").appendField(Blockly.Msg.OLCD_LINE_START), this.appendValueInput("POSB").setCheck("String").appendField(Blockly.Msg.OLCD_LINE_END), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawline = function (t) { var e = Blockly.Python.valueToCode(t, "POSA", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "POSB", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); if ("#" == i.charAt(0)) { var l = 0, o = 0, _ = 0; try { 7 == i.length && (l = parseInt(i.substring(1, 3), 16), o = parseInt(i.substring(3, 5), 16), _ = parseInt(i.substring(5, 7), 16)) } catch (t) { } code = "tft.line((" + e + "), (" + n + "), _TFTColor" + l + "," + o + "," + _ + ")\n" } else "#" != i.charAt(0) && (code = "tft.line((" + e + "), (" + n + "), _TFTColor" + i + ")\n"); return code }, Blockly.Blocks.esp32_main_controller_lcd_drawlinelen = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_line.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW).appendField(new Blockly.FieldDropdown([[Blockly.Msg.display_draw_vertical, "vline"], [Blockly.Msg.display_draw_horizontal, "hline"]]), "rect_type").appendField(Blockly.Msg.OLCD_LINE), this.appendValueInput("COLOR").setCheck(null).appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POS").setCheck(null).appendField(Blockly.Msg.display_start_cord), this.appendValueInput("LENGTH").setCheck(null).appendField(Blockly.Msg.display_length), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawlinelen = function (t) { var e = t.getFieldValue("rect_type"), n = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "POS", Blockly.Python.ORDER_ATOMIC), l = Blockly.Python.valueToCode(t, "LENGTH", Blockly.Python.ORDER_ATOMIC); n = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); return code = "tft." + e + "((" + i + "), " + l + ", _TFTColor" + n + ")\n", code }, Blockly.Blocks.esp32_main_controller_lcd_drawrect = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_rectangle.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW).appendField(new Blockly.FieldDropdown([[Blockly.Msg.OLCD_FULL, "fillrect"], [Blockly.Msg.OLCD_CIRCLE, "rect"]]), "rect_type").appendField(Blockly.Msg.display_draw_rectangle), this.appendValueInput("COLOR").setCheck("String").appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POSA").setCheck("String").appendField(Blockly.Msg.OLCD_COORDINATE), this.appendValueInput("POSB").setCheck("String").appendField(Blockly.Msg.OLCD_SIZE), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawrect = function (t) { var e = t.getFieldValue("rect_type"), n = Blockly.Python.valueToCode(t, "POSA", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "POSB", Blockly.Python.ORDER_ATOMIC), l = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); return code = "tft." + e + "((" + n + "), (" + i + "), _TFTColor" + l + ")\n", code }, Blockly.Blocks.esp32_main_controller_lcd_drawcircle = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_circle.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW).appendField(new Blockly.FieldDropdown([[Blockly.Msg.OLCD_FULL, "fillcircle"], [Blockly.Msg.OLCD_STROKED, "circle"]]), "circle_type").appendField(Blockly.Msg.OLCD_CIRCLE), this.appendValueInput("COLOR").setCheck("String").appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POSA").setCheck("String").appendField(Blockly.Msg.OLCD_CENTER_POS), this.appendValueInput("RADIUS").setCheck(null).appendField(Blockly.Msg.OLCD_RADIUS), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawcircle = function (t) { var e = t.getFieldValue("circle_type"), n = Blockly.Python.valueToCode(t, "POSA", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "RADIUS", Blockly.Python.ORDER_ATOMIC), l = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); return code = "tft." + e + "((" + n + "), " + i + ", _TFTColor" + l + ")\n", code }, Blockly.Blocks.esp32_main_controller_lcd_drawqrcode = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_qr.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.display_drawqr_text), this.appendValueInput("POSA").setCheck("String").appendField(Blockly.Msg.OLCD_SET_POS), this.appendValueInput("CONTENT").setCheck("String").appendField(Blockly.Msg.display_drawqr_content), this.appendValueInput("WIDTH").setCheck("Number").appendField(Blockly.Msg.display_drawqr_padding), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawqrcode = function (t) { return "tft.drawqrcode((" + Blockly.Python.valueToCode(t, "POSA", Blockly.Python.ORDER_ATOMIC) + "), " + Blockly.Python.valueToCode(t, "CONTENT", Blockly.Python.ORDER_ATOMIC) + ", " + Blockly.Python.valueToCode(t, "WIDTH", Blockly.Python.ORDER_ATOMIC) + ")\n" }, Blockly.Blocks.esp32_main_controller_lcd_drawtext = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/lcd_draw_text.png", 42, 42, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.display_draw_text), this.appendValueInput("COLOR").setCheck("String").appendField(Blockly.Msg.OLCD_COLOR), this.appendValueInput("POSA").setCheck("String").appendField(Blockly.Msg.display_start_cord), this.appendValueInput("CONTENT").setCheck("String").appendField(Blockly.Msg.display_draw_text_content), this.appendValueInput("SIZE").setCheck("Number").appendField(Blockly.Msg.display_draw_text_size), this.appendDummyInput().appendField(Blockly.Msg.display_draw_text_return).appendField(new Blockly.FieldCheckbox("TRUE"), "TextCheckBox"), this.setInputsInline(!1), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_drawtext = function (t) { var e = Blockly.Python.valueToCode(t, "POSA", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "CONTENT", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "SIZE", Blockly.Python.ORDER_ATOMIC), l = "TRUE" == t.getFieldValue("TextCheckBox") ? "True" : "False", o = Blockly.Python.valueToCode(t, "COLOR", Blockly.Python.ORDER_ATOMIC); return code = "tft.text((" + e + "), " + n + ", _TFTColor" + o + ", sysfont, " + i + ", nowrap=" + l + ")\n", code }, Blockly.Blocks.esp32_main_controller_rgb_value = { init: function () { this.appendValueInput("rgb_value_r").setCheck(null).appendField(Blockly.Msg.display_red), this.appendValueInput("rgb_value_g").setCheck(null).appendField(Blockly.Msg.display_green), this.appendValueInput("rgb_value_b").setCheck(null).appendField(Blockly.Msg.display_blue), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(ESP32_SCREEN_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_rgb_value = function (t) { var e = Blockly.Python.valueToCode(t, "rgb_value_r", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "rgb_value_g", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "rgb_value_b", Blockly.Python.ORDER_ATOMIC), l = parseInt(e, 10), o = parseInt(n, 10), _ = parseInt(i, 10); return _r = l.toString(16), _g = o.toString(16), _b = _.toString(16), 1 == _r.length && (_r = "0" + _r), 1 == _g.length && (_g = "0" + _g), 1 == _b.length && (_b = "0" + _b), [e + "," + n + "," + i, Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_main_controller_lcd_color_hex_to_rgb = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.COLOR).appendField(new Blockly.FieldColour("#ff0000"), "COLOR"), this.setOutput(!0, null), this.setColour("#5bb2d6"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_lcd_color_hex_to_rgb = function (t) { var e, n, i, l; return t = t.getFieldValue("COLOR"), [(l = i = n = 0, 4 == (e = t).length ? (n = "0x" + e[1] + e[1], i = "0x" + e[2] + e[2], l = "0x" + e[3] + e[3]) : 7 == e.length && (n = "0x" + e[1] + e[2], i = "0x" + e[3] + e[4], l = "0x" + e[5] + e[6]), +n + "," + +i + "," + +l), Blockly.Python.ORDER_CONDITIONAL] }; var ESP32_WIFI_COLOR = "#3062c1"; Blockly.Blocks.esp32_main_controller_wifi_enable_hotspot_mode = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/hotspot_setup.png", 38, 38, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.wifi_setup_hotspot), this.appendValueInput("SSID").setCheck(null).appendField(Blockly.Msg.wifi_hotspot_ssid), this.appendValueInput("PASSWORD").setCheck(null).appendField(Blockly.Msg.wifi_hotspot_pass), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Enable_Hotspot_Mode_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_wifi_enable_hotspot_mode = function (t) { var e = Blockly.Python.valueToCode(t, "SSID", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "PASSWORD", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.definitions_.import_network = "import network\n_WIFI = network.WLAN(network.STA_IF)\n_WIFI.active(False)\n_WIFI = network.WLAN(network.AP_IF)\n_WIFI.active(True)\n_WIFI.config(essid=" + e + ", password=" + n + ", authmode=2, channel=11, hidden=0)\n\n", code = "", code }, Blockly.Blocks.esp32_main_controller_wifi_connect_internet = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/wifi_setup.png", 38, 38, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.wifi_connect_router), this.appendValueInput("ssid").setCheck(null).appendField(Blockly.Msg.wifi_router_ssid), this.appendValueInput("password").setCheck(null).appendField(Blockly.Msg.wifi_router_pass), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Connect_Internet_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_wifi_connect_internet = function (t) { var e = Blockly.Python.valueToCode(t, "ssid", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "password", Blockly.Python.ORDER_ATOMIC); Blockly.Python.definitions_.esp32_import_network = "import network\nif (network.WLAN(network.STA_IF).isconnected()) == False:\n _WIFI = network.WLAN(network.AP_IF)\n _WIFI.active(False)\n _WIFI = network.WLAN(network.STA_IF)\n _WIFI.active(True)\n _WIFI.connect(" + e + ", " + n + ")\nelse:\n pass\n\n"; return "" }, Blockly.Blocks.esp32_main_controller_wifi_disconnect = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_router_disconnect), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Disconnect_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_wifi_disconnect = function (t) { return "_WIFI.active(False)\n" }, Blockly.Blocks.esp32_main_controller_get_wifi_devices_number = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_hotspot_get_clients), this.setOutput(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Get_Wifi_Devices_Number_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_get_wifi_devices_number = function (t) { return ['len(_WIFI.status("stations"))', Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_wifi_acquiring_equipment = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_hotspot_get_list), this.setOutput(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Acquiring_Equipment_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_wifi_acquiring_equipment = function (t) { return ['_WIFI.status("stations")', Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_get_wifi_connection_status = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_router_connection_status), this.setOutput(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Get_Wifi_Connection_Status_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_get_wifi_connection_status = function (t) { return ["_WIFI.isconnected()", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_wifi_close = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_close_hotspot), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Close_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_wifi_close = function (t) { return ["_WIFI.active(False)", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_wifi_get_info = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_router_get_info).appendField(new Blockly.FieldDropdown([[Blockly.Msg.wifi_router_device_ip, "0"], [Blockly.Msg.wifi_router_device_mask, "1"], [Blockly.Msg.wifi_router_device_gateway, "2"], [Blockly.Msg.wifi_router_device_dns, "3"]]), "wifi_info"), this.setOutput(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('wifi_info');var TOOLTIPS = {'0': Blockly.Msg.Esp32_Main_Controller_Wifi_Get_Info_TOOLTIP.replace('%1', Blockly.Msg.wifi_router_device_ip),'1': Blockly.Msg.Esp32_Main_Controller_Wifi_Get_Info_TOOLTIP.replace('%1', Blockly.Msg.wifi_router_device_mask),'2': Blockly.Msg.Esp32_Main_Controller_Wifi_Get_Info_TOOLTIP.replace('%1', Blockly.Msg.wifi_router_device_gateway),'3': Blockly.Msg.Esp32_Main_Controller_Wifi_Get_Info_TOOLTIP.replace('%1', Blockly.Msg.wifi_router_device_dns)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_main_controller_wifi_get_info = function (t) { return ["_WIFI.ifconfig()[" + t.getFieldValue("wifi_info") + "]", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.esp32_main_controller_wifi_ntptime = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/ntptime_header.png", 38, 38, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.wifi_ntptime_title), this.appendDummyInput().appendField(Blockly.Msg.wifi_ntptime_set_timezone).appendField(new Blockly.FieldDropdown([[Blockly.Msg.wifi_ntptime_utc8, "8"], [Blockly.Msg.wifi_ntptime_utc9, "9"], [Blockly.Msg.wifi_ntptime_utc10, "10"], [Blockly.Msg.wifi_ntptime_utc11, "11"], [Blockly.Msg.wifi_ntptime_utc12, "12"], [Blockly.Msg.wifi_ntptime_utcm12, "-12"], [Blockly.Msg.wifi_ntptime_utcm11, "-11"], [Blockly.Msg.wifi_ntptime_utcm10, "-10"], [Blockly.Msg.wifi_ntptime_utcm9, "-9"], [Blockly.Msg.wifi_ntptime_utcm8, "-8"], [Blockly.Msg.wifi_ntptime_utcm7, "-7"], [Blockly.Msg.wifi_ntptime_utcm6, "-6"], [Blockly.Msg.wifi_ntptime_utcm5, "-5"], [Blockly.Msg.wifi_ntptime_utcm4, "-4"], [Blockly.Msg.wifi_ntptime_utcm3, "-3"], [Blockly.Msg.wifi_ntptime_utcm2, "-2"], [Blockly.Msg.wifi_ntptime_utcm1, "-1"], [Blockly.Msg.wifi_ntptime_utc0, "0"], [Blockly.Msg.wifi_ntptime_utc1, "1"], [Blockly.Msg.wifi_ntptime_utc2, "2"], [Blockly.Msg.wifi_ntptime_utc3, "3"], [Blockly.Msg.wifi_ntptime_utc4, "4"], [Blockly.Msg.wifi_ntptime_utc5, "5"], [Blockly.Msg.wifi_ntptime_utc6, "6"], [Blockly.Msg.wifi_ntptime_utc7, "7"]]), "timezone"), this.appendDummyInput().appendField(Blockly.Msg.wifi_ntptime_time_server).appendField(new Blockly.FieldTextInput("time.windows.com"), "website"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_WIFI_COLOR), this.setHelpUrl("");this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Wifi_Ntptime_TOOLTIP); } }, Blockly.Python.esp32_main_controller_wifi_ntptime = function (t) { var e = t.getFieldValue("timezone"), n = t.getFieldValue("website"); return Blockly.Python.definitions_.esp32_main_controller_wifi_ntptime_def = "import network\nimport ntptime\n\n", "ntptime.settime(" + e + ', "' + n + '")\n' }, Blockly.Blocks.esp32_main_controller_ThingSpeak_send_data = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/thingspeak.png", 190, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_send_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_send_api_set).appendField(new Blockly.FieldTextInput("ENTER_YOUR_CHANNEL_API_KEY"), "key"), this.appendValueInput("data").setCheck(null).appendField(Blockly.Msg.iotservice_thingspeak_send_data_1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_IOT_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_ThingSpeak_send_data = function (t) { var e = t.getFieldValue("key"), n = Blockly.Python.valueToCode(t, "data", Blockly.Python.ORDER_ATOMIC); Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n"; var i = '_THINGSPEAK_CHANNEL_API = "' + e + '"\n'; Blockly.Python.addSetup("esp32_main_controller_ThingSpeak_send_data", i); i = "_THINGSPEAK_DATA1 = " + n + "\n"; return i += '_THINGSPEAK_ENDPOINT = "http://api.thingspeak.com/update?api_key=" + _THINGSPEAK_CHANNEL_API + "&field1=" + _THINGSPEAK_DATA1\n', i += "_THINGSPEAK_REQEUST = urequests.get(_THINGSPEAK_ENDPOINT)\n" }, Blockly.Blocks.CocoRobo_set_max = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/http_server_header.png", 130, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.internet_server_setup), this.appendDummyInput().appendField(Blockly.Msg.internet_server_set_max).appendField(new Blockly.FieldTextInput("5"), "number"), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour("#183895"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.CocoRobo_set_max = function (t) { var e = t.getFieldValue("number"); Blockly.Python.definitions_.import_socket = "import usocket as socket"; var n = "_S = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n"; n += "_S.bind((_WIFI.ifconfig()[0], 80))\n", n += "_S.listen(" + e + ")\n", Blockly.Python.addSetup("CocoRobo_set_max", n); n = "_SERVER_CONN, _SERVER_ADDR = _S.accept()\n"; return n += "_SERVER_REQUEST = _CONN.recv(1024)\n" }, Blockly.Blocks.CocoRobo_get_source = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.internet_server_set_source), this.setOutput(!0, null), this.setColour("#183895"), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.CocoRobo_get_source = function (t) { return ["str(_SERVER_ADDR)\n", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.CocoRobo_get = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.internet_response_http_content_title).appendField(new Blockly.FieldDropdown([[Blockly.Msg.internet_response_text, "text"], [Blockly.Msg.internet_response_content, "content"], [Blockly.Msg.internet_response_status, "state"], [Blockly.Msg.internet_response_json, "json"], [Blockly.Msg.internet_response_encode, "code"], [Blockly.Msg.internet_response_reason, "reason"]]), "op"), this.setOutput(!0, null), this.setColour("#183895"), this.setTooltip(Blockly.Msg.CocoRobo_get_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.CocoRobo_get = function (t) { var e = t.getFieldValue("op"), n = "_SEND_HTTP_REQUEST.text"; return "text" == e ? n = "_SEND_HTTP_REQUEST.text" : "content" == e ? n = "_SEND_HTTP_REQUEST.content" : "state" == e ? n = "_SEND_HTTP_REQUEST.status_code" : "json" == e ? n = "_SEND_HTTP_REQUEST.json()" : "code" == e ? n = "_SEND_HTTP_REQUEST.encoding" : "reason" == e && (n = "_SEND_HTTP_REQUEST.reason"), [n, Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.iot_system_run = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_RUN), this.appendValueInput("PATH").setCheck(null).appendField(Blockly.Msg.system_code_path), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(32), this.setTooltip(Blockly.Msg.Iot_System_Run_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_run = function (t) { return "exec(open(" + Blockly.Python.valueToCode(t, "PATH", Blockly.Python.ORDER_ATOMIC) + ").read())\n" }, Blockly.Blocks.iot_system_create = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_CREATE), this.appendValueInput("PATH").setCheck(null).appendField(Blockly.Msg.SYSTEM_CREATE_F), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(32), this.setTooltip(Blockly.Msg.Iot_System_Create_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_create = function (t) { var e = Blockly.Python.valueToCode(t, "PATH", Blockly.Python.ORDER_ATOMIC), n = "def _CREATE_TEXT_FILE(_path):\n"; return n += " f = open(_path, 'w')\n", n += " f.close()\n", Blockly.Python.addFunction("_CREATE_TEXT_FILE", n), n = "_CREATE_TEXT_FILE(" + e + ")\n" }, Blockly.Blocks.iot_system_write = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_WRITE), this.appendValueInput("PATH").setCheck(null).appendField(Blockly.Msg.SYSTEM_WRITE_F), this.appendValueInput("WPATH").setCheck(null).appendField(Blockly.Msg.SYSTEM_WRITE_W), this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_WRITE_S).appendField(new Blockly.FieldDropdown([[Blockly.Msg.SYSTEM_WRITE_S_N, "newline"], [Blockly.Msg.SYSTEM_WRITE_S_C, "comma"], [Blockly.Msg.SYSTEM_WRITE_S_S, "space"], [Blockly.Msg.SYSTEM_WRITE_S_SE, "semicolon"]]), "separator"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(32), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('separator'); var TOOLTIPS = { 'newline': Blockly.Msg.Iot_System_Write_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_N), 'comma': Blockly.Msg.Iot_System_Write_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_C), 'space': Blockly.Msg.Iot_System_Write_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_S), 'semicolon': Blockly.Msg.Iot_System_Write_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_SE) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.iot_system_write = function (t) { var e = Blockly.Python.valueToCode(t, "PATH", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "WPATH", Blockly.Python.ORDER_ATOMIC), i = t.getFieldValue("separator"), l = "def _CREATE_TEXT_FILE_WITH_CONTENT(_path, _data, _sep):\n"; return l += " f = open(_path, 'a')\n", l += " f.write(_data + _sep)\n", l += " f.close()\n", Blockly.Python.addFunction("_CREATE_TEXT_FILE_WITH_CONTENT", l), l = "_CREATE_TEXT_FILE_WITH_CONTENT(" + e + ", " + n + ", '\\r\\n')", "newline" == i ? l = "_CREATE_TEXT_FILE_WITH_CONTENT(" + e + ", " + n + ", '\\r\\n')" : "comma" == i ? l = "_CREATE_TEXT_FILE_WITH_CONTENT(" + e + ", " + n + ", ',')" : "space" == i ? l = "_CREATE_TEXT_FILE_WITH_CONTENT(" + e + ", " + n + ", ' ')" : "semicolon" == i && (l = "_CREATE_TEXT_FILE_WITH_CONTENT(" + e + ", " + n + ", ';')"), l }, Blockly.Blocks.iot_system_input = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_INPUT), this.appendValueInput("PATH").setCheck(null).appendField(Blockly.Msg.SYSTEM_WRITE_F), this.appendDummyInput().appendField(Blockly.Msg.SYSTEM_WRITE_S).appendField(new Blockly.FieldDropdown([[Blockly.Msg.SYSTEM_WRITE_S_N, "newline"], [Blockly.Msg.SYSTEM_WRITE_S_C, "comma"], [Blockly.Msg.SYSTEM_WRITE_S_S, "space"], [Blockly.Msg.SYSTEM_WRITE_S_SE, "semicolon"]]), "separator"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(32), this.setHelpUrl(""); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('separator'); var TOOLTIPS = { 'newline': Blockly.Msg.Iot_System_Input_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_N), 'comma': Blockly.Msg.Iot_System_Input_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_C), 'space': Blockly.Msg.Iot_System_Input_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_S), 'semicolon': Blockly.Msg.Iot_System_Input_TOOLTIP.replace('%1', Blockly.Msg.SYSTEM_WRITE_S_SE) }; return TOOLTIPS[mode]; }); } }, Blockly.Python.iot_system_input = function (t) { var e = Blockly.Python.valueToCode(t, "PATH", Blockly.Python.ORDER_ATOMIC), n = t.getFieldValue("separator"), i = "def _GET_LIST_FROM_FILE(_path, _sep):\n"; return i += " f = open(_path, 'r')\n", i += " result = f.read().split(_sep)\n", i += " f.close()\n", i += " return result\n", Blockly.Python.addFunction("_GET_LIST_FROM_FILE", i), i = "_GET_LIST_FROM_FILE(" + e + ", '\\r\\n')", "newline" == n ? i = "_GET_LIST_FROM_FILE(" + e + ", '\\r\\n')" : "comma" == n ? i = "_GET_LIST_FROM_FILE(" + e + ", ',')" : "space" == n ? i = "_GET_LIST_FROM_FILE(" + e + ", ' ')" : "semicolon" == n && (i = "_GET_LIST_FROM_FILE(" + e + ", ';')"), i }, Blockly.Blocks.iot_system_restart = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.SYSTEM), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setColour("#22398e"), this.setTooltip(Blockly.Msg.Iot_System_Restart_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_restart = function (t) { Blockly.Python.definitions_.import_machine = "import machine"; return "machine.reset()\n" }, Blockly.Blocks.iot_system_get = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.system_get_size), this.setOutput(!0, null), this.setColour("#22398e"), this.setTooltip(Blockly.Msg.Iot_System_Get_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_get = function (t) { return ["_MCU_FREESPACE", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.iot_system_mac = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.system_get_mac), this.setOutput(!0, null), this.setColour("#22398e"), this.setTooltip(Blockly.Msg.Iot_System_Mac_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_mac = function (t) { Blockly.Python.definitions_.import_machine_ub = "import machine, ubinascii"; return ["ubinascii.hexlify(machine.unique_id()).decode().upper()", Blockly.Python.ORDER_CONDITIONAL] }, Blockly.Blocks.iot_system_get_cocorobo_id = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.system_get_cocorobo_cid), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour("#22398e"), this.setTooltip(Blockly.Msg.Iot_System_Get_Cocorobo_Id_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_system_get_cocorobo_id = function (t) { Blockly.Python.definitions_.import_cocorobo_cid = "from cocorobo import cid\n"; return ["cid._GET_MACHINE_ID().strip('\\n')", Blockly.Python.ORDER_NONE] }; var ESP32_IOT_COLOR = "#3c7683", IFTTT_BLOCK_COLOR = "#ff3b00", ONENET_BLOCK_COLOR = "#00b5ff"; Blockly.Blocks.esp32_main_controller_onenet_setup = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/onenet_setup_logo.png", 130, 70, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_setup), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_server).appendField(new Blockly.FieldTextInput("183.230.40.39"), "server_ip"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_productid).appendField(new Blockly.FieldTextInput("ENTER_YOUR_PRODUCT_ID"), "product_id"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_productkey).appendField(new Blockly.FieldTextInput("ENTER_YOUR_PRODUCT_KEY"), "product_api_key"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_deviceid).appendField(new Blockly.FieldTextInput("ENTER_YOUR_DEVICE_ID"), "device_id"), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_onenet_setup = function (t) { t.getFieldValue("server_ip"), t.getFieldValue("product_id"), t.getFieldValue("product_api_key"), t.getFieldValue("device_id"); return "...\n" }, Blockly.Blocks.iot_service_onenet = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/onenet_setup_logo.png", 120, 70, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_send), this.itemCount_ = 1, this.updateShape_(), this.setMutator(new Blockly.Mutator(["iot_service_onenet_create_with_item"])), this.setColour(ONENET_BLOCK_COLOR), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setTooltip(""), this.setHelpUrl("") }, mutationToDom: function () { var t = document.createElement("mutation"); return t.setAttribute("items", this.itemCount_), t }, domToMutation: function (t) { this.itemCount_ = parseInt(t.getAttribute("items"), 10), this.updateShape_() }, decompose: function (t) { var e = t.newBlock("iot_service_onenet_create_with_container"); e.initSvg(); for (var n = e.getInput("STACK").connection, i = 0; i < this.itemCount_; i++) { var l = t.newBlock("iot_service_onenet_create_with_item"); l.initSvg(), n.connect(l.previousConnection), n = l.nextConnection } return e }, compose: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = []; e;)n.push(e.valueConnection_), e = e.nextConnection && e.nextConnection.targetBlock(); for (var i = 0; i < this.itemCount_; i++) { var l = this.getInput("ADD" + i).connection.targetConnection; l && -1 == n.indexOf(l) && l.disconnect() } this.itemCount_ = n.length, this.updateShape_(); for (i = 0; i < this.itemCount_; i++)Blockly.Mutator.reconnect(n[i], this, "ADD" + i) }, saveConnections: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = 0; e;) { var i = this.getInput("ADD" + n); e.valueConnection_ = i && i.connection.targetConnection, n++, e = e.nextConnection && e.nextConnection.targetBlock() } }, updateShape_: function () { for (var t = 0; t < this.itemCount_; t++) { if (!this.getInput("ADD" + t)) this.appendValueInput("ADD" + t).appendField(Blockly.Msg.iotservice_onenet_mqtt_send_item).appendField(new Blockly.FieldTextInput("Property" + t), "field" + t) } for (; this.getInput("ADD" + t);)this.removeInput("ADD" + t), t++ } }, Blockly.Blocks.iot_service_onenet_create_with_container = { init: function () { this.setColour(ONENET_BLOCK_COLOR), this.appendDummyInput().appendField("Items"), this.appendStatementInput("STACK"), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Blocks.iot_service_onenet_create_with_item = { init: function () { this.setColour(ONENET_BLOCK_COLOR), this.appendDummyInput().appendField("Field"), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Python.iot_service_onenet = function (t) { return "" }, Blockly.Blocks.esp32_main_controller_onenet_when_receive_msg = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_receive), this.appendValueInput("content").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_receive_when), this.appendStatementInput("exec").setCheck(null).appendField(Blockly.Msg.iotservice_onenet_mqtt_receive_exec), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_onenet_when_receive_msg = function (t) { Blockly.Python.valueToCode(t, "content", Blockly.Python.ORDER_ATOMIC), Blockly.Python.statementToCode(t, "exec"); return "...\n" }, Blockly.Blocks.esp32_main_controller_onenet_disconnect = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.iotservice_onenet_mqtt_disconnect), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_onenet_disconnect = function (t) { return "\n" }, Blockly.Blocks.esp32_main_controller_ifttt_send_data = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/ifttt_webhook.png", 110, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_send_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_send_webhook).appendField(new Blockly.FieldTextInput("ENTER_YOUR_API_KEY"), "ifttt_api_key"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_send_eventname).appendField(new Blockly.FieldTextInput("ENTER_YOUR_EVENT_NAME"), "ifttt_event"), this.appendValueInput("ifttt_data_1").setCheck(null).appendField(Blockly.Msg.iotservice_ifttt_send_1), this.appendValueInput("ifttt_data_2").setCheck(null).appendField(Blockly.Msg.iotservice_ifttt_send_2), this.appendValueInput("ifttt_data_3").setCheck(null).appendField(Blockly.Msg.iotservice_ifttt_send_3), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(IFTTT_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Ifttt_Send_Data_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_ifttt_send_data = function (t) { var e = t.getFieldValue("ifttt_api_key"), n = t.getFieldValue("ifttt_event"), i = Blockly.Python.valueToCode(t, "ifttt_data_1", Blockly.Python.ORDER_ATOMIC), l = Blockly.Python.valueToCode(t, "ifttt_data_2", Blockly.Python.ORDER_ATOMIC), o = Blockly.Python.valueToCode(t, "ifttt_data_3", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n", '_IFTTT_POST_API_KEY = "' + e + '"\n_IFTTT_POST_EVENT_NAME = "' + n + '"\n_IFTTT_POST_ENDPOINT = "http://maker.ifttt.com/trigger/"+ _IFTTT_POST_EVENT_NAME + "/with/key/" + _IFTTT_POST_API_KEY\n_IFTTT_POST_DATA = \'{"value1":"\'+ str(' + i + ') +\'","value2":"\'+ str(' + l + ') +\'","value3":"\'+ str(' + o + ') +\'"}\'\n_IFTTT_POST_REQUEST = urequests.post(_IFTTT_POST_ENDPOINT, data = _IFTTT_POST_DATA , headers = { "Content-type": "application/json" }, timeout=60)\n\n' }, Blockly.Blocks.esp32_main_controller_ifttt_touched = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/ifttt_webhook.png", 110, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_trigger_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_trigger_webhook).appendField(new Blockly.FieldTextInput("ENTER_YOUR_API_KEY"), "key"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_ifttt_trigger_eventname).appendField(new Blockly.FieldTextInput("ENTER_YOUR_EVENT_NAME"), "timename"), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(IFTTT_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Main_Controller_Ifttt_Touched_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_main_controller_ifttt_touched = function (t) { var e = t.getFieldValue("key"), n = t.getFieldValue("timename"); Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n"; var i = '_IFTTT_TRIGGER_EVENT_NAME = "' + n + '"\n'; return i += '_IFTTT_TRIGGER_API_KEY = "' + e + '"\n', i += '_IFTTT_TRIGGER_ENDPOINT = "https://maker.ifttt.com/trigger/" + _IFTTT_TRIGGER_EVENT_NAME + "/with/key/" + _IFTTT_TRIGGER_API_KEY\n', Blockly.Python.addSetup("esp32_main_controller_ifttt_touched", i), i = "_IFTTT_GET_REQUEST = urequests.get(_IFTTT_TRIGGER_ENDPOINT, timeout=60)\n" }, IOT_THINGSPEAK_COLOR = "#1b379f", Blockly.Blocks.iot_service_thingspeak = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/thingspeak.png", 170, 45, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_send_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_send_api).appendField(new Blockly.FieldTextInput("ENTET_YOUT_CHANNEL_WRITE_API_KEY"), "t_api"), this.itemCount_ = 1, this.updateShape_(), this.setMutator(new Blockly.Mutator(["iot_service_thingspeak_create_with_item"])), this.setColour(IOT_THINGSPEAK_COLOR), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setTooltip(Blockly.Msg.Iot_Service_Thingspeak_TOOLTIP), this.setHelpUrl("") }, mutationToDom: function () { var t = document.createElement("mutation"); return t.setAttribute("items", this.itemCount_), t }, domToMutation: function (t) { this.itemCount_ = parseInt(t.getAttribute("items"), 10), this.updateShape_() }, decompose: function (t) { var e = t.newBlock("iot_service_thingspeak_create_with_container"); e.initSvg(); for (var n = e.getInput("STACK").connection, i = 0; i < this.itemCount_; i++) { var l = t.newBlock("iot_service_thingspeak_create_with_item"); l.initSvg(), n.connect(l.previousConnection), n = l.nextConnection } return e }, compose: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = []; e;)n.push(e.valueConnection_), e = e.nextConnection && e.nextConnection.targetBlock(); for (var i = 0; i < this.itemCount_; i++) { var l = this.getInput("ADD" + i).connection.targetConnection; l && -1 == n.indexOf(l) && l.disconnect() } this.itemCount_ = n.length, this.updateShape_(); for (i = 0; i < this.itemCount_; i++)Blockly.Mutator.reconnect(n[i], this, "ADD" + i) }, saveConnections: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = 0; e;) { var i = this.getInput("ADD" + n); e.valueConnection_ = i && i.connection.targetConnection, n++, e = e.nextConnection && e.nextConnection.targetBlock() } }, updateShape_: function () { for (var t = 0; t < this.itemCount_; t++) { if (!this.getInput("ADD" + t)) this.appendValueInput("ADD" + t).appendField("Field " + (t + 1) + ":") } for (; this.getInput("ADD" + t);)this.removeInput("ADD" + t), t++ } }, Blockly.Blocks.iot_service_thingspeak_create_with_container = { init: function () { this.setColour(IOT_THINGSPEAK_COLOR), this.appendDummyInput().appendField("Items"), this.appendStatementInput("STACK"), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Blocks.iot_service_thingspeak_create_with_item = { init: function () { this.setColour(IOT_THINGSPEAK_COLOR), this.appendDummyInput().appendField("Field"), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Python.iot_service_thingspeak = function (t) { Blockly.Python.valueToCode(t, "first_input", Blockly.Python.ORDER_ATOMIC); var e = t.getFieldValue("t_api"); Blockly.Python.addVariable("_THINGSPEAK_REQUEST", "", !0), Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n"; for (var n = "http://api.thingspeak.com/update?api_key=" + e, i = 0; i < this.itemCount_; i++)n += "&" + ("field" + (i + 1)) + '="+str(' + (Blockly.Python.valueToCode(this, "ADD" + i, Blockly.Python.ORDER_NONE) || "") + ')+"'; return '_THINGSPEAK_ENDPOINT = "' + n + '"\n_THINGSPEAK_REQUEST = urequests.get(_THINGSPEAK_ENDPOINT,timeout=60)\n' }, Blockly.Blocks.iot_service_thingspeak_read = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/thingspeak.png", 170, 45, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_query_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_query_api).appendField(new Blockly.FieldTextInput("ENTER_YOUR_CHANNEL_READ_API_KEY"), "api_key"), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_channel_id).appendField(new Blockly.FieldTextInput("ENTER_YOUR_CHANNEL_ID"), "id"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(IOT_THINGSPEAK_COLOR), this.setTooltip(Blockly.Msg.Iot_Service_Thingspeak_Read_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_service_thingspeak_read = function (t) { var e = t.getFieldValue("api_key"), n = t.getFieldValue("id"); return Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n", Blockly.Python.addVariable("_THINGSPEAK_READ_REQUEST", "", !0), '_THINGSPEAK_READ_REQUEST = urequests.get("https://api.thingspeak.com/channels/" + "' + n + '" + "/feeds.json?api_key=" + "' + e + '",timeout=60)\n' }, Blockly.Blocks.iot_service_thingspeak_read_total = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_read_total), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour(IOT_THINGSPEAK_COLOR), this.setTooltip(Blockly.Msg.Iot_Service_Thingspeak_Read_Total_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_service_thingspeak_read_total = function (t) { return ["_THINGSPEAK_READ_REQUEST.json()['channel']['last_entry_id']", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.iot_service_thingspeak_read_specific = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeak_get_title), this.appendValueInput("entry").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeaK_get_field), this.appendValueInput("field").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.iotservice_thingspeaK_get_value), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(IOT_THINGSPEAK_COLOR), this.setTooltip(Blockly.Msg.Iot_Service_Thingspeak_Read_Specific_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_service_thingspeak_read_specific = function (t) { return ["_THINGSPEAK_READ_REQUEST.json()['feeds'][" + Blockly.Python.valueToCode(t, "entry", Blockly.Python.ORDER_ATOMIC) + "]['field" + Blockly.Python.valueToCode(t, "field", Blockly.Python.ORDER_ATOMIC) + "']", Blockly.Python.ORDER_NONE] }; var COCOCLOUD_BLOCK_COLOR = "#4085de"; Blockly.Blocks.iot_service_cococloud = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/cococloud_send.png", 180, 65, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_send_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_send_title_api).appendField(new Blockly.FieldTextInput("ENTET_YOUT_EVENT_API_KEY"), "t_api"), this.itemCount_ = 1, this.updateShape_(), this.setMutator(new Blockly.Mutator(["iot_service_cococloud_create_with_item"])), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setTooltip(Blockly.Msg.Iot_Service_Cococloud_TOOLTIP), this.setHelpUrl("") }, mutationToDom: function () { var t = document.createElement("mutation"); return t.setAttribute("items", this.itemCount_), t }, domToMutation: function (t) { this.itemCount_ = parseInt(t.getAttribute("items"), 10), this.updateShape_() }, decompose: function (t) { var e = t.newBlock("iot_service_cococloud_create_with_container"); e.initSvg(); for (var n = e.getInput("STACK").connection, i = 0; i < this.itemCount_; i++) { var l = t.newBlock("iot_service_cococloud_create_with_item"); l.initSvg(), n.connect(l.previousConnection), n = l.nextConnection } return e }, compose: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = []; e;)n.push(e.valueConnection_), e = e.nextConnection && e.nextConnection.targetBlock(); for (var i = 0; i < this.itemCount_; i++) { var l = this.getInput("ADD" + i).connection.targetConnection; l && -1 == n.indexOf(l) && l.disconnect() } this.itemCount_ = n.length, this.updateShape_(); for (i = 0; i < this.itemCount_; i++)Blockly.Mutator.reconnect(n[i], this, "ADD" + i) }, saveConnections: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = 0; e;) { var i = this.getInput("ADD" + n); e.valueConnection_ = i && i.connection.targetConnection, n++, e = e.nextConnection && e.nextConnection.targetBlock() } }, updateShape_: function () { for (var t = 0; t < this.itemCount_; t++) { if (!this.getInput("ADD" + t)) this.appendValueInput("ADD" + t).appendField(Blockly.Msg.iotservice_cococloud_send_property).appendField(new Blockly.FieldTextInput("Property" + t), "field" + t) } for (; this.getInput("ADD" + t);)this.removeInput("ADD" + t), t++ } }, Blockly.Blocks.iot_service_cococloud_create_with_container = { init: function () { this.setColour(COCOCLOUD_BLOCK_COLOR), this.appendDummyInput().appendField("Items"), this.appendStatementInput("STACK"), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Blocks.iot_service_cococloud_create_with_item = { init: function () { this.setColour(COCOCLOUD_BLOCK_COLOR), this.appendDummyInput().appendField("Field"), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Python.iot_service_cococloud = function (t) { var e = t.getFieldValue("t_api"); Blockly.Python.addVariable("_COCOCLOUD_SEND_REQUEST", "", !0), Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n"; for (var n = "'{", i = 0; i < this.itemCount_; i++)n += '"' + t.getFieldValue("field" + i) + '":"\' + str(' + (Blockly.Python.valueToCode(this, "ADD" + i, Blockly.Python.ORDER_NONE) || "") + ") + '\","; return '_COCOCLOUD_SEND_ENDPOINT = "http://api.cocorobo.cn/iot/data/eventAPIKey/"+ "' + e + '"\n_COCOCLOUD_SEND_DATA = ' + (n + "}'").slice(0, -3) + '}\'\n_COCOCLOUD_SEND_REQUEST = urequests.post(_COCOCLOUD_SEND_ENDPOINT, data = _COCOCLOUD_SEND_DATA , headers = { "Content-type": "application/json" }, timeout = 30)\n' }, Blockly.Blocks.iot_service_cococloud_read = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/cococloud_get.png", 200, 70, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_get_title), this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_get_api).appendField(new Blockly.FieldTextInput("ENTET_YOUT_EVENT_API_KEY"), "api"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Iot_Service_Cococloud_Read_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_service_cococloud_read = function (t) { var e = t.getFieldValue("api"); return Blockly.Python.addVariable("_COCOCLOUD_READ_REQUEST", "", !0), Blockly.Python.definitions_.import_urequests = "import urequests\nimport ujson as json\n", '_COCOCLOUD_READ_REQUEST = urequests.get("http://api.cocorobo.cn/iot/data/eventAPIKey/" + "' + e + '", timeout=60)\n' }, Blockly.Blocks.iot_service_cococloud_read_data = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_get_property), this.appendValueInput("property").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.iotservice_cococloud_get_data), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Iot_Service_Cococloud_Read_Data_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.iot_service_cococloud_read_data = function (t) { return ["_COCOCLOUD_READ_REQUEST.json()['data'][0][" + Blockly.Python.valueToCode(t, "property", Blockly.Python.ORDER_ATOMIC) + "]", Blockly.Python.ORDER_NONE] }; var NETWORK_BLOCK_COLOR = "#16318a"; Blockly.Blocks.esp32_network_http_get = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/http_header_get.png", 180, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.internet_http_get_title), this.appendValueInput("http_get_url").setCheck(null).appendField(Blockly.Msg.internet_http_get_url), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Network_Http_Get_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_network_http_get = function (t) { var e = Blockly.Python.valueToCode(t, "http_get_url", Blockly.Python.ORDER_ATOMIC); Blockly.Python.addVariable("_SEND_HTTP_GET_ENDPOINT", "", !0), Blockly.Python.addVariable("_SEND_HTTP_REQUEST", "", !0), Blockly.Python.definitions_.import_urequests = "import urequests as requests\nimport ujson as json\n\n_SEND_HTTP_GET_ENDPOINT = " + e + "\n"; return "_SEND_HTTP_REQUEST = requests.get(_SEND_HTTP_GET_ENDPOINT)\n" }, Blockly.Blocks.esp32_network_http_post = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/http_header_post.png", 180, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.internet_http_post_title), this.appendValueInput("http_post_url").setCheck(null).appendField(Blockly.Msg.internet_http_post_url), this.appendValueInput("data").setCheck(null).appendField(Blockly.Msg.internet_http_post_json), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Network_Http_Post_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_network_http_post = function (t) { var e = Blockly.Python.valueToCode(t, "http_post_url", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "data", Blockly.Python.ORDER_ATOMIC); return Blockly.Python.addVariable("_SEND_HTTP_POST_ENDPOINT", "", !0), Blockly.Python.addVariable("_SEND_HTTP_REQUEST", "", !0), Blockly.Python.definitions_.import_urequests = "import urequests as requests\nimport ujson as json\n\n_SEND_HTTP_POST_ENDPOINT = " + e + "\n", "_SEND_HTTP_POST_DATA = '" + n + '\'\n_SEND_HTTP_REQUEST = requests.post(_SEND_HTTP_POST_ENDPOINT, data = _SEND_HTTP_POST_DATA , headers = { "Content-type": "application/json" })\n' }, Blockly.Blocks.esp32_network_http_get_data_from_local_server = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.internet_http_get_server_data_title), this.appendDummyInput().appendField(Blockly.Msg.internet_http_get_server_data_type).appendField(new Blockly.FieldDropdown([[Blockly.Msg.internet_http_get_server_data_json, "json"], [Blockly.Msg.internet_http_get_server_data_text, "text"]]), "type"), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setHelpUrl(""); var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('type');var TOOLTIPS = {'json': Blockly.Msg.Esp32_Network_Http_Get_Data_From_Local_Server_TOOLTIP.replace('%1', Blockly.Msg.internet_http_get_server_data_json),'text': Blockly.Msg.Esp32_Network_Http_Get_Data_From_Local_Server_TOOLTIP.replace('%1', Blockly.Msg.internet_http_get_server_data_text)};return TOOLTIPS[mode];});this.setHelpUrl(""); } }, Blockly.Python.esp32_network_http_get_data_from_local_server = function (t) { var e = t.getFieldValue("type"); if ("text" == e) var n = "_SEND_HTTP_REQUEST.text"; else if ("json" == e) n = "eval(_SEND_HTTP_REQUEST.text)"; return [n, Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_network_http_server_setup = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/http_server_header.png", 130, 40, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_setup), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Network_Http_Server_Setup_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_network_http_server_setup = function (t) { Blockly.Python.definitions_.esp32_network_http_server_setup_def_setup = "from microWebSrv import MicroWebSrv\nimport time\n"; return "" }, Blockly.Blocks.esp32_network_http_server_route = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_route_setting_title), this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_route_setting_path).appendField(new Blockly.FieldTextInput("/"), "path").appendField(Blockly.Msg.wifi_web_http_server_route_setting_being_requested), this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_route_setting_property).appendField(new Blockly.FieldDropdown([[Blockly.Msg.wifi_web_http_server_route_setting_get, "get"], [Blockly.Msg.wifi_web_http_server_route_setting_post, "post"]]), "response_type"), this.appendStatementInput("exec").setCheck(null).appendField(Blockly.Msg.wifi_web_http_server_route_setting_do), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('response_type');var TOOLTIPS = {'get': Blockly.Msg.Esp32_Network_Http_Server_Route_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_route_setting_get),'post': Blockly.Msg.Esp32_Network_Http_Server_Route_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_route_setting_post)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_network_http_server_route = function (t) { var e = t.getFieldValue("response_type"), n = t.getFieldValue("path"), i = Blockly.Python.statementToCode(t, "exec"), l = ""; "get" == e ? l = "" : "post" == e && (l = ", 'POST'"), Blockly.Python.definitions_["esp32_network_http_server_route_def_" + n.substring(1)] = "@MicroWebSrv.route('" + n + "'" + l + ")\ndef _httpHandler" + n.substring(1) + "Get(httpClient, httpResponse):\n" + i + "\n", Blockly.Python.addSetup("server_route_setup", 'def _acceptWebSocketCallback(webSocket, httpClient) :\n print("WS ACCEPT")\n webSocket.RecvTextCallback = _recvTextCallback\n webSocket.RecvBinaryCallback = _recvBinaryCallback\n webSocket.ClosedCallback = _closedCallback\n\ndef _recvTextCallback(webSocket, msg) :\n print("WS RECV TEXT : %s" % msg)\n webSocket.SendText("Reply for %s" % msg)\n\ndef _recvBinaryCallback(webSocket, data) :\n print("WS RECV DATA : %s" % data)\n\ndef _closedCallback(webSocket) :\n print("WS CLOSED")\n\ntry:\n srv.Stop()\n srv = MicroWebSrv()\n srv.MaxWebSocketRecvLen = 1024\n srv.WebSocketThreaded = False\n srv.AcceptWebSocketCallback = _acceptWebSocketCallback\n srv.Start(threaded=True)\nexcept BaseException as e:\n print(str(e))\n srv = MicroWebSrv()\n srv.MaxWebSocketRecvLen = 1024\n srv.WebSocketThreaded = False\n srv.AcceptWebSocketCallback = _acceptWebSocketCallback\n srv.Start(threaded=True)\n'); return "" }, Blockly.Blocks.esp32_network_http_server_route_respond = { init: function () { this.appendValueInput("exec").setCheck(null).appendField(Blockly.Msg.wifi_web_http_server_respond_title), this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_respond_type).appendField(new Blockly.FieldDropdown([[Blockly.Msg.wifi_web_http_server_respond_text, "text/plain"], [Blockly.Msg.wifi_web_http_server_respond_json, "application/json"], [Blockly.Msg.wifi_web_http_server_respond_html, "text/html"]]), "response_type"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('response_type');var TOOLTIPS = {'text/plain': Blockly.Msg.Esp32_Network_Http_Server_Route_Respond_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_respond_text),'application/json': Blockly.Msg.Esp32_Network_Http_Server_Route_Respond_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_respond_json),'text/html': Blockly.Msg.Esp32_Network_Http_Server_Route_Respond_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_respond_html)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_network_http_server_route_respond = function (t) { var e = t.getFieldValue("response_type"); return "content = " + Blockly.Python.valueToCode(t, "exec", Blockly.Python.ORDER_ATOMIC) + '\nhttpResponse.WriteResponseOk( headers = None,\n contentType = "' + e + '",\n contentCharset = "UTF-8",\n content = str(content) )\n' }, Blockly.Blocks.esp32_network_http_server_get_data = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.wifi_web_http_server_get_title).appendField(new Blockly.FieldDropdown([[Blockly.Msg.wifi_web_http_server_get_as_json, "json"], [Blockly.Msg.wifi_web_http_server_get_as_text, "text"]]), "type"), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour(NETWORK_BLOCK_COLOR), this.setHelpUrl(""); var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('type');var TOOLTIPS = {'json': Blockly.Msg.Esp32_Network_Http_Server_Get_Data_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_get_as_json),'text': Blockly.Msg.Esp32_Network_Http_Server_Get_Data_TOOLTIP.replace('%1', Blockly.Msg.wifi_web_http_server_get_as_text)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_network_http_server_get_data = function (t) { var e = t.getFieldValue("type"); if ("json" == e) var n = "ReadRequestContentAsJSON()"; else if ("text" == e) n = "ReadRequestContent(size=None)"; return ["httpClient." + n, Blockly.Python.ORDER_NONE] }; var WS_BLOCK_COLOR = "#83178a"; Blockly.Blocks.esp32_web_ws_setup_send = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/ws_header_send.png", 220, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_send_text), this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_send_ip).appendField(new Blockly.FieldTextInput("192.168.4.1"), "ip"), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(WS_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Web_Ws_Setup_Send_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_web_ws_setup_send = function (t) { var e = t.getFieldValue("ip"); return Blockly.Python.definitions_.ws_setup_send = "import uwebsockets.client\n\n", '_client_websocket = uwebsockets.client.connect("ws://' + e + ':80")\n' }, Blockly.Blocks.esp32_web_ws_send = { init: function () { this.appendValueInput("command").setCheck(null).appendField(Blockly.Msg.internet_ws_send_msg), this.setInputsInline(!0), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(WS_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Web_Ws_Send_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_web_ws_send = function (t) { return "message = " + Blockly.Python.valueToCode(t, "command", Blockly.Python.ORDER_ATOMIC) + "\n_client_websocket.send(message)\n" }, Blockly.Blocks.esp32_web_ws_setup_receive = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/ws_header_receive.png", 220, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_recv), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(WS_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Web_Ws_Setup_Receive_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_web_ws_setup_receive = function (t) { Blockly.Python.definitions_.ws_setup_receive = "import uasyncio, logging\nfrom uasyncio.websocket.server import WSReader, WSWriter\nlogging.basicConfig(level=logging.DEBUG)\n\n"; return "" }, Blockly.Blocks.esp32_web_ws_receive_statement = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_receiving), this.appendStatementInput("command").setCheck(null).appendField(Blockly.Msg.internet_ws_setup_recv_exec), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(WS_BLOCK_COLOR), this.setTooltip(Blockly.Msg.Esp32_Web_Ws_Receive_Statement_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_web_ws_receive_statement = function (t) { var e = Blockly.Python.statementToCode(t, "command"); Blockly.Python.definitions_.ws_setup_receive_statement = "def _ws_exec(msg):\n" + e + '\ndef _ws_echo(reader, writer):\n yield from reader.readline()\n\n reader = yield from WSReader(reader, writer)\n writer = WSWriter(reader, writer)\n\n while 1:\n _ws_l = yield from reader.read(1024)\n print(_ws_l)\n _ws_exec(_ws_l)\n\n if _ws_l == b"\\r":\n await writer.awrite(b"\\r\\n")\n else:\n await writer.awrite(_ws_l)\n\n_ws_loop = uasyncio.get_event_loop()\n_ws_loop.create_task(uasyncio.start_server(_ws_echo, "0.0.0.0", 80))\n_ws_loop.run_forever()\n_ws_loop.close()\n'; return "\n" }, Blockly.Blocks.esp32_web_ws_receive_get_data = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_get_msg), this.appendDummyInput().appendField(Blockly.Msg.internet_ws_setup_get_msg_type).appendField(new Blockly.FieldDropdown([[Blockly.Msg.internet_ws_setup_get_msg_text, "text"], [Blockly.Msg.internet_ws_setup_get_msg_json, "json"]]), "type"), this.setInputsInline(!1), this.setOutput(!0, null), this.setColour(WS_BLOCK_COLOR), this.setHelpUrl("");var thisBlock = this;this.setTooltip(function () {var mode = thisBlock.getFieldValue('type');var TOOLTIPS = {'text': Blockly.Msg.Esp32_Web_Ws_Receive_Get_Data_TOOLTIP.replace('%1', Blockly.Msg.internet_ws_setup_get_msg_text),'json': Blockly.Msg.Esp32_Web_Ws_Receive_Get_Data_TOOLTIP.replace('%1', Blockly.Msg.internet_ws_setup_get_msg_json)};return TOOLTIPS[mode];}); } }, Blockly.Python.esp32_web_ws_receive_get_data = function (t) { var e = t.getFieldValue("type"); if ("text" == e) var n = 'msg.decode("utf-8")'; else if ("json" == e) n = 'eval(msg.decode("utf-8"))'; return [n, Blockly.Python.ORDER_NONE] }; var ESP32_NBIOT_COLOR = "#629978"; Blockly.Blocks.esp32_nbiot_setup = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_esp32_header.png", 110, 40, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_module_init), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ESP32_NBIOT_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_setup = function (t) { Blockly.Python.addVariable("_nbiot_serial_read", '_nbiot_serial_read = ""', !0), Blockly.Python.addVariable("_nbiot_readings", '_nbiot_readings = ""', !0), Blockly.Python.addVariable("_nbiot_power_on_status", "_nbiot_power_on_status = False", !0), Blockly.Python.addVariable("_nbiot_internet_status", "_nbiot_internet_status = False", !0), Blockly.Python.addVariable("_nbiot_internet_ip_address", '_nbiot_internet_ip_address = ""', !0), Blockly.Python.definitions_.import_definition = 'from machine import UART\nfrom machine import Timer\nimport ubinascii as binascii\nimport time\n\n_nbiot_serial = UART(2,rx=16, tx=17, baudrate=115200, timeout=10)\n\n_nbiot_serial_timer = Timer(1)\n_nbiot_serial_timer.init(period=50, mode=Timer.PERIODIC, callback=lambda t: _read_nbiot_serial(_nbiot_serial))\n\ndef _read_nbiot_serial(uart):\n global _nbiot_readings, _nbiot_power_on_status, _nbiot_internet_status, _nbiot_internet_ip_address\n if _nbiot_serial.any():\n _nbiot_serial_read = _nbiot_serial.readline().decode("utf-8")\n _nbiot_serial_read = _nbiot_serial_read.strip()\n _nbiot_readings = _nbiot_serial_read.strip()\n\n if _nbiot_serial_read == "+CPIN: READY":\n _nbiot_power_on_status = True\n print("NB-IoT Module Initiated!\\n")\n _nbiot_serial.write(b\'AT+CMSYSCTRL=0,2,50,300,100,800\\r\\n\')\n\n if "+IP" in _nbiot_serial_read:\n _nbiot_internet_status = True\n _nbiot_internet_ip_address = _nbiot_serial_read[5:len(_nbiot_serial_read)]\n'; return "" }, Blockly.Blocks.esp32_nbiot_get_power_status = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_module_power), this.setOutput(!0, null), this.setColour(ESP32_NBIOT_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_get_power_status = function (t) { return ["_nbiot_power_on_status", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_nbiot_get_network_status = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_module_connectivity), this.setOutput(!0, null), this.setColour(ESP32_NBIOT_COLOR), this.setTooltip(Blockly.Msg.esp32_nbiot_get_power_status_TOOLTIP), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_get_network_status = function (t) { return ["_nbiot_internet_status", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_nbiot_get_network_ip = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_module_ip), this.setOutput(!0, null), this.setColour(ESP32_NBIOT_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_get_network_ip = function (t) { return ["_nbiot_internet_ip_address", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.esp32_nbiot_onenet_init = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_onenet.png", 200, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_title), this.appendValueInput("product_id").setCheck(null).appendField(Blockly.Msg.nbiot_onenet_connect_productid), this.appendValueInput("device_id").setCheck(null).appendField(Blockly.Msg.nbiot_onenet_connect_deviceid), this.appendValueInput("device_apikey").setCheck(null).appendField(Blockly.Msg.nbiot_onenet_connect_device_api), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_onenet_init = function (t) { var e = Blockly.Python.valueToCode(t, "product_id", Blockly.Python.ORDER_ATOMIC), n = Blockly.Python.valueToCode(t, "device_id", Blockly.Python.ORDER_ATOMIC), i = Blockly.Python.valueToCode(t, "device_apikey", Blockly.Python.ORDER_ATOMIC); Blockly.Python.addVariable("_nbiot_onenet_product_id", "", !0), Blockly.Python.addVariable("_nbiot_onenet_device_id", "", !0), Blockly.Python.addVariable("_nbiot_onent_device_apikey", "", !0), Blockly.Python.addVariable("_nbiot_onenet_connection_status", "", !0), Blockly.Python.addVariable("_nbiot_onenet_read_anything", "", !0), Blockly.Python.addVariable("_nbiot_onenet_init_state", "", !0), Blockly.Python.addSetup("setup", "_nbiot_onenet_init_state = False\n_nbiot_onenet_connection_status = False\n_nbiot_onenet_read_anything = False\n_nbiot_onenet_product_id = " + e + "\n_nbiot_onenet_device_id = " + n + "\n_nbiot_onent_device_apikey = " + i + '\n\ndef _nbiot_send_onenet_data(data):\n _nbiot_send_message = data\n _nbiot_send_data_content = binascii.hexlify(_nbiot_send_message).decode("utf-8")\n _nbiot_send_header = ",0300" + str(hex(len(_nbiot_send_message)).split(\'x\')[-1])\n _nbiot_send_at_content = "AT+MQTTPUB=$dp,0,1,0," + str(len(_nbiot_send_message)+len(_nbiot_send_header[1:7].replace("0",""))) + ",0300" + str(hex(len(_nbiot_send_message)).split(\'x\')[-1]) + str(_nbiot_send_data_content)\n return _nbiot_send_at_content\n\ndef _nbiot_read_onenet_data(raw_response):\n _nbiot_receive = raw_response\n if "+MQTTPUBLISH" not in raw_response:\n return ""\n elif "+MQTTPUBLISH" in raw_response:\n _nbiot_occur = -1\n for i in range(0, 6): _nbiot_occur = _nbiot_receive.find(",", _nbiot_occur + 1)\n return _nbiot_receive[_nbiot_occur+1:len(_nbiot_receive)]\n\ndef _read_nbiot_onenet(_incoming_data):\n global _nbiot_onenet_connection_status, _nbiot_onenet_read_anything\n\n if "+MQTTOPEN: OK" in _incoming_data:\n _nbiot_onenet_connection_status = True\n # print("OneNET Connected!")\n if "+MQTTOPEN: FAIL" in _incoming_data:\n _nbiot_onenet_connection_status = False\n # print("OneNET Lost Connection!")\n\n if "+MQTTPUBLISH" in _incoming_data:\n _nbiot_onenet_read_anything = True\n else:\n _nbiot_onenet_read_anything = False\n\n if "+MQTTDISC" in _incoming_data:\n _nbiot_onenet_read_anything = False\n _nbiot_onenet_configuration = "AT+MQTTCFG=183.230.40.39,6002,"+_nbiot_onenet_device_id+",100,"+_nbiot_onenet_product_id+","+_nbiot_onent_device_apikey+",1,0\\r\\n"\n print("Enabling OneNET Connection...")\n _nbiot_serial.write(_nbiot_onenet_configuration.encode())\n time.sleep_ms(100)\n _nbiot_serial.write(b\'AT+MQTTOPEN=1,1,0\\r\\n\')\n\ndef _init_onenet_connection():\n _nbiot_onenet_configuration = "AT+MQTTCFG=183.230.40.39,6002,"+_nbiot_onenet_device_id+",100,"+_nbiot_onenet_product_id+","+_nbiot_onent_device_apikey+",1,0\\r\\n"\n print("Enabling OneNET Connection...")\n _nbiot_serial.write(_nbiot_onenet_configuration.encode())\n time.sleep_ms(100)\n _nbiot_serial.write(b\'AT+MQTTOPEN=1,1,0\\r\\n\')\n time.sleep_ms(100)\n'); return "if (_nbiot_internet_status == True) and (_nbiot_onenet_init_state == False) and (_nbiot_onenet_connection_status == False):\n _init_onenet_connection()\n _nbiot_onenet_init_state = True\n\n_read_nbiot_onenet(_nbiot_readings)\n" }, Blockly.Blocks.esp32_nbiot_onenet_connection_status = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_connectivity), this.setOutput(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_onenet_connection_status = function (t) { return ["_nbiot_onenet_connection_status", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.iot_service_nbiot_onenet = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_onenet_send.png", 210, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_send_title), this.itemCount_ = 1, this.updateShape_(), this.setMutator(new Blockly.Mutator(["iot_service_nbiot_onenet_create_with_item"])), this.setColour(ONENET_BLOCK_COLOR), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setTooltip(""), this.setHelpUrl("") }, mutationToDom: function () { var t = document.createElement("mutation"); return t.setAttribute("items", this.itemCount_), t }, domToMutation: function (t) { this.itemCount_ = parseInt(t.getAttribute("items"), 10), this.updateShape_() }, decompose: function (t) { var e = t.newBlock("iot_service_nbiot_onenet_create_with_container"); e.initSvg(); for (var n = e.getInput("STACK").connection, i = 0; i < this.itemCount_; i++) { var l = t.newBlock("iot_service_nbiot_onenet_create_with_item"); l.initSvg(), n.connect(l.previousConnection), n = l.nextConnection } return e }, compose: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = []; e;)n.push(e.valueConnection_), e = e.nextConnection && e.nextConnection.targetBlock(); for (var i = 0; i < this.itemCount_; i++) { var l = this.getInput("ADD" + i).connection.targetConnection; l && -1 == n.indexOf(l) && l.disconnect() } this.itemCount_ = n.length, this.updateShape_(); for (i = 0; i < this.itemCount_; i++)Blockly.Mutator.reconnect(n[i], this, "ADD" + i) }, saveConnections: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = 0; e;) { var i = this.getInput("ADD" + n); e.valueConnection_ = i && i.connection.targetConnection, n++, e = e.nextConnection && e.nextConnection.targetBlock() } }, updateShape_: function () { for (var t = 0; t < this.itemCount_; t++) { if (!this.getInput("ADD" + t)) this.appendValueInput("ADD" + t).appendField(Blockly.Msg.nbiot_onenet_send_property).appendField(new Blockly.FieldTextInput("Property" + t), "field" + t) } for (; this.getInput("ADD" + t);)this.removeInput("ADD" + t), t++ } }, Blockly.Blocks.iot_service_nbiot_onenet_create_with_container = { init: function () { this.setColour(ONENET_BLOCK_COLOR), this.appendDummyInput().appendField("Items"), this.appendStatementInput("STACK"), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Blocks.iot_service_nbiot_onenet_create_with_item = { init: function () { this.setColour(ONENET_BLOCK_COLOR), this.appendDummyInput().appendField("Field"), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Python.iot_service_nbiot_onenet = function (t) { for (var e = "'{", n = 0; n < this.itemCount_; n++)e += '"' + t.getFieldValue("field" + n) + '":"\' + str(' + (Blockly.Python.valueToCode(this, "ADD" + n, Blockly.Python.ORDER_NONE) || "") + ") + '\","; return "_data_to_be_send = " + (e + "}'").slice(0, -3) + '}\\r\\n\'\n_data_add_rn = _nbiot_send_onenet_data(_data_to_be_send) + "\\r\\n"\n_data_for_at = _data_add_rn.encode()\n_nbiot_serial.write(_data_for_at)\n\n' }, Blockly.Blocks.iot_service_nbiot_onenet_read = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_when_incoming_msg), this.appendValueInput("message").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_when_incoming_msg_when), this.appendStatementInput("exec").setCheck(null).appendField(Blockly.Msg.nbiot_onenet_when_incoming_msg_exec), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.iot_service_nbiot_onenet_read = function (t) { return "if (_nbiot_read_onenet_data(_nbiot_readings) == " + Blockly.Python.valueToCode(t, "message", Blockly.Python.ORDER_ATOMIC) + "):\n" + Blockly.Python.statementToCode(t, "exec") + "\n" }, Blockly.Blocks.esp32_nbiot_onenet_read_value = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_onenet_receive_command), this.setOutput(!0, null), this.setColour(ONENET_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.esp32_nbiot_onenet_read_value = function (t) { return ["_nbiot_read_onenet_data(_nbiot_readings)", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.iot_service_nbiot_cococloud_read = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_cococloud_get.png", 260, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_get_event_title), this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_get_event_api).appendField(new Blockly.FieldTextInput("ENTER_YOUR_EVENT_API_KEY"), "t_api"), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.iot_service_nbiot_cococloud_read = function (t) { t.getFieldValue("t_api"); return "\n" }, Blockly.Blocks.iot_service_nbiot_cococloud_read_data = { init: function () { this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_get_property), this.appendValueInput("property").setCheck(null), this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_get_data), this.setInputsInline(!0), this.setOutput(!0, null), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } }, Blockly.Python.iot_service_nbiot_cococloud_read_data = function (t) { Blockly.Python.valueToCode(t, "property", Blockly.Python.ORDER_ATOMIC); return ["\n", Blockly.Python.ORDER_NONE] }, Blockly.Blocks.iot_service_nbiot_cococloud = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_cococloud_send.png", 260, 60, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_send_title), this.appendDummyInput().appendField(Blockly.Msg.nbiot_cococloud_send_api).appendField(new Blockly.FieldTextInput("ENTET_YOUT_EVENT_API_KEY"), "t_api"), this.itemCount_ = 1, this.updateShape_(), this.setMutator(new Blockly.Mutator(["iot_service_nbiot_cococloud_create_with_item"])), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setTooltip(Blockly.Msg.iot_service_nbiot_cococloud_TOOLTIP), this.setHelpUrl("") }, mutationToDom: function () { var t = document.createElement("mutation"); return t.setAttribute("items", this.itemCount_), t }, domToMutation: function (t) { this.itemCount_ = parseInt(t.getAttribute("items"), 10), this.updateShape_() }, decompose: function (t) { var e = t.newBlock("iot_service_nbiot_cococloud_create_with_container"); e.initSvg(); for (var n = e.getInput("STACK").connection, i = 0; i < this.itemCount_; i++) { var l = t.newBlock("iot_service_nbiot_cococloud_create_with_item"); l.initSvg(), n.connect(l.previousConnection), n = l.nextConnection } return e }, compose: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = []; e;)n.push(e.valueConnection_), e = e.nextConnection && e.nextConnection.targetBlock(); for (var i = 0; i < this.itemCount_; i++) { var l = this.getInput("ADD" + i).connection.targetConnection; l && -1 == n.indexOf(l) && l.disconnect() } this.itemCount_ = n.length, this.updateShape_(); for (i = 0; i < this.itemCount_; i++)Blockly.Mutator.reconnect(n[i], this, "ADD" + i) }, saveConnections: function (t) { for (var e = t.getInputTargetBlock("STACK"), n = 0; e;) { var i = this.getInput("ADD" + n); e.valueConnection_ = i && i.connection.targetConnection, n++, e = e.nextConnection && e.nextConnection.targetBlock() } }, updateShape_: function () { for (var t = 0; t < this.itemCount_; t++) { if (!this.getInput("ADD" + t)) this.appendValueInput("ADD" + t).appendField(Blockly.Msg.nbiot_cococloud_send_property).appendField(new Blockly.FieldTextInput("Property" + t), "field" + t) } for (; this.getInput("ADD" + t);)this.removeInput("ADD" + t), t++ } }, Blockly.Blocks.iot_service_nbiot_cococloud_create_with_container = { init: function () { this.setColour(ESP32_NBIOT_COLOR), this.appendDummyInput().appendField("Items"), this.appendStatementInput("STACK"), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Blocks.iot_service_nbiot_cococloud_create_with_item = { init: function () { this.setColour(COCOCLOUD_BLOCK_COLOR), this.appendDummyInput().appendField("Field"), this.setPreviousStatement(!0), this.setNextStatement(!0), this.setTooltip(""), this.contextMenu = !1 } }, Blockly.Python.iot_service_nbiot_cococloud = function (t) { var e = t.getFieldValue("t_api"); Blockly.Python.addVariable("_nbiot_cococloud_send_init_state", "", !0), Blockly.Python.addVariable("_nbiot_cococloud_json_content", "", !0), Blockly.Python.definitions_.import = "_nbiot_cococloud_send_init_state = False\n\ndef _nbiot_cococloud_send(data):\n _nbiot_cococloud_send_data = 'AT+HTTPCONTENT=0,\"'+ data + '\"\\r\\n'\n print(_nbiot_cococloud_send_data)\n _nbiot_serial.write(b'AT+HTTPCLOSE=0\\r\\n')\n time.sleep_ms(500)\n _nbiot_serial.write(b'AT+HTTPCREATE=\"http://api.cocorobo.cn/\"\\r\\n')\n time.sleep_ms(500)\n _nbiot_serial.write(b'AT+HTTPHEADER=0,\"Content-Type: application/json\\\\r\\\\n\"\\r\\n')\n time.sleep_ms(500)\n _nbiot_serial.write(_nbiot_cococloud_send_data.encode())\n time.sleep_ms(500)\n _nbiot_serial.write(b'AT+HTTPSEND=0,1,\"/iot/data/eventAPIKey/" + e + "\"\\r\\n')\n time.sleep_ms(500)\n"; for (var n = "'{", i = 0; i < this.itemCount_; i++)n += '"' + t.getFieldValue("field" + i) + '":"\' + str(' + (Blockly.Python.valueToCode(this, "ADD" + i, Blockly.Python.ORDER_NONE) || "") + ") + '\","; return "_nbiot_cococloud_json_content = " + (n + "}'").slice(0, -3) + "}'\n_nbiot_cococloud_send(_nbiot_cococloud_json_content)\n" }, Blockly.Blocks.esp32_network_nbiot_http_get = { init: function () { this.appendDummyInput().appendField(new Blockly.FieldImage("blockly/media/nbiot_esp32_header.png", 150, 50, { alt: "*", flipRtl: "FALSE" })), this.appendDummyInput().appendField(Blockly.Msg.nbiot_http_get_title), this.appendValueInput("nbiot_http_get_url").setCheck(null).appendField(Blockly.Msg.nbiot_http_get_url), this.setInputsInline(!1), this.setPreviousStatement(!0, null), this.setNextStatement(!0, null), this.setColour(COCOCLOUD_BLOCK_COLOR), this.setTooltip(""), this.setHelpUrl("") } };