.. _tutorials_radio: Wireless Broadcast ================== The mPython Board provides 2.4G wireless RF communication, with a total of 13 channels. It can achieve simple networked communication within a certain area. On the same channel, members can receive broadcast messages. It is similar to a walkie-talkie: on the same channel, communication is achieved. .. figure:: /_static/products/ledong-v2/_static/image/tutorials/radio/radio.png :align: center :width: 200 Walkie-talkie radio -------- .. literalinclude:: /_static/products/ledong-v2/_static/examples/radio/radio.py :caption: Example of sending a broadcast message :linenos: .. literalinclude:: /_static/products/ledong-v2/_static/examples/radio/radio2.py :caption: Example of sending data to a device with a specific mac address :linenos: .. literalinclude:: /_static/products/ledong-v2/_static/examples/radio/radio3.py :caption: Example of receiving a message :linenos: .. class:: MPythonESPNow(wifi_ch=0) :noindex: Instantiate Radio :param wifi_ch: Set channel 0-11 :type wifi_ch: int .. class:: MPythonESPNow .. function:: get_mac(mode) :noindex: Get the mac address of its own network card :param mode: 0 sta address / 1 ap address :type mode: int :return: hexadecimal string mac address :rtype: str .. class:: MPythonESPNow .. function:: broadcast_data(msg) :noindex: Send wireless broadcast data, group send :param msg: wireless broadcast data :type msg: str .. class:: MPythonESPNow .. function:: set_add_peer(peer_mac) :noindex: Register the provided mac address as a peer address. Registration is required for private sending, not for group sending :param peer_mac: mac address, hexadecimal string :type peer_mac: str .. class:: MPythonESPNow .. function:: send_msg(peer_mac, msg) :noindex: Send wireless broadcast data, private send :param peer_mac: mac address, hexadecimal string :type peer_mac: str :param msg: wireless broadcast data :type msg: str .. class:: MPythonESPNow .. function:: set_irq_callback(espnow_recv_callback) :noindex: Set the callback handler function for receiving messages :param espnow_recv_callback: callback function :type espnow_recv_callback: function .. function:: espnow_recv_callback(espnow_obj) :noindex: espnow_mac, espnow_data, espnow_rssi = espnow_obj.recv_msg() receive message object :var str espnow_mac: mac address of the device broadcasting the message :var str espnow_data: received message :var str espnow_rssi: broadcast signal strength dBm