I'm trying to run esp-now example given in esp-idf: <https://github.com/espressif/esp-idf/bl ... ple_main.c> on 2 ESP32 devkits with the following changes in data_parse() and data_prepare():
- /* Parse received ESPNOW data. */
- int example_espnow_data_parse(uint8_t *data, uint16_t data_len, uint8_t *state, uint16_t *seq, int *magic)
- {
- example_espnow_data_t *buf = (example_espnow_data_t *)data;
- uint16_t crc, crc_cal = 0;
- uint8_t i;
- if (data_len < sizeof(example_espnow_data_t)) {
- ESP_LOGE(TAG, "Receive ESPNOW data too short, len:%d", data_len);
- return -1;
- }
- *state = buf->state;
- *seq = buf->seq_num;
- *magic = buf->magic;
- crc = buf->crc;
- buf->crc = 0;
- crc_cal = esp_crc16_le(UINT16_MAX, (uint8_t const *)buf, data_len);
- if (crc_cal == crc) {
- for(i=0;i<data_len;i++){
- ESP_LOGI(TAG, "||| Payload: %02x |||", buf->payload[i]);
- }
- ESP_LOGI(TAG, "<<< Type: %02x | State: %02x | Seq_num: %04x | CRC: %04x | Magic: %08x", buf->type, buf->state, buf->seq_num, crc_cal, buf->magic);
- return buf->type;
- }
- return -1;
- }
- /* Prepare ESPNOW data to be sent. */
- void example_espnow_data_prepare(example_espnow_send_param_t *send_param)
- {
- example_espnow_data_t *buf = (example_espnow_data_t *)send_param->buffer;
- uint8_t i;
- assert(send_param->len >= sizeof(example_espnow_data_t));
- buf->type = IS_BROADCAST_ADDR(send_param->dest_mac) ? EXAMPLE_ESPNOW_DATA_BROADCAST : EXAMPLE_ESPNOW_DATA_UNICAST;
- buf->state = send_param->state;
- buf->seq_num = s_example_espnow_seq[buf->type]++;
- buf->crc = 0;
- buf->magic = send_param->magic;
- *buf->payload = 0x32;
- // for(i=0;i<send_param->len;i++){
- // *(buf->payload + i) = 0x32 + i;
- // }
- /* Fill all remaining bytes after the data with random values */
- esp_fill_random(buf->payload, send_param->len - sizeof(example_espnow_data_t));
- buf->crc = esp_crc16_le(UINT16_MAX, (uint8_t const *)buf, send_param->len);
- for(i=0;i<send_param->len;i++){
- ESP_LOGI(TAG, "||| Payload: %02x |||", buf->payload[i]);
- }
- ESP_LOGI(TAG, ">>> Size: %d | Type: %02x | State: %02x | Seq_num: %04x | CRC: %04x | Magic: %08x", sizeof(buf->payload), buf->type, buf->state, buf->seq_num, buf->crc, buf->magic);
- }
And this is the output:
sender side:
Code: Select all
I (304238) espnow_example: send data to 9c:9c:1f:c9:47:15
I (304238) espnow_example: ||| Payload: 32 |||
I (304238) espnow_example: ||| Payload: 3f |||
I (304238) espnow_example: ||| Payload: 00 |||
I (304248) espnow_example: ||| Payload: 08 |||
I (304248) espnow_example: ||| Payload: 00 |||
I (304258) espnow_example: ||| Payload: 00 |||
I (304258) espnow_example: ||| Payload: a5 |||
I (304268) espnow_example: ||| Payload: a5 |||
I (304268) espnow_example: ||| Payload: a5 |||
I (304278) espnow_example: ||| Payload: a5 |||
I (304278) espnow_example: >>> Size: 0 | Type: 00 | State: 01 | Seq_num: 011c | CRC: e969 | Magic: 29d68dfc
Code: Select all
I (302476) espnow_example: ||| Payload: 00 |||
I (302476) espnow_example: ||| Payload: 00 |||
I (302476) espnow_example: ||| Payload: bc |||
I (302476) espnow_example: ||| Payload: 68 |||
I (302486) espnow_example: ||| Payload: fc |||
I (302486) espnow_example: ||| Payload: 3f |||
I (302496) espnow_example: ||| Payload: 40 |||
I (302496) espnow_example: ||| Payload: 00 |||
I (302506) espnow_example: ||| Payload: 00 |||
I (302506) espnow_example: ||| Payload: 00 |||
I (302516) espnow_example: <<< Type: 00 | State: 01 | Seq_num: 011c | CRC: e969 | Magic: 29d68dfc
I (302526) espnow_example: Receive 284th broadcast data from: 84:cc:a8:2e:05:b8, len: 10
And even if the payload is set to random right now, it remains the same as mentioned above on their resp. sides. Also, when I uncomment the lines 38-40 to change the data being sent, it executes once and then the ESP keeps on going into a panic state and it resets.
What is causing these problems? And how to solve them?