radio
— Radio-related functions¶
The radio module is based on ESP-NOW Wireless broadcasting without connection provides wireless broadcast function, supports 13 Channel, and can receive broadcast messages sent by members in the same Channel, suitable for multi-board network communication within 30 meters. Parameter ———-
-
radio.
on
()¶
Turn ON wireless function
-
radio.
off
()¶
Turn OFF wireless function
-
radio.
config
(channel)¶
Configure wireless parameters
channel
(int): Wireless channel, range 1~13
-
radio.
receive
()¶
Receive a wireless broadcast message, the message is returned as a string. Can receive up to 250 bytes of data. If no message is received, it returns None
. When the internal parameter of receive
is True
, that is receive(True)
, the (msg,mac) binary is returned. The default is receive(False)
, which only returns msg.
-
radio.
receive_bytes
()¶
Receive wireless broadcast message, the message is returned in bytes. Others are the same as radio.receive()
.
-
radio.
send
()¶
Send wireless broadcast message, data type as string. Return True after successful transmission, otherwise return False.
-
radio.
send_bytes
()¶
Send wireless broadcast message, byte data type. Return True after successful transmission, otherwise return False.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import radio
import _thread
channel=2
radio.on()
radio.config(channel=channel) # radio通道设置
def rec_loop(): # radio接收循环
while True:
temp=radio.receive(True) # radio 接收数据,返回(msg,mac)
# temp=radio.receive() # radio 接收数据,返回msg
if temp: # 当接收到数据时打印
print(temp)
_thread.start_new_thread(rec_loop, ()) # radio接收线程
radio.send("hello mPython!")
|