Please enable JavaScript to view this site.

Waijung 2 User Guide

How do these blocks appear in a Simulink model?

esp_now_1

What can be configured?

esp_now_setup

esp_now_2

 

Configuration Parameter

Selectable Option/Value

Description

WIFI mode

WIFI Station--WIFI AP

Configure ESP32 to function in Access Point Mode or Station Mode.

Long range

Check--Uncheck

Enable long range.

ESP-NOW rate

WIFI_PHY_RATE_1M_L--WIFI_PHY_RATE_2M_L--WIFI_PHY_RATE_5M_L--WIFI_PHY_RATE_11M_L--WIFI_PHY_RATE_2M_S--WIFI_PHY_RATE_5M_S--WIFI_PHY_RATE_11M_S--WIFI_PHY_RATE_48M--WIFI_PHY_RATE_24M--WIFI_PHY_RATE_12M--WIFI_PHY_RATE_6M--WIFI_PHY_RATE_54M--WIFI_PHY_RATE_36M--WIFI_PHY_RATE_18M--WIFI_PHY_RATE_9M--WIFI_PHY_RATE_MCS0_LGI--WIFI_PHY_RATE_MCS1_LGI--WIFI_PHY_RATE_MCS2_LGI--WIFI_PHY_RATE_MCS3_LGI--WIFI_PHY_RATE_MCS4_LGI--WIFI_PHY_RATE_MCS5_LGI--WIFI_PHY_RATE_MCS6_LGI--WIFI_PHY_RATE_MCS7_LGI--WIFI_PHY_RATE_MCS0_SGI--WIFI_PHY_RATE_MCS1_SGI--WIFI_PHY_RATE_MCS2_SGI--WIFI_PHY_RATE_MCS3_SGI--WIFI_PHY_RATE_MCS4_SGI--WIFI_PHY_RATE_MCS5_SGI--WIFI_PHY_RATE_MCS6_SGI--WIFI_PHY_RATE_MCS7_SGI--WIFI_PHY_RATE_LORA_250K--WIFI_PHY_RATE_LORA_250K

Select PHY rate to send ESP-NOW data. When long range communication is enabled WIFI_PHY_RATE_LORA_250K--WIFI_PHY_RATE_LORA_250K will be the only option that can be selected.

WIFI channel

0 to 13

Select the WIFI channel. Select 0 to select default settings.

Primary master key(PMK)

 

16 byte key to encrypt Local Master Key(LMK). If this is empty default key will be assigned automatically.

Add Broadcast MAC address

Check--Uncheck

Add the broadcast MAC address to the table.

MAC address

 

Enter WIFI driver MAC address that needs to add to the paired table. The format should be as follow

0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX

Local master key(LMK)

 

16 byte key to encrypt the vendor-specific action frame. If the LMK is empty, the vendor-specific action frame will not be encrypted for the paired device.

Channel

0 to 14

Wi-Fi channel that peer uses to send/receive ESPNOW data. If the value is 0, use the current channel which station or softap is on. Otherwise, it must be set as the channel that station or softap is on.

Add

 

Add MAC address, LMK & Channel to the paired table.

Remove

 

Remove the given MAC address in the text field from the table

esp_now_send

esp_now_3

Configuration Parameter

Selectable Option/Value

Description

 

Unicast--Multicast--Broadcast

Unicast - Only transmits data to a given MAC address. Setup block need to configure first with paired devices on both sender and receiver end.

Multicast - Transmitting data to all paired devices. Setup block need to configure first with paired devices on both sender and receiver end.

Broadcast - Transmitting to all recipients. Only Broadcast MAC address needs to be added in the setup block, individual ESP32 MAC addresses don't need to be added.

Sample time (sec)

-1 (inherited) or specify

Specify the sample time.

INPUT/ OUTPUT Port

Port Name

Port Type

Date Type

Description

Data

Scalar/Vector

uint8

Data input to send through ESP-NOW. Sending data must be less than or equal to 250 bytes of data

esp_now_recv

esp_now_4

Configuration Parameter

Selectable Option/Value

Description

Receive buffer size

 

Buffer size to receive data. If the buffer size is not correct, error will be printed

Sample time (sec)

-1 (inherited) or specify

Specify the sample time.

INPUT/ OUTPUT Port

Port Name

Port Type

Date Type

Description

Status

Scalar

uint8

The status port is 0 initially and becomes 1 when there are new values received for ESP-NOW. Once the values are out it becomes 0 again.

Recv MAC

Vector

uint8

Output the sender's MAC address

Data

Scalar/Vector

uint8

Output data

When to use this block?

These blocks can be used to do stable communication through ESP-NOW protocol, both for short and long ranges.

How does this block work?

ESP-NOW is a connectionless communication protocol developed by Espressif that features short packet transmission. This protocol enables multiple devices to talk to each other in an easy way. To communicate via ESP-NOW, you need to know the MAC Address(es) of the ESP32 sender(s) and receiver(s) [unless you are using the Broadcast method]. That’s how the boards know which device is sending to which device and receiving from which device. Each ESP32 has a unique MAC address and that’s how we identify each board to send data to it.

Description

These blocks can be used to exchange small messages (up to 250 bytes) between ESP32 boards and it can configure one-way or two-way communication in different setups.

 

If ESP-NOW fails to send data, it can be for these reasons:

the destination device doesn’t exist;

the channels of the devices are not the same;

the action frame is lost when transmitting on the air, etc.

 

Note:

Limitations:

Encrypting multicast vendor-specific action frame is not supported.

The maximum number of paired devices is 20. If paired devices are encrypted it is limited to 6.

Maximum number of different LMKs is 6.

Sending data must be less than or equal to 250 bytes of data.

 

How to get the MAC address of the ESP32 board?

 

Run the UIDREAD demo to obtain the MAC addresses. The UIDREAD block will output the MAC addresses of various network adapters present in the ESP32 board, such as WiFi AP, WiFi STA, Ethernet, Bluetooth, etc. For our purposes, we are interested in obtaining only the WiFi STA MAC address (which is also the base MAC address)

 

esp_now_4_4

 

Once you have obtained the WiFi STA MAC address(es) of your ESP32 device(s), you can use those to pair ESP32 sender(s) and receiver(s) to exchange data via Unicast/Multicast methods.

 

How to pair devices?

esp_now_6

Note:

2 - Local master key can be left empty if the user doesn't want to encrypt data.

3 - Channel should be equal to the WIFI channel.

To remove paired devices from the table, enter the MAC address in the MAC address field, click the Remove button, and Apply.

If the user wants to transmit data through Unicast or Multicast method, then devices need to be paired first on both sender and receiver sides in the ESP-NOW Setup block as shown above.

 

Demo

This example is about ESP-NOW sending data using the Broadcast method. Only Broadcast MAC address needs to be added by enabling the check-box in the ESP-NOW Setup block on the sender side. Peer ESP32 MAC addresses don't need to be added when transmitting data through the Broadcast method.

 

Send data

Demo file : esp_now_send_demo.slx

esp_now_5

Description

ESP-NOW Setup block on the sender side will have the Peer MAC address of the receiver ESP32 board while the ESP-NOW Send block will provide the option to choose the Unicast/Multicast/Broadcast method.

 

MATLAB's "counter limited" block increases its counter until counter values become 5 every 2 seconds, and the second value is a constant value of 70. Both will pack using a "Byte Pack" block. Finally, packed data will be sent to the esp-now-send block.

 

What should be happening?

This will transmit 2 uint8 data from the ESP-NOW broadcast communication method.

 

Receive data

Demo file : esp_now_recv_demo.slx

esp_now_7

Description

ESP-NOW Setup block on the receiver side will have the Peer MAC address of the sender ESP32 board. Since the sender side is transmitting 2 uint8 data packets, the received buffer size in the ESP-NOW recv block needs to be set as 2. Use demux blocks to split output data as shown in the example.

 

What should be happening?

Open the serial monitor at baud rate 115200 and you will see that your receiver ESP32 board is receiving the data from your sender ESP32 board.

esp_now_8

Copyright 2024 Aimagin Co.,Ltd. Rev.1454