|
| 1 | +GatewayH2 Module |
| 2 | +============================ |
| 3 | + |
| 4 | +.. sku: M141 |
| 5 | +
|
| 6 | +.. include:: ../refs/module.gateway_h2.ref |
| 7 | + |
| 8 | +This library is the driver for Module Gateway H2, and the module communicates via UART. |
| 9 | + |
| 10 | +Support the following products: |
| 11 | + |
| 12 | + |Module Gateway H2| |
| 13 | + |
| 14 | +.. note:: When using this module, you need to flash the NCP firmware to the module. For details, refer to the `ESP Zigbee NCP <https://docs.m5stack.com/zh_CN/guide/zigbee/module_gateway_h2/zigbee_ncp>`_ documentation. |
| 15 | + |
| 16 | +UiFlow2 Example: |
| 17 | +-------------------------- |
| 18 | + |
| 19 | +Switch Control |
| 20 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 21 | + |
| 22 | +.. note:: To use this example, you need to flash this program onto an ESP32C6 or similar module as a light node device. For details, refer to `HA_on_off_light <https://github.com/espressif/esp-zigbee-sdk/tree/main/examples/esp_zigbee_HA_sample/HA_on_off_light>`_ |
| 23 | + |
| 24 | +Open the |cores3_switch_endpoint_example.m5f2| project in UiFlow2. |
| 25 | + |
| 26 | +The example demonstrates group control and targeted device operation for light nodes through SwitchEndpoint of Gateway H2 module. |
| 27 | + |
| 28 | +UiFlow2 Code Block: |
| 29 | + |
| 30 | + |cores3_switch_endpoint_example.png| |
| 31 | + |
| 32 | +Example output: |
| 33 | + |
| 34 | + None |
| 35 | + |
| 36 | +MicroPython Example: |
| 37 | +-------------------------- |
| 38 | + |
| 39 | +Switch Control |
| 40 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 41 | + |
| 42 | +The example demonstrates group control and targeted device operation for light nodes through SwitchEndpoint of Gateway H2 module. |
| 43 | + |
| 44 | +MicroPython Code Block: |
| 45 | + |
| 46 | + .. literalinclude:: ../../../examples/module/gateway_h2/cores3_switch_endpoint_example.py |
| 47 | + :language: python |
| 48 | + :linenos: |
| 49 | + |
| 50 | +Example output: |
| 51 | + |
| 52 | + None |
| 53 | + |
| 54 | +**API** |
| 55 | +-------------------------- |
| 56 | + |
| 57 | +GatewayH2Module |
| 58 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 59 | + |
| 60 | +.. class:: module.gateway_h2.GatewayH2Module |
| 61 | + |
| 62 | + Create an GatewayH2Module object. |
| 63 | + |
| 64 | + :param int id: UART id. |
| 65 | + :param int tx: the UART TX pin. |
| 66 | + :param int rx: the UART RX pin. |
| 67 | + |
| 68 | + UiFlow2 Code Block: |
| 69 | + |
| 70 | + |init.png| |
| 71 | + |
| 72 | + MicroPython Code Block: |
| 73 | + |
| 74 | + .. code-block:: python |
| 75 | +
|
| 76 | + from module import GatewayH2Module |
| 77 | +
|
| 78 | + module_gateway_h2 = GatewayH2Module(id = 1, tx = 10, rx = 17) |
| 79 | +
|
| 80 | + .. method:: create_switch_endpoint() |
| 81 | + |
| 82 | + Create Switch Endpoint. |
| 83 | + |
| 84 | + :returns SwitchEndpoint: zigbee switch endpoint object. |
| 85 | + :return type: SwitchEndpoint |
| 86 | + |
| 87 | + UiFlow2 Code Block: |
| 88 | + |
| 89 | + |init.png| |
| 90 | + |
| 91 | + MicroPython Code Block: |
| 92 | + |
| 93 | + .. code-block:: python |
| 94 | +
|
| 95 | + h2_switch_endpoint = module_gateway_h2.create_switch_endpoint() |
| 96 | +
|
| 97 | +.. class:: SwitchEndpoint |
| 98 | + |
| 99 | + Return by GatewayH2Module.create_switch_endpoint() |
| 100 | + |
| 101 | + .. method:: on([addr]) |
| 102 | + |
| 103 | + Turn on the light. |
| 104 | + |
| 105 | + :param addr: The device address (optional). |
| 106 | + |
| 107 | + - If called as ``on()``, turn on all devices. |
| 108 | + - If called as ``on(addr)``, turn on special address devices. |
| 109 | + |
| 110 | + UiFlow2 Code Block: |
| 111 | + |
| 112 | + |on.png| |
| 113 | + |all_on.png| |
| 114 | + |
| 115 | + MicroPython Code Block: |
| 116 | + |
| 117 | + .. code-block:: python |
| 118 | +
|
| 119 | + h2_switch_endpoint.on(addr) |
| 120 | + h2_switch_endpoint.on() |
| 121 | +
|
| 122 | + .. method:: off([addr]) |
| 123 | + |
| 124 | + Turn off the light. |
| 125 | + |
| 126 | + :param addr: The device address (optional). |
| 127 | + |
| 128 | + - If called as ``off()``, turn off all devices. |
| 129 | + - If called as ``off(addr)``, turn off special address devices. |
| 130 | + |
| 131 | + UiFlow2 Code Block: |
| 132 | + |
| 133 | + |off.png| |
| 134 | + |all_off.png| |
| 135 | + |
| 136 | + MicroPython Code Block: |
| 137 | + |
| 138 | + .. code-block:: python |
| 139 | +
|
| 140 | + h2_switch_endpoint.off(addr) |
| 141 | + h2_switch_endpoint.off() |
| 142 | +
|
| 143 | + .. method:: toggle([addr]) |
| 144 | + |
| 145 | + Toggle the light state. |
| 146 | + |
| 147 | + :param addr: The device address (optional). |
| 148 | + |
| 149 | + - If called as ``toggle()``, toggle all devices. |
| 150 | + - If called as ``toggle(addr)``, toggle special address devices. |
| 151 | + |
| 152 | + UiFlow2 Code Block: |
| 153 | + |
| 154 | + |toggle.png| |
| 155 | + |all_toggle.png| |
| 156 | + |
| 157 | + MicroPython Code Block: |
| 158 | + |
| 159 | + .. code-block:: python |
| 160 | + |
| 161 | + h2_switch_endpoint.toggle(addr) |
| 162 | + h2_switch_endpoint.toggle() |
| 163 | +
|
0 commit comments